MessageHandler.c 1.1 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123
  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=10;
  711. //===============================
  712. // OCPP sign variable
  713. //===============================
  714. static int server_sign = FALSE;
  715. int server_pending = FALSE;
  716. static int BootNotificationInterval = 10;
  717. //===============================
  718. // OCPP auth variable
  719. //===============================
  720. static int authorizeRetryTimes = 0; //number of Retry times
  721. //===============================
  722. // OCPP other variables
  723. //===============================
  724. static int HeartBeatWaitTime = 10;
  725. static int FirstHeartBeat = 0;
  726. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  727. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  728. static char CurrentChargingProfileScheduleStr[30] = {0};
  729. static int isCancelUploadLog = FALSE;
  730. pthread_t th_GetLog;
  731. //========================================
  732. // OCPP status/previous related variables
  733. //========================================
  734. static int GunStatusInterval = 10;
  735. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  736. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  737. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  738. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  739. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  740. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  741. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  742. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  743. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  744. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  745. static int TransactionMessageAttemptsValue = 0;
  746. static int TransactionMessageRetryIntervalValue = 0;
  747. static struct AuthorizationData idTagQuery;
  748. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  749. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  750. //=============================================
  751. // OCPP HeartBeat Response Not Receive Counts
  752. //============================================
  753. static int HeartBeatWithNOResponse = 0;
  754. static int HeartBeatCountPerHour = 0;
  755. sqlite3 *db;
  756. int TransactionMessageAttemptsGet(void);
  757. int TransactionMessageRetryIntervalGet(void);
  758. int GetOcppConnStatus(void);
  759. void SetOcppConnStatus(uint8_t status);
  760. int setKeyValue(char *key, char *value);
  761. void OCPP_get_TableAuthlocalAllData(void);
  762. void processUnkownKey(void);
  763. struct InterLock
  764. {
  765. unsigned char isGetLogGoing:1;
  766. unsigned char isUpdateFirmwareGoing:1;
  767. }interLock;
  768. struct ClientTime
  769. {
  770. struct timespec Heartbeat;
  771. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  772. struct timespec StartTransaction;
  773. struct timespec StopTransaction;
  774. struct timespec MeterValues[CONNECTOR_QUANTITY];
  775. struct timespec SampledDataTxEnded[CONNECTOR_QUANTITY];
  776. struct timespec RemoteStartWait;
  777. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  778. }clientTime;
  779. typedef union
  780. {
  781. //Operations Initiated by Central System
  782. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  783. struct
  784. {
  785. //CsMsgValue[0]
  786. unsigned char StatusNotificationReq:1; //bit 0,
  787. unsigned char StatusNotificationConf:1; //bit 1,
  788. unsigned char TriggerMeterValueReq:1; //bit 2,
  789. unsigned char SampleMeterReq:1; //bit 3,
  790. unsigned char ClockAlignMeterReq:1; //bit 4,
  791. unsigned char TriggerStatusNotificationReq:1; //bit 5,
  792. unsigned char isOnCharging:1; //bit 6,
  793. unsigned char TriggerTransactionEventReq:1; //bit 7
  794. }bits[CONNECTOR_QUANTITY];
  795. }CpinitiateMsg;
  796. CpinitiateMsg cpinitateMsg;
  797. //=========================================
  798. // Meter buffer process
  799. //=========================================
  800. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContextEnumType dataType)
  801. {
  802. uint32_t result = 0;
  803. char sqlCmd[8192];
  804. char zErrMsg[200];
  805. int rows, cols;
  806. char **resultData;
  807. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContextEnumType_Sample_Periodic?0:1));
  808. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  809. {
  810. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  811. }
  812. else
  813. {
  814. if(rows >= 1)
  815. {
  816. result = atoi(resultData[1]);
  817. }
  818. }
  819. return result;
  820. }
  821. int meterValueBufferClear(uint8_t gun_index)
  822. {
  823. int result = PASS;
  824. char sqlCmd[512];
  825. char *errMsg = 0;
  826. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  827. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  828. {
  829. DEBUG_INFO("SQL error: %s\n",errMsg);
  830. result = FAIL;
  831. }
  832. return result;
  833. }
  834. int meterValueBufferInsert(uint8_t gun_index, ReadingContextEnumType dataType, char * transactionId, char *meterValue)
  835. {
  836. int result = PASS;
  837. char sqlCmd[8192];
  838. char *errMsg = 0;
  839. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%s','%d','%s')", gun_index
  840. , transactionId
  841. , (dataType==ReadingContextEnumType_Sample_Periodic?0:1)
  842. , meterValue);
  843. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  844. {
  845. result = FAIL;
  846. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  847. }
  848. return result;
  849. }
  850. int meterValueBufferReplace(int bufferIdx, uint8_t gun_index, ReadingContextEnumType dataType, char * transactionId, char *meterValue)
  851. {
  852. int result = PASS;
  853. char sqlCmd[8192];
  854. char *errMsg = 0;
  855. sprintf(sqlCmd, "replace into meterValuesBuffer(idx, occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values('%d', CURRENT_TIMESTAMP, '%d', '%s','%d','%s')", bufferIdx
  856. , gun_index
  857. , transactionId
  858. , (dataType==ReadingContextEnumType_Sample_Periodic?0:1)
  859. , meterValue);
  860. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  861. {
  862. result = FAIL;
  863. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  864. }
  865. return result;
  866. }
  867. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  868. {
  869. int result = PASS;
  870. char sqlCmd[8192];
  871. char zErrMsg[200];
  872. int rows, cols;
  873. char **resultData;
  874. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  875. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  876. {
  877. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  878. result = FAIL;
  879. }
  880. else
  881. {
  882. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  883. {
  884. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  885. json_object_array_add(MeterValues, MeterValue);
  886. }
  887. }
  888. return result;
  889. }
  890. //=========================================
  891. // Certificate related routine
  892. //=========================================
  893. int certVerify(char *privateKey, char *cert)
  894. {
  895. int result = PASS;
  896. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  897. // Load certificate file
  898. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  899. {
  900. DEBUG_ERROR("Load certificate error!\n");
  901. result = FAIL;
  902. }
  903. // Load private key file
  904. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  905. {
  906. DEBUG_ERROR("Load private key error!\n");
  907. result = FAIL;
  908. }
  909. if(!SSL_CTX_check_private_key(ctx))
  910. {
  911. result = FAIL;
  912. }
  913. SSL_CTX_free(ctx);
  914. return result;
  915. }
  916. //==========================================
  917. // Parse certificate content
  918. //==========================================
  919. int parseCertInfo(char *certPath, int parseType, char *data)
  920. {
  921. int result = FAIL;
  922. int count = 0;
  923. int showupLine = 0;
  924. memset(data, 0, ARRAY_SIZE(data));
  925. if(access(certPath,F_OK) != -1)
  926. {
  927. char temp[512] = {0};
  928. char capturedData[256] = {0};
  929. char hashType[10] = "SHA256";
  930. FILE *fp;
  931. // Need to get hash type first
  932. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  933. fp = popen(temp, "r");
  934. if(fp)
  935. {
  936. while(fgets(temp, sizeof(temp), fp) != NULL)
  937. {
  938. if(strstr(temp, "Signature Algorithm:") != NULL)
  939. {
  940. result = PASS;
  941. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  942. sprintf((char*)hashType, "SHA256");
  943. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  944. sprintf((char*)hashType, "SHA384");
  945. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  946. sprintf((char*)hashType, "SHA512");
  947. else
  948. {
  949. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  950. result = FAIL;
  951. }
  952. break;
  953. }
  954. }
  955. }
  956. switch(parseType)
  957. {
  958. case CERT_PARSE_HashAlgorithm:
  959. sprintf((char*)data, hashType);
  960. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  961. break;
  962. case CERT_PARSE_SerialNumber:
  963. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  964. fp = popen(temp, "r");
  965. if(fp)
  966. {
  967. while(fgets(temp, sizeof(temp), fp) != NULL)
  968. {
  969. if(strstr(temp, "serial=") != NULL)
  970. {
  971. sscanf(temp, "%*[^=]=%s", capturedData);
  972. result = PASS;
  973. break;
  974. }
  975. }
  976. DEBUG_INFO("serialNumber: %s\n", capturedData);
  977. sprintf((char*)data, capturedData);
  978. }
  979. break;
  980. case CERT_PARSE_IssuerNameHash:
  981. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  982. fp = popen(temp, "r");
  983. if(fp)
  984. {
  985. while(fgets(temp, sizeof(temp), fp) != NULL)
  986. {
  987. if(strstr(temp, "SEQUENCE") != NULL)
  988. {
  989. count++;
  990. if(count==4)
  991. {
  992. sscanf(temp, "%[^:]", capturedData);
  993. showupLine = atoi(capturedData);
  994. break;
  995. }
  996. }
  997. }
  998. }
  999. if(showupLine > 0)
  1000. {
  1001. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1002. system(temp);
  1003. }
  1004. else
  1005. {
  1006. break;
  1007. }
  1008. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1009. {
  1010. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1011. fp = popen(temp, "r");
  1012. if(fp)
  1013. {
  1014. while(fgets(temp, sizeof(temp), fp) != NULL)
  1015. {
  1016. if(strstr(temp, "(stdin)=") != NULL)
  1017. {
  1018. sscanf(temp, "%*[^=]=%s", capturedData);
  1019. result = PASS;
  1020. break;
  1021. }
  1022. }
  1023. stringtrimspace(capturedData);
  1024. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1025. sprintf((char*)data, capturedData);
  1026. }
  1027. }
  1028. break;
  1029. case CERT_PARSE_IssuerKeyHash:
  1030. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1031. fp = popen(temp, "r");
  1032. if(fp)
  1033. {
  1034. while(fgets(temp, sizeof(temp), fp) != NULL)
  1035. {
  1036. if(strstr(temp, "BIT STRING") != NULL)
  1037. {
  1038. sscanf(temp, "%[^:]", capturedData);
  1039. showupLine = atoi(capturedData);
  1040. break;
  1041. }
  1042. }
  1043. }
  1044. if(showupLine > 0)
  1045. {
  1046. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1047. system(temp);
  1048. }
  1049. else
  1050. {
  1051. break;
  1052. }
  1053. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1054. {
  1055. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1056. fp = popen(temp, "r");
  1057. if(fp)
  1058. {
  1059. while(fgets(temp, sizeof(temp), fp) != NULL)
  1060. {
  1061. if(strstr(temp, "(stdin)=") != NULL)
  1062. {
  1063. sscanf(temp, "%*[^=]=%s", capturedData);
  1064. result = PASS;
  1065. break;
  1066. }
  1067. }
  1068. stringtrimspace(capturedData);
  1069. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1070. sprintf((char*)data, capturedData);
  1071. }
  1072. }
  1073. break;
  1074. case CERT_PARSE_OcspUrl:
  1075. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1076. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1077. fp = popen(temp, "r");
  1078. if(fp)
  1079. {
  1080. while(fgets(temp, sizeof(temp), fp) != NULL)
  1081. {
  1082. if(strstr(temp, "OCSP - URI:") != NULL)
  1083. {
  1084. //strcpy((char*)data, temp);
  1085. sscanf(temp, "%*[^:]:%s", capturedData);
  1086. sprintf((char*)data, capturedData);
  1087. DEBUG_INFO("OCSP_URI: %s\n", data);
  1088. result = PASS;
  1089. break;
  1090. }
  1091. }
  1092. }
  1093. break;
  1094. default:
  1095. DEBUG_INFO("Parse type is invalid.\n");
  1096. break;
  1097. }
  1098. pclose(fp);
  1099. }
  1100. return result;
  1101. }
  1102. //=========================================
  1103. // Get connector charging info
  1104. //=========================================
  1105. struct ChargingInfoData *getTargetChargingInfoData(uint8_t gun_index)
  1106. {
  1107. struct ChargingInfoData *targetChargingInfoData;
  1108. uint8_t tempIndex;
  1109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1110. {
  1111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1112. {
  1113. tempIndex = ((gun_index==2) ? 1: 0);
  1114. }
  1115. else
  1116. {
  1117. tempIndex = gun_index;
  1118. }
  1119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1120. {
  1121. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1122. {
  1123. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  1124. break;
  1125. }
  1126. }
  1127. }
  1128. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1129. {
  1130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1131. {
  1132. tempIndex = ((gun_index==2) ? 1: 0);
  1133. }
  1134. else
  1135. {
  1136. tempIndex = gun_index;
  1137. }
  1138. for (int index = 0; index < CCS_QUANTITY; index++)
  1139. {
  1140. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1141. {
  1142. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1148. {
  1149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1150. {
  1151. tempIndex = ((gun_index==2) ? 1: 0);
  1152. }
  1153. else
  1154. {
  1155. tempIndex = gun_index;
  1156. }
  1157. for (int index = 0; index < GB_QUANTITY; index++)
  1158. {
  1159. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1160. {
  1161. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. else if(gunType[gun_index] == GUN_TYPE_DO)
  1167. {
  1168. tempIndex = gun_index;
  1169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1170. {
  1171. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1172. {
  1173. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData;
  1174. break;
  1175. }
  1176. }
  1177. }
  1178. else
  1179. {
  1180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1181. {
  1182. tempIndex = 2;
  1183. }
  1184. else
  1185. {
  1186. tempIndex = gun_index;
  1187. }
  1188. for (int index = 0; index < AC_QUANTITY; index++)
  1189. {
  1190. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1191. {
  1192. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.AcChargingData[index];
  1193. break;
  1194. }
  1195. }
  1196. }
  1197. return targetChargingInfoData;
  1198. }
  1199. //=========================================
  1200. // Save configuration
  1201. //=========================================
  1202. int runShellCmd(const char*cmd)
  1203. {
  1204. int result = FAIL;
  1205. char buf[256];
  1206. FILE *fp;
  1207. fp = popen(cmd, "r");
  1208. if(fp != NULL)
  1209. {
  1210. while(fgets(buf, sizeof(buf), fp) != NULL)
  1211. {
  1212. DEBUG_INFO("%s\n", buf);
  1213. }
  1214. result = PASS;
  1215. }
  1216. pclose(fp);
  1217. return result;
  1218. }
  1219. int StoreUsrConfigData(struct SysConfigData *UsrData)
  1220. {
  1221. int result = PASS;
  1222. int fd,wrd;
  1223. unsigned int i,Chk;
  1224. unsigned char *ptr, *BufTmp;
  1225. int MtdBlockSize = 0x300000;
  1226. Chk=0;
  1227. ptr=(unsigned char *)UsrData;
  1228. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  1229. {
  1230. memset(BufTmp,0,MtdBlockSize);
  1231. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  1232. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  1233. Chk+=*(BufTmp+i);
  1234. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  1235. // Output configuration to file.
  1236. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  1237. if (fd < 0)
  1238. {
  1239. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  1240. free(BufTmp);
  1241. return 0;
  1242. }
  1243. wrd=write(fd, BufTmp, MtdBlockSize);
  1244. close(fd);
  1245. if(wrd<MtdBlockSize)
  1246. {
  1247. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  1248. free(BufTmp);
  1249. return 0;
  1250. }
  1251. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  1252. DEBUG_INFO("Erase /dev/mtd10.\n");
  1253. runShellCmd("flash_erase /dev/mtd10 0 0");
  1254. DEBUG_INFO("Write /dev/mtd10.\n");
  1255. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  1256. DEBUG_INFO("Erase /dev/mtd11.\n");
  1257. runShellCmd("flash_erase /dev/mtd11 0 0");
  1258. DEBUG_INFO("Write /dev/mtd11.\n");
  1259. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  1260. system("rm -f /mnt/EvseConfig.bin");
  1261. DEBUG_INFO("EvseConfig write to flash OK\n");
  1262. }
  1263. else
  1264. {
  1265. DEBUG_ERROR("alloc BlockSize NG\r\n");
  1266. result = FAIL;
  1267. }
  1268. if(BufTmp!=NULL)
  1269. free(BufTmp);
  1270. return result;
  1271. }
  1272. //=========================================
  1273. // Date time related function
  1274. //=========================================
  1275. void getNowDatetime(uint8_t *data)
  1276. {
  1277. time_t t = time(NULL);
  1278. struct tm tm = *localtime(&t);
  1279. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1280. }
  1281. //=========================================
  1282. // Sqlite3 related function
  1283. //=========================================
  1284. int DB_Initial()
  1285. {
  1286. int result = PASS;
  1287. char* errMsg = NULL;
  1288. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  1289. "idToken text UNIQUE,"
  1290. "type text,"
  1291. "status text,"
  1292. "cacheExpiryDateTime text,"
  1293. "chargingPriority integer,"
  1294. "language1 text,"
  1295. "evseId text,"
  1296. "language2 text,"
  1297. "groupIdToken_idToken text,"
  1298. "groupIdToken_type text,"
  1299. "personalMessage text);";
  1300. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  1301. "idToken text UNIQUE,"
  1302. "type text,"
  1303. "status text,"
  1304. "cacheExpiryDateTime text,"
  1305. "chargingPriority integer,"
  1306. "language1 text,"
  1307. "evseId text,"
  1308. "language2 text,"
  1309. "groupIdToken_idToken text,"
  1310. "groupIdToken_type text,"
  1311. "personalMessage text,"
  1312. "version text);";
  1313. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  1314. "componentName text NOT NULL ,"
  1315. "componentInstance text, "
  1316. "variableName text NOT NULL, "
  1317. "variableInstance text, "
  1318. "variableCharacteristicsDataType integer, "
  1319. "variableCharacteristicsUnit text, "
  1320. "variableCharacteristicsMaxLimit real,"
  1321. "variableAttributesType text, "
  1322. "variableAttributesTypeMutability text, "
  1323. "variableAttributesTypeValue text, "
  1324. "variableCharacteristicsMinLimit real,"
  1325. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  1326. char *sqlVariableMonitoring = "create table if not exists ocpp20_variable_monitoring (idx integer primary key,"
  1327. "id integer ,"
  1328. "txn text, "
  1329. "value text , "
  1330. "type text, "
  1331. "severity integer, "
  1332. "component_name text, "
  1333. "component_instance text,"
  1334. "component_evse_id integer, "
  1335. "component_evse_connectorId integer, "
  1336. "variable_name text, "
  1337. "variable_instance text);";
  1338. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  1339. "type text);";
  1340. char *sqlSecurityEventType = "create table if not exists ocpp20_securityevent_type (idx integer primary key,"
  1341. "type text);";
  1342. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  1343. "slot integer UNIQUE, connectionData text);";
  1344. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  1345. "occurDatetime text,"
  1346. "message_type text,"
  1347. "message_content text)";
  1348. char *sqlMeterValueBuffer = "create table if not exists meterValuesBuffer( idx integer primary key,"
  1349. "occurDatetime text,"
  1350. "gun_index text,"
  1351. "transactionId text,"
  1352. "ReadingContext text,"
  1353. "meterValue text);";
  1354. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  1355. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  1356. {
  1357. result = FAIL;
  1358. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  1359. sqlite3_close(db);
  1360. }
  1361. else
  1362. {
  1363. DEBUG_INFO( "OCPP local database open successfully.\n");
  1364. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  1365. {
  1366. result = FAIL;
  1367. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  1368. }
  1369. else
  1370. {
  1371. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  1372. }
  1373. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  1374. {
  1375. result = FAIL;
  1376. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  1377. }
  1378. else
  1379. {
  1380. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  1381. }
  1382. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  1383. {
  1384. result = FAIL;
  1385. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  1386. }
  1387. else
  1388. {
  1389. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  1390. }
  1391. if (sqlite3_exec(db, sqlVariableMonitoring, 0, 0, &errMsg) != SQLITE_OK)
  1392. {
  1393. result = FAIL;
  1394. DEBUG_ERROR( "Create OCPP 2.0 variable monitoring table error message: %s\n", errMsg);
  1395. }
  1396. else
  1397. {
  1398. DEBUG_INFO( "Create OCPP 2.0 variable monitoring table successfully\n");
  1399. }
  1400. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  1401. {
  1402. result = FAIL;
  1403. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  1404. }
  1405. else
  1406. {
  1407. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  1408. }
  1409. if (sqlite3_exec(db, sqlSecurityEventType, 0, 0, &errMsg) != SQLITE_OK)
  1410. {
  1411. result = FAIL;
  1412. DEBUG_ERROR( "Create OCPP 2.0 securityevent_type table error message: %s\n", errMsg);
  1413. }
  1414. else
  1415. {
  1416. DEBUG_INFO( "Create OCPP 2.0 securityevent_type table successfully\n");
  1417. }
  1418. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  1419. {
  1420. result = FAIL;
  1421. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  1422. }
  1423. else
  1424. {
  1425. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  1426. }
  1427. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  1428. {
  1429. result = FAIL;
  1430. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  1431. }
  1432. else
  1433. {
  1434. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  1435. }
  1436. // Create meter values buffer table
  1437. if(sqlite3_exec(db, sqlMeterValueBuffer, 0, 0, &errMsg) != SQLITE_OK)
  1438. {
  1439. DEBUG_INFO( "Create Table meterValuesBuffer error %s\n",errMsg);
  1440. return 0;
  1441. }
  1442. else
  1443. {
  1444. DEBUG_INFO( "Opened meterValuesBuffer table successfully\n");
  1445. }
  1446. //sqlite3_close(db);
  1447. }
  1448. return result;
  1449. }
  1450. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  1451. {
  1452. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  1453. return 0;
  1454. }
  1455. void DB_getListVerion()
  1456. {
  1457. char sql[256];
  1458. char* errMsg = NULL;
  1459. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  1460. /* Execute SQL statement */
  1461. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  1462. {
  1463. DEBUG_INFO("SQL error: %s", errMsg);
  1464. }
  1465. }
  1466. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  1467. {
  1468. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  1469. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  1470. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  1471. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  1472. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  1473. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  1474. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  1475. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  1476. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  1477. return 0;
  1478. }
  1479. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1480. {
  1481. char sql[256];
  1482. char* errMsg = NULL;
  1483. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1484. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1485. if(isQueryFromCache)
  1486. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1487. else
  1488. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1489. /* Execute SQL statement */
  1490. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1491. {
  1492. DEBUG_INFO("SQL error: %s", errMsg);
  1493. }
  1494. }
  1495. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1496. {
  1497. for (int i = 0; i < columnCount; i++)
  1498. {
  1499. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1500. }
  1501. return 0;
  1502. }
  1503. void DB_get_TableAuthlocalAllData(void)
  1504. {
  1505. char sql[256];
  1506. char* errMsg = NULL;
  1507. sprintf(sql,"select * from ocpp20_auth_local;");
  1508. /* Execute SQL statement */
  1509. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1510. {
  1511. DEBUG_INFO("SQL error: %s", errMsg);
  1512. }
  1513. }
  1514. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1515. {
  1516. for(int i = 0; i<columnCount; i++)
  1517. {
  1518. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1519. }
  1520. return 0;
  1521. }
  1522. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1523. {
  1524. int result = PASS;
  1525. char sql[512];
  1526. char* errMsg = NULL;
  1527. 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;",
  1528. data->idToken.idToken,
  1529. data->idToken.type,
  1530. data->idTokenInfo.status,
  1531. data->idTokenInfo.cacheExpiryDateTime,
  1532. data->idTokenInfo.chargingPriority,
  1533. data->idTokenInfo.language1,
  1534. data->idTokenInfo.language2,
  1535. data->idTokenInfo.groupIdToken.idToken,
  1536. data->idTokenInfo.groupIdToken.type,
  1537. listVersion);
  1538. //* Execute SQL statement */
  1539. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1540. {
  1541. DEBUG_INFO("SQL error: %s\n", errMsg);
  1542. result = FAIL;
  1543. }
  1544. else
  1545. {
  1546. memset(sql, 0, ARRAY_SIZE(sql));
  1547. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1548. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1549. {
  1550. DEBUG_INFO("SQL error: %s\n", errMsg);
  1551. result = FAIL;
  1552. }
  1553. }
  1554. return result;
  1555. }
  1556. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1557. {
  1558. int result = PASS;
  1559. char sql[512];
  1560. char* errMsg = NULL;
  1561. 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;",
  1562. idToken->idToken,
  1563. idToken->type,
  1564. idTokenInfo->status,
  1565. idTokenInfo->cacheExpiryDateTime,
  1566. idTokenInfo->chargingPriority,
  1567. idTokenInfo->language1,
  1568. idTokenInfo->language2,
  1569. idTokenInfo->groupIdToken.idToken,
  1570. idTokenInfo->groupIdToken.type);
  1571. //* Execute SQL statement */
  1572. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1573. {
  1574. DEBUG_INFO("SQL error: %s\n", errMsg);
  1575. result = FAIL;
  1576. }
  1577. return result;
  1578. }
  1579. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1580. {
  1581. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1582. // printf("localversion=%d\n", localversion);
  1583. return 0;
  1584. }
  1585. void DB_deleteIdTag(char idTag[])
  1586. {
  1587. char sql[512];
  1588. char* errMsg = NULL;
  1589. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1590. //* Execute SQL statement */
  1591. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1592. {
  1593. DEBUG_INFO("SQL error: %s", errMsg);
  1594. }
  1595. }
  1596. int DB_cleanLocalList()
  1597. {
  1598. int result = PASS;
  1599. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1600. char *errMsg = 0;
  1601. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1602. {
  1603. DEBUG_INFO("%s\n", errMsg);
  1604. result = FAIL;
  1605. }
  1606. return result;
  1607. }
  1608. int DB_cleanLocalCache()
  1609. {
  1610. int result = PASS;
  1611. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1612. char *errMsg = 0;
  1613. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1614. {
  1615. DEBUG_INFO("%s\n", errMsg);
  1616. result = FAIL;
  1617. }
  1618. return result;
  1619. }
  1620. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1621. {
  1622. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1623. return 0;
  1624. }
  1625. void DB_getBooType()
  1626. {
  1627. char sql[256];
  1628. char* errMsg = NULL;
  1629. sprintf(sql,"select * from ocpp20_boot_type;");
  1630. /* Execute SQL statement */
  1631. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1632. {
  1633. DEBUG_INFO("SQL error: %s\n", errMsg);
  1634. }
  1635. }
  1636. int DB_cbUpdateBootType(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_updateBootType(BootReasonEnumType reason)
  1645. {
  1646. int result = PASS;
  1647. char sql[512];
  1648. char* errMsg = NULL;
  1649. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1650. //* Execute SQL statement */
  1651. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1652. {
  1653. DEBUG_INFO("SQL error: %s\n", errMsg);
  1654. result = FAIL;
  1655. }
  1656. return result;
  1657. }
  1658. int SecurityEventTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1659. {
  1660. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", columnValue[1] ? columnValue[1] : SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  1661. return 0;
  1662. }
  1663. void DB_getSecurityEventType()
  1664. {
  1665. char sql[256];
  1666. char* errMsg = NULL;
  1667. sprintf(sql,"select * from ocpp20_securityevent_type;");
  1668. /* Execute SQL statement */
  1669. if(sqlite3_exec(db, sql, SecurityEventTypecallback, 0, &errMsg) != SQLITE_OK )
  1670. {
  1671. DEBUG_INFO("SQL error: %s\n", errMsg);
  1672. }
  1673. }
  1674. int DB_cbUpdateSecurityEventType(void *para, int columnCount, char **columnValue, char **columnName)
  1675. {
  1676. for(int i = 0; i<columnCount; i++)
  1677. {
  1678. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1679. }
  1680. return 0;
  1681. }
  1682. int DB_updateSecurityEventType(SecurityEventEnumType reason)
  1683. {
  1684. int result = PASS;
  1685. char sql[512];
  1686. char* errMsg = NULL;
  1687. sprintf(sql,"insert or replace into ocpp20_securityevent_type (idx, type) VALUES(1, '%s');", SecurityEventEnumTypeStr[reason]);
  1688. //* Execute SQL statement */
  1689. if(sqlite3_exec(db, sql, DB_cbUpdateSecurityEventType, 0, &errMsg) != SQLITE_OK)
  1690. {
  1691. DEBUG_INFO("SQL error: %s\n", errMsg);
  1692. result = FAIL;
  1693. }
  1694. return result;
  1695. }
  1696. int DB_variableClear()
  1697. {
  1698. int result = PASS;
  1699. char * sqlclearVariable = "delete from ocpp20_variable";
  1700. char *errMsg = 0;
  1701. if (sqlite3_exec(db, sqlclearVariable, 0, 0, &errMsg) != SQLITE_OK)
  1702. {
  1703. DEBUG_INFO("%s\n", errMsg);
  1704. result = FAIL;
  1705. }
  1706. return result;
  1707. }
  1708. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1709. {
  1710. for(int i = 0; i<columnCount; i++)
  1711. {
  1712. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1713. }
  1714. return 0;
  1715. }
  1716. int DB_variableSaveToDb(struct ReportDataType *variable)
  1717. {
  1718. int result = FAIL;
  1719. char sql[4096];
  1720. char* errMsg = NULL;
  1721. 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;",
  1722. variable->component.name,
  1723. variable->component.instance,
  1724. variable->variable.name,
  1725. variable->variable.instance,
  1726. variable->variableCharacteristics.dataType,
  1727. variable->variableCharacteristics.unit,
  1728. variable->variableCharacteristics.maxLimit,
  1729. variable->variableAttribute[0].type,
  1730. variable->variableAttribute[0].mutability,
  1731. variable->variableAttribute[0].value,
  1732. variable->variableCharacteristics.minLimit);
  1733. //* Execute SQL statement */
  1734. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1735. {
  1736. DEBUG_INFO("SQL error: %s\n", errMsg);
  1737. result = FAIL;
  1738. }
  1739. return result;
  1740. }
  1741. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1742. {
  1743. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1744. if(atoi(columnValue[0]) == 0)
  1745. {
  1746. DB_updateBootType(BootReasonEnumType_PowerUp);
  1747. // Create variable table content
  1748. /* AlignedDataCtrlr Required item */
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "false");
  1755. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "true");
  1762. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1766. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1769. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1771. "Energy.Active.Import.Register,"
  1772. "Energy.Active.Import.Interval,"
  1773. "Power.Active.Import,"
  1774. "Voltage,"
  1775. "SoC,"
  1776. "Current.Offered,"
  1777. "Power.Offered");
  1778. else
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1780. "Energy.Active.Import.Register,"
  1781. "Energy.Active.Import.Interval,"
  1782. "Power.Active.Import,"
  1783. "Voltage,"
  1784. "Current.Offered");
  1785. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1790. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 5;
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1794. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "true");
  1801. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  1808. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1812. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1817. "Energy.Active.Import.Register,"
  1818. "Energy.Active.Import.Interval,"
  1819. "Power.Active.Import,"
  1820. "Voltage,"
  1821. "SoC");
  1822. else
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1824. "Energy.Active.Import.Register,"
  1825. "Energy.Active.Import.Interval,"
  1826. "Power.Active.Import,"
  1827. "Voltage");
  1828. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1836. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1837. /* AuthCtrlrVariable Required item */
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE?"true":"false");
  1844. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AuthCtrlr");
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1851. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "false");
  1858. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "false");
  1865. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true");
  1872. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true");
  1879. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1883. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1887. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1888. /* AuthCacheCtrlr Variable Required item*/
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "false");
  1895. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "true");
  1902. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "true");
  1910. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1914. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "true");
  1918. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1925. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1926. /* ClockCtrlr Variable Required item */
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1932. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1933. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1940. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1948. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1955. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1962. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1970. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1977. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1984. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1985. /* ChargingStation Required item */
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "false");
  1992. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1999. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  2006. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].value, "0");
  2013. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  2020. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend]);
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value, "FreeVendIdtag");
  2027. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag]);
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].value, "0");
  2034. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower]);
  2035. /* Connector Required item */
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "false");
  2042. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  2043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  2049. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  2056. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  2057. /* CustomizationCtrlr Required item */
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "false");
  2064. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  2065. /* DeviceDataCtrlr Required item */
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  2073. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  2081. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  2089. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  2090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  2097. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2100. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  2105. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2108. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  2113. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  2121. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  2129. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  2130. /* DisplayMessageCtrlr Required item */
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "false");
  2137. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "false");
  2144. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2148. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  2152. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  2159. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  2166. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  2167. /* EVSE Required item */
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "false");
  2174. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  2181. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  2188. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  2195. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  2196. /* LocalAuthListCtrlr Required item */
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true");
  2203. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2207. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  2211. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "true");
  2218. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  2226. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  2234. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2238. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  2242. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  2243. /* MonitoringCtrlr Required item */
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "false");
  2250. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "false");
  2257. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  2265. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  2273. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  2281. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  2289. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  2296. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  2297. /* OCPPCommCtrlr Required item */
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  2304. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  2313. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  2320. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  2324. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  2329. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  2336. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  2343. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  2351. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "false");
  2358. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  2367. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  2376. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "true");
  2383. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  2387. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  2392. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  2399. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  2406. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  2413. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "false");
  2420. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  2424. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  2429. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.unit, "Seconds");
  2433. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.minLimit = 5;
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value, "30");
  2438. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval]);
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].component.name, "OCPPCommCtrlr");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variable.name, "RfidEndianType");
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"big":"little");
  2445. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType]);
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].component.name, "OCPPCommCtrlr");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variable.name, "AuthorizeTimeout");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.unit, "Seconds");
  2449. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.minLimit = 10;
  2450. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.maxLimit = 300;
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].value, "15");
  2455. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout]);
  2456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].component.name, "OCPPCommCtrlr");
  2457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variable.name, "EnableAcCcs");
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variableAttribute[0].value, "false");
  2462. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs]);
  2463. /* ReservationCtrlr Required item */
  2464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "true");
  2470. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "true");
  2477. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "false");
  2484. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  2485. /* SampledDataCtrlr Required item */
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "true");
  2492. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  2493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "true");
  2499. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  2506. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2510. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2513. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2515. "Energy.Active.Import.Register,"
  2516. "Energy.Active.Import.Interval,"
  2517. "Power.Active.Import,"
  2518. "Voltage,"
  2519. "SoC");
  2520. else
  2521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2522. "Energy.Active.Import.Register,"
  2523. "Energy.Active.Import.Interval,"
  2524. "Power.Active.Import,"
  2525. "Voltage");
  2526. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  2527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  2530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  2534. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  2535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2538. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  2542. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2546. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  2547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2551. "Energy.Active.Import.Register,"
  2552. "Energy.Active.Import.Interval,"
  2553. "Power.Active.Import,"
  2554. "Voltage,"
  2555. "SoC,"
  2556. "Current.Offered,"
  2557. "Power.Offered");
  2558. else
  2559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2560. "Energy.Active.Import.Register,"
  2561. "Energy.Active.Import.Interval,"
  2562. "Power.Active.Import,"
  2563. "Voltage,"
  2564. "Current.Offered");
  2565. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2570. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2574. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2575. /* SecurityCtrlr Required item */
  2576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2579. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", (strlen((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword)>0?(char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword:"00000000"));
  2583. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2587. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2591. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2598. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2602. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2606. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2613. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "false");
  2620. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2624. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2628. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2629. /* SmartChargingCtrlr Required item */
  2630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "true");
  2636. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "true");
  2643. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "false");
  2650. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "3");
  2657. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2664. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2671. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "false");
  2678. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "false");
  2685. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "false");
  2692. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2696. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2700. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2707. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2708. /* TariffCostCtrlr Required item */
  2709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "false");
  2716. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "false");
  2724. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2728. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2732. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "false");
  2740. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "false");
  2748. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2752. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2756. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2760. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2764. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2765. /* TxCtrlr Required item */
  2766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2772. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2780. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2783. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "true");
  2787. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2794. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2801. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2808. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2816. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "false");
  2823. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2824. }
  2825. else
  2826. {
  2827. // Variable name init
  2828. /* AlignedDataCtrlr Required item */
  2829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2845. /* AuthCtrlrVariable Required item */
  2846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2860. /* AuthCacheCtrlr Variable Required item */
  2861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2871. /* ClockCtrlr Variable Required item */
  2872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2890. /* ChargingStation Required item */
  2891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2905. /* Connector Required item */
  2906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2912. /* CustomizationCtrlr Required item */
  2913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2915. /* DeviceDataCtrlr Required item */
  2916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2938. /* DisplayMessageCtrlr Required item */
  2939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2949. /* EVSE Required item */
  2950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2958. /* LocalAuthListCtrlr Required item */
  2959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2973. /* MonitoringCtrlr Required item */
  2974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2992. /* OCPPCommCtrlr Required item */
  2993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  3000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  3001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  3002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  3003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  3004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  3005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  3006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  3007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  3008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  3009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  3010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  3011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  3012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  3013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  3014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  3015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  3016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  3017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  3018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  3019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  3020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  3021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  3022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  3023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  3024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  3025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  3026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  3027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  3028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  3029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  3030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  3031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  3032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].component.name, "OCPPCommCtrlr");
  3033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variable.name, "RfidEndianType");
  3034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].component.name, "OCPPCommCtrlr");
  3035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variable.name, "AuthorizeTimeout");
  3036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].component.name, "OCPPCommCtrlr");
  3037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variable.name, "EnableAcCcs");
  3038. /* ReservationCtrlr Required item */
  3039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  3040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  3041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  3042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  3043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  3044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  3045. /* SampledDataCtrlr Required item */
  3046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  3047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  3048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  3049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  3050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  3051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  3052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  3053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  3054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  3055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  3056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  3057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  3058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  3059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  3060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  3061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  3062. /* SecurityCtrlr Required item */
  3063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  3064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  3065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  3066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  3067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  3068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  3069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  3070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  3071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  3072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  3073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  3074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  3075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  3076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  3077. /* SmartChargingCtrlr Required item */
  3078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  3079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  3080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  3081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  3082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  3083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  3084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  3085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  3086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  3087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  3088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  3089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  3090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  3091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  3092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  3093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  3094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  3095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  3096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  3097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  3098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  3099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  3100. /* TariffCostCtrlr Required item */
  3101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  3102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  3103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  3104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  3105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  3106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  3107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  3108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  3109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  3110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  3111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  3112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  3113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  3114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  3115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  3116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  3117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  3118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  3119. /* TxCtrlr Required item */
  3120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  3121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  3122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  3123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  3124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  3125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  3126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  3127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  3128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  3129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  3130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  3131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  3132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  3133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  3134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  3135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  3136. }
  3137. return 0;
  3138. }
  3139. void DB_variableIsCreate()
  3140. {
  3141. char sql[512];
  3142. char* errMsg = NULL;
  3143. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  3144. /* Execute SQL statement */
  3145. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  3146. {
  3147. DEBUG_INFO("SQL error: %s\n", errMsg);
  3148. }
  3149. }
  3150. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3151. {
  3152. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  3153. {
  3154. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  3155. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  3156. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  3157. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  3158. {
  3159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  3160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  3161. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  3162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  3163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  3164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  3165. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  3166. }
  3167. }
  3168. return 0;
  3169. }
  3170. void DB_variableLoadFromDb()
  3171. {
  3172. char sql[512];
  3173. char* errMsg = NULL;
  3174. sprintf(sql,"select * from ocpp20_variable order by idx;");
  3175. /* Execute SQL statement */
  3176. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  3177. {
  3178. DEBUG_INFO("SQL error: %s\n", errMsg);
  3179. }
  3180. }
  3181. //==============================
  3182. // Variable Monitoring
  3183. //==============================
  3184. int DB_variableMonitoringClear()
  3185. {
  3186. int result = PASS;
  3187. char * sqlclearVariableMonitoring = "delete from ocpp20_variable_monitoring";
  3188. char *errMsg = 0;
  3189. if (sqlite3_exec(db, sqlclearVariableMonitoring, 0, 0, &errMsg) != SQLITE_OK)
  3190. {
  3191. DEBUG_INFO("%s\n", errMsg);
  3192. result = FAIL;
  3193. }
  3194. return result;
  3195. }
  3196. int DB_cbVariableMonitoringSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  3197. {
  3198. for(int i = 0; i<columnCount; i++)
  3199. {
  3200. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  3201. }
  3202. return 0;
  3203. }
  3204. int DB_variableMonitoringSaveToDb(struct SetMonitoringDataType *variableMonitoring)
  3205. {
  3206. int result = FAIL;
  3207. char sql[4096];
  3208. char* errMsg = NULL;
  3209. sprintf(sql,"insert or replace into ocpp20_variable_monitoring "
  3210. "(id, transaction, value, type, severity, component_name, component_instance, component_evse_id, component_evse_connectorId, variable_name, variable_instance) "
  3211. "VALUES('%d', '%d', '%.2f', '%s', '%d', '%s', %s, '%d', '%d', '%s', '%s'); SELECT * from ocpp20_variable_monitoring;",
  3212. variableMonitoring->id,
  3213. variableMonitoring->transaction,
  3214. variableMonitoring->value,
  3215. variableMonitoring->type,
  3216. variableMonitoring->severity,
  3217. variableMonitoring->component.name,
  3218. variableMonitoring->component.instance,
  3219. variableMonitoring->component.evse.id,
  3220. variableMonitoring->component.evse.connectorId,
  3221. variableMonitoring->variable.name,
  3222. variableMonitoring->variable.instance
  3223. );
  3224. //* Execute SQL statement */
  3225. if(sqlite3_exec(db, sql, DB_cbVariableMonitoringSaveToDb, 0, &errMsg) != SQLITE_OK)
  3226. {
  3227. DEBUG_INFO("SQL error: %s\n", errMsg);
  3228. result = FAIL;
  3229. }
  3230. return result;
  3231. }
  3232. int DB_cbVariableMonitoringLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3233. {
  3234. for(int idx=0;idx<10;idx++)
  3235. {
  3236. if((strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name) == 0) &&
  3237. (strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name) == 0))
  3238. {
  3239. ShmOCPP20Data->MonitoringComponentVariable[idx].id = strlen(columnValue[1])>=0?atoi(columnValue[1]):-1;
  3240. ShmOCPP20Data->MonitoringComponentVariable[idx].transaction = strlen(columnValue[2])>=0?atoi(columnValue[2]):0;
  3241. ShmOCPP20Data->MonitoringComponentVariable[idx].value = strlen(columnValue[3])>=0?atof(columnValue[3]):0;
  3242. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "%s", columnValue[4]);
  3243. ShmOCPP20Data->MonitoringComponentVariable[idx].severity = strlen(columnValue[5])>0?atoi(columnValue[5]):9;
  3244. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, "%s", columnValue[6]);
  3245. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.instance, "%s", columnValue[7]);
  3246. ShmOCPP20Data->MonitoringComponentVariable[idx].component.evse.id = strlen(columnValue[8])>0?atoi(columnValue[8]):-1;
  3247. ShmOCPP20Data->MonitoringComponentVariable[idx].component.evse.connectorId = strlen(columnValue[9])>0?atoi(columnValue[9]):-1;
  3248. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, "%s", columnValue[10]);
  3249. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.instance, "%s", columnValue[11]);
  3250. break;
  3251. }
  3252. }
  3253. return 0;
  3254. }
  3255. void DB_variableMonitoringLoadFromDb()
  3256. {
  3257. char sql[512];
  3258. char* errMsg = NULL;
  3259. sprintf(sql,"select * from ocpp20_variable_monitoring order by idx;");
  3260. /* Execute SQL statement */
  3261. if(sqlite3_exec(db, sql, DB_cbVariableMonitoringLoadFromDb, 0, &errMsg) != SQLITE_OK )
  3262. {
  3263. DEBUG_INFO("SQL error: %s\n", errMsg);
  3264. }
  3265. }
  3266. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3267. {
  3268. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  3269. if(columnCount > 0)
  3270. {
  3271. for(int idx=0;idx<columnCount;idx++)
  3272. {
  3273. json_object *SetNetworkProfile;
  3274. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  3275. if(!is_error(SetNetworkProfile))
  3276. {
  3277. // Required data
  3278. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  3279. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  3280. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  3281. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  3282. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  3283. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  3284. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  3285. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  3286. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  3287. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  3288. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  3289. {
  3290. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  3291. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  3292. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  3293. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  3294. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  3295. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  3296. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  3297. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  3298. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  3299. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  3300. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  3301. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  3302. }
  3303. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  3304. {
  3305. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  3306. {
  3307. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  3308. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  3309. }
  3310. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  3311. {
  3312. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  3313. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  3314. }
  3315. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  3316. {
  3317. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  3318. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  3319. }
  3320. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  3321. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  3322. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  3323. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  3324. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  3325. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  3326. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  3327. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  3328. }
  3329. }
  3330. json_object_put(SetNetworkProfile);
  3331. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  3332. }
  3333. }
  3334. return 0;
  3335. }
  3336. void DB_getNetworkProfileFromDb()
  3337. {
  3338. char sql[512];
  3339. char* errMsg = NULL;
  3340. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  3341. /* Execute SQL statement */
  3342. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3343. {
  3344. DEBUG_INFO("SQL error: %s\n", errMsg);
  3345. }
  3346. }
  3347. int DB_addNetworkProfile(int slot, char *data)
  3348. {
  3349. int result = PASS;
  3350. char sql[512];
  3351. char* errMsg = NULL;
  3352. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  3353. slot,
  3354. data);
  3355. //* Execute SQL statement */
  3356. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  3357. {
  3358. DEBUG_INFO("SQL error: %s\n", errMsg);
  3359. result = FAIL;
  3360. }
  3361. return result;
  3362. }
  3363. int DB_deleteNetworkProfile(int slot)
  3364. {
  3365. int result = PASS;
  3366. char sql[512];
  3367. char* errMsg = NULL;
  3368. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  3369. //* Execute SQL statement */
  3370. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3371. {
  3372. DEBUG_INFO("SQL error: %s", errMsg);
  3373. result = FAIL;
  3374. }
  3375. return result;
  3376. }
  3377. int isNumber(uint8_t *string, uint8_t isFloat)
  3378. {
  3379. int result = NO;
  3380. int cntDecimal = 0;
  3381. float i;
  3382. for(int idx=0; idx<strlen((char*)string); idx++)
  3383. {
  3384. if((isdigit(string[idx])==0) && (string[idx] != '.'))
  3385. {
  3386. return result;
  3387. }
  3388. else if(string[idx] == '.')
  3389. cntDecimal++;
  3390. if(cntDecimal>1)
  3391. return result;
  3392. }
  3393. if((isFloat==FALSE) && (strstr((char*)string, ".") != NULL))
  3394. {
  3395. //DEBUG_INFO("%s is not pure integer!!\n", string);
  3396. }
  3397. else if((isFloat==TRUE) && (strstr((char*)string, ".") == NULL))
  3398. {
  3399. //DEBUG_INFO("%s is not float format!!\n", string);
  3400. }
  3401. else if(sscanf((char*)string, "%f", &i) != 0)
  3402. {
  3403. result = YES;
  3404. }
  3405. return result;
  3406. }
  3407. int isMatchTimeFormat(uint8_t *time)
  3408. {
  3409. int result = NO;
  3410. struct ParsingResult
  3411. {
  3412. int result;
  3413. int scanedElement;
  3414. int year;
  3415. int month;
  3416. int mday;
  3417. int hour;
  3418. int min;
  3419. int sec;
  3420. int tz_hour;
  3421. int tz_min;
  3422. float minSec;
  3423. }parsingResult;
  3424. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3425. if(strstr((char*)time, ".") != NULL)
  3426. {
  3427. // Original data with mini second
  3428. if(strstr((char*)time, "Z") != NULL)
  3429. {
  3430. // Original data with Z
  3431. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%fZ",
  3432. &parsingResult.year,
  3433. &parsingResult.month,
  3434. &parsingResult.mday,
  3435. &parsingResult.hour,
  3436. &parsingResult.min,
  3437. &parsingResult.sec,
  3438. &parsingResult.minSec);
  3439. }
  3440. else
  3441. {
  3442. // Original data without Z
  3443. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3444. &parsingResult.year,
  3445. &parsingResult.month,
  3446. &parsingResult.mday,
  3447. &parsingResult.hour,
  3448. &parsingResult.min,
  3449. &parsingResult.sec,
  3450. &parsingResult.minSec,
  3451. &parsingResult.tz_hour,
  3452. &parsingResult.tz_min);
  3453. }
  3454. }
  3455. else
  3456. {
  3457. // Original data without mini second
  3458. if(strstr((char*)time, "Z") != NULL)
  3459. {
  3460. // Original data with Z
  3461. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%dZ",
  3462. &parsingResult.year,
  3463. &parsingResult.month,
  3464. &parsingResult.mday,
  3465. &parsingResult.hour,
  3466. &parsingResult.min,
  3467. &parsingResult.sec);
  3468. }
  3469. else
  3470. {
  3471. // Original data without Z
  3472. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d%d:%d",
  3473. &parsingResult.year,
  3474. &parsingResult.month,
  3475. &parsingResult.mday,
  3476. &parsingResult.hour,
  3477. &parsingResult.min,
  3478. &parsingResult.sec,
  3479. &parsingResult.tz_hour,
  3480. &parsingResult.tz_min);
  3481. }
  3482. }
  3483. if(parsingResult.scanedElement >= 6)
  3484. {
  3485. result = YES;
  3486. }
  3487. return result;
  3488. }
  3489. int getCurrentYear()
  3490. {
  3491. int result = 0;
  3492. time_t CurrentTime;
  3493. struct tm *tm;
  3494. CurrentTime = time(NULL);
  3495. tm=localtime(&CurrentTime);
  3496. result = (tm->tm_year + 1900);
  3497. return result;
  3498. }
  3499. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  3500. {
  3501. int result = PASS;
  3502. char* errMsg = NULL;
  3503. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  3504. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  3505. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3506. {
  3507. result = FAIL;
  3508. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  3509. }
  3510. 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));
  3511. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3512. {
  3513. result = FAIL;
  3514. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  3515. }
  3516. return result;
  3517. }
  3518. //==========================================
  3519. // Check time passed since today
  3520. //==========================================
  3521. long long DiffTimebWithNow(struct timeb ST)
  3522. {
  3523. //return milli-second
  3524. struct timeb ET;
  3525. long long StartTime,StopTime;
  3526. ftime(&ET);
  3527. StartTime=(long long)ST.time;
  3528. StopTime=(long long)ET.time;
  3529. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  3530. }
  3531. int getTimePassSinceToday(uint8_t gun_index)
  3532. {
  3533. int result = -1;
  3534. static time_t lastTime[4];
  3535. time_t t;
  3536. struct tm *tmStartToday;
  3537. struct timeb tbStartToday;
  3538. t=time(NULL);
  3539. if(difftime(t, lastTime[gun_index])>0)
  3540. {
  3541. tmStartToday=localtime(&t);
  3542. tmStartToday->tm_hour = 0;
  3543. tmStartToday->tm_min = 0;
  3544. tmStartToday->tm_sec = 0;
  3545. tbStartToday.time = mktime(tmStartToday);
  3546. tbStartToday.millitm = 0;
  3547. result = DiffTimebWithNow(tbStartToday)/1000;
  3548. lastTime[gun_index] = t;
  3549. }
  3550. return result;
  3551. }
  3552. int syncDateTimeRTC(uint8_t *data)
  3553. {
  3554. struct ParsingResult
  3555. {
  3556. int result;
  3557. int scanedElement;
  3558. int year;
  3559. int month;
  3560. int mday;
  3561. int hour;
  3562. int min;
  3563. int sec;
  3564. int tz_hour;
  3565. int tz_min;
  3566. float minSec;
  3567. }result;
  3568. struct tm tmOrg;
  3569. struct tm *tmTarget;
  3570. struct timeb tbTarget;
  3571. char buf[128];
  3572. memset(&result, 0x00, sizeof(struct ParsingResult));
  3573. result.result = PASS;
  3574. if(strstr((char*)data, ".") != NULL)
  3575. {
  3576. // Original data with mini second
  3577. if(strstr((char*)data, "Z") != NULL)
  3578. {
  3579. // Original data with Z
  3580. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  3581. &result.year,
  3582. &result.month,
  3583. &result.mday,
  3584. &result.hour,
  3585. &result.min,
  3586. &result.sec,
  3587. &result.minSec);
  3588. }
  3589. else
  3590. {
  3591. // Original data without Z
  3592. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3593. &result.year,
  3594. &result.month,
  3595. &result.mday,
  3596. &result.hour,
  3597. &result.min,
  3598. &result.sec,
  3599. &result.minSec,
  3600. &result.tz_hour,
  3601. &result.tz_min);
  3602. }
  3603. }
  3604. else
  3605. {
  3606. // Original data without mini second
  3607. if(strstr((char*)data, "Z") != NULL)
  3608. {
  3609. // Original data with Z
  3610. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  3611. &result.year,
  3612. &result.month,
  3613. &result.mday,
  3614. &result.hour,
  3615. &result.min,
  3616. &result.sec);
  3617. }
  3618. else
  3619. {
  3620. // Original data without Z
  3621. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  3622. &result.year,
  3623. &result.month,
  3624. &result.mday,
  3625. &result.hour,
  3626. &result.min,
  3627. &result.sec,
  3628. &result.tz_hour,
  3629. &result.tz_min);
  3630. }
  3631. }
  3632. tmOrg.tm_year = result.year - 1900;
  3633. tmOrg.tm_mon = result.month - 1;
  3634. tmOrg.tm_mday = result.mday;
  3635. tmOrg.tm_hour = result.hour;
  3636. tmOrg.tm_min = result.min;
  3637. tmOrg.tm_sec = result.sec;
  3638. tmOrg.tm_gmtoff = 0;
  3639. tbTarget.time = mktime(&tmOrg);
  3640. tbTarget.timezone = 0;
  3641. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  3642. tmTarget = gmtime(&tbTarget.time);
  3643. 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);
  3644. //DEBUG_INFO(" org date time: %s\n", data);
  3645. //DEBUG_INFO("parse date time: %s\n", buf);
  3646. system(buf);
  3647. system("/sbin/hwclock -w --systohc");
  3648. if(result.scanedElement < 6)
  3649. result.result = FAIL;
  3650. return result.result;
  3651. }
  3652. //==========================================
  3653. // GetCompositeSchedule logic related function
  3654. //==========================================
  3655. int DiffTimebSec(struct timeb ST, struct timeb ET)
  3656. {
  3657. //return milli-second
  3658. unsigned int StartTime,StopTime;
  3659. StartTime=(unsigned int)ST.time;
  3660. StopTime=(unsigned int)ET.time;
  3661. return (StopTime-StartTime);
  3662. }
  3663. int DiffTimebWithNowSec(struct timeb ST)
  3664. {
  3665. //return milli-second
  3666. struct timeb ET;
  3667. unsigned int StartTime,StopTime;
  3668. ftime(&ET);
  3669. StartTime=(unsigned int)ST.time;
  3670. StopTime=(unsigned int)ET.time;
  3671. return (StopTime-StartTime);
  3672. }
  3673. int getStartStop(uint8_t *start, uint8_t *stop)
  3674. {
  3675. struct ParsingResult
  3676. {
  3677. int result;
  3678. int scanedElement;
  3679. int year;
  3680. int month;
  3681. int mday;
  3682. int hour;
  3683. int min;
  3684. int sec;
  3685. int tz_hour;
  3686. int tz_min;
  3687. float minSec;
  3688. };
  3689. struct ParsingResult parseStart;
  3690. struct ParsingResult parseStop;
  3691. int result = -1;
  3692. struct tm tmStart;
  3693. struct timeb tbStart;
  3694. struct tm tmStop;
  3695. struct timeb tbStop;
  3696. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3697. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3698. // Scan start & stop date time
  3699. if(strstr((char*)start, ".") != NULL)
  3700. {
  3701. // Original data with mini second
  3702. if(strstr((char*)start, "Z") != NULL)
  3703. {
  3704. // Original data with Z
  3705. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3706. &parseStart.year,
  3707. &parseStart.month,
  3708. &parseStart.mday,
  3709. &parseStart.hour,
  3710. &parseStart.min,
  3711. &parseStart.sec,
  3712. &parseStart.minSec);
  3713. }
  3714. else
  3715. {
  3716. // Original data without Z
  3717. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3718. &parseStart.year,
  3719. &parseStart.month,
  3720. &parseStart.mday,
  3721. &parseStart.hour,
  3722. &parseStart.min,
  3723. &parseStart.sec,
  3724. &parseStart.minSec,
  3725. &parseStart.tz_hour,
  3726. &parseStart.tz_min);
  3727. }
  3728. }
  3729. else
  3730. {
  3731. // Original data without mini second
  3732. if(strstr((char*)start, "Z") != NULL)
  3733. {
  3734. // Original data with Z
  3735. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3736. &parseStart.year,
  3737. &parseStart.month,
  3738. &parseStart.mday,
  3739. &parseStart.hour,
  3740. &parseStart.min,
  3741. &parseStart.sec);
  3742. }
  3743. else
  3744. {
  3745. // Original data without Z
  3746. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3747. &parseStart.year,
  3748. &parseStart.month,
  3749. &parseStart.mday,
  3750. &parseStart.hour,
  3751. &parseStart.min,
  3752. &parseStart.sec,
  3753. &parseStart.tz_hour,
  3754. &parseStart.tz_min);
  3755. }
  3756. }
  3757. if(strstr((char*)stop, ".") != NULL)
  3758. {
  3759. // Original data with mini second
  3760. if(strstr((char*)stop, "Z") != NULL)
  3761. {
  3762. // Original data with Z
  3763. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3764. &parseStop.year,
  3765. &parseStop.month,
  3766. &parseStop.mday,
  3767. &parseStop.hour,
  3768. &parseStop.min,
  3769. &parseStop.sec,
  3770. &parseStop.minSec);
  3771. }
  3772. else
  3773. {
  3774. // Original data without Z
  3775. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3776. &parseStop.year,
  3777. &parseStop.month,
  3778. &parseStop.mday,
  3779. &parseStop.hour,
  3780. &parseStop.min,
  3781. &parseStop.sec,
  3782. &parseStop.minSec,
  3783. &parseStop.tz_hour,
  3784. &parseStop.tz_min);
  3785. }
  3786. }
  3787. else
  3788. {
  3789. // Original data without mini second
  3790. if(strstr((char*)stop, "Z") != NULL)
  3791. {
  3792. // Original data with Z
  3793. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3794. &parseStop.year,
  3795. &parseStop.month,
  3796. &parseStop.mday,
  3797. &parseStop.hour,
  3798. &parseStop.min,
  3799. &parseStop.sec);
  3800. }
  3801. else
  3802. {
  3803. // Original data without Z
  3804. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3805. &parseStop.year,
  3806. &parseStop.month,
  3807. &parseStop.mday,
  3808. &parseStop.hour,
  3809. &parseStop.min,
  3810. &parseStop.sec,
  3811. &parseStop.tz_hour,
  3812. &parseStop.tz_min);
  3813. }
  3814. }
  3815. // Calculate date time difference
  3816. if((parseStart.scanedElement >=6) &&
  3817. (parseStop.scanedElement >=6))
  3818. {
  3819. //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);
  3820. //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);
  3821. tmStart.tm_year = parseStart.year - 1900;
  3822. tmStart.tm_mon = parseStart.month - 1;
  3823. tmStart.tm_mday = parseStart.mday;
  3824. tmStart.tm_hour = parseStart.hour;
  3825. tmStart.tm_min = parseStart.min;
  3826. tmStart.tm_sec = parseStart.sec;
  3827. tmStart.tm_gmtoff = 0;
  3828. tbStart.time = mktime(&tmStart);
  3829. tbStart.timezone = 0;
  3830. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3831. tmStop.tm_year = parseStop.year - 1900;
  3832. tmStop.tm_mon = parseStop.month - 1;
  3833. tmStop.tm_mday = parseStop.mday;
  3834. tmStop.tm_hour = parseStop.hour;
  3835. tmStop.tm_min = parseStop.min;
  3836. tmStop.tm_sec = parseStop.sec;
  3837. tmStop.tm_gmtoff = 0;
  3838. tbStop.time = mktime(&tmStop);
  3839. tbStop.timezone = 0;
  3840. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3841. result = DiffTimebSec(tbStart, tbStop);
  3842. //DEBUG_INFO("getStartStop(): %d\n", result);
  3843. }
  3844. else
  3845. {
  3846. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3847. }
  3848. return result;
  3849. }
  3850. int isOvertNow(uint8_t *start)
  3851. {
  3852. int result = NO;
  3853. struct ParsingResult
  3854. {
  3855. int result;
  3856. int scanedElement;
  3857. int year;
  3858. int month;
  3859. int mday;
  3860. int hour;
  3861. int min;
  3862. int sec;
  3863. int tz_hour;
  3864. int tz_min;
  3865. float minSec;
  3866. }parsingResult;
  3867. struct tm tmStart;
  3868. struct timeb tbStart;
  3869. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3870. if(strstr((char*)start, ".") != NULL)
  3871. {
  3872. // Original data with mini second
  3873. if(strstr((char*)start, "Z") != NULL)
  3874. {
  3875. // Original data with Z
  3876. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3877. &parsingResult.year,
  3878. &parsingResult.month,
  3879. &parsingResult.mday,
  3880. &parsingResult.hour,
  3881. &parsingResult.min,
  3882. &parsingResult.sec,
  3883. &parsingResult.minSec);
  3884. }
  3885. else
  3886. {
  3887. // Original data without Z
  3888. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3889. &parsingResult.year,
  3890. &parsingResult.month,
  3891. &parsingResult.mday,
  3892. &parsingResult.hour,
  3893. &parsingResult.min,
  3894. &parsingResult.sec,
  3895. &parsingResult.minSec,
  3896. &parsingResult.tz_hour,
  3897. &parsingResult.tz_min);
  3898. }
  3899. }
  3900. else
  3901. {
  3902. // Original data without mini second
  3903. if(strstr((char*)start, "Z") != NULL)
  3904. {
  3905. // Original data with Z
  3906. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3907. &parsingResult.year,
  3908. &parsingResult.month,
  3909. &parsingResult.mday,
  3910. &parsingResult.hour,
  3911. &parsingResult.min,
  3912. &parsingResult.sec);
  3913. }
  3914. else
  3915. {
  3916. // Original data without Z
  3917. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3918. &parsingResult.year,
  3919. &parsingResult.month,
  3920. &parsingResult.mday,
  3921. &parsingResult.hour,
  3922. &parsingResult.min,
  3923. &parsingResult.sec,
  3924. &parsingResult.tz_hour,
  3925. &parsingResult.tz_min);
  3926. }
  3927. }
  3928. if(parsingResult.scanedElement >= 6)
  3929. {
  3930. tmStart.tm_year = parsingResult.year - 1900;
  3931. tmStart.tm_mon = parsingResult.month - 1;
  3932. tmStart.tm_mday = parsingResult.mday;
  3933. tmStart.tm_hour = parsingResult.hour;
  3934. tmStart.tm_min = parsingResult.min;
  3935. tmStart.tm_sec = parsingResult.sec;
  3936. tmStart.tm_gmtoff = 0;
  3937. tbStart.time = mktime(&tmStart);
  3938. tbStart.timezone = 0;
  3939. tbStart.millitm = 0;
  3940. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3941. if(DiffTimebWithNowSec(tbStart) <= 0)
  3942. result = NO;
  3943. else
  3944. result = YES;
  3945. }
  3946. else
  3947. {
  3948. DEBUG_WARN("Start date parsing error.\n");
  3949. }
  3950. return result;
  3951. }
  3952. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3953. {
  3954. struct ParsingResult
  3955. {
  3956. int result;
  3957. int scanedElement;
  3958. int year;
  3959. int month;
  3960. int mday;
  3961. int hour;
  3962. int min;
  3963. int sec;
  3964. int tz_hour;
  3965. int tz_min;
  3966. float minSec;
  3967. };
  3968. struct ParsingResult parseStart;
  3969. struct ParsingResult parseStop;
  3970. int result = -1;
  3971. struct tm tmStart;
  3972. struct timeb tbStart;
  3973. struct tm tmStop;
  3974. struct timeb tbStop;
  3975. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3976. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3977. // Scan start & stop date time
  3978. if(strstr((char*)start, ".") != NULL)
  3979. {
  3980. // Original data with mini second
  3981. if(strstr((char*)start, "Z") != NULL)
  3982. {
  3983. // Original data with Z
  3984. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3985. &parseStart.year,
  3986. &parseStart.month,
  3987. &parseStart.mday,
  3988. &parseStart.hour,
  3989. &parseStart.min,
  3990. &parseStart.sec,
  3991. &parseStart.minSec);
  3992. }
  3993. else
  3994. {
  3995. // Original data without Z
  3996. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3997. &parseStart.year,
  3998. &parseStart.month,
  3999. &parseStart.mday,
  4000. &parseStart.hour,
  4001. &parseStart.min,
  4002. &parseStart.sec,
  4003. &parseStart.minSec,
  4004. &parseStart.tz_hour,
  4005. &parseStart.tz_min);
  4006. }
  4007. }
  4008. else
  4009. {
  4010. // Original data without mini second
  4011. if(strstr((char*)start, "Z") != NULL)
  4012. {
  4013. // Original data with Z
  4014. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  4015. &parseStart.year,
  4016. &parseStart.month,
  4017. &parseStart.mday,
  4018. &parseStart.hour,
  4019. &parseStart.min,
  4020. &parseStart.sec);
  4021. }
  4022. else
  4023. {
  4024. // Original data without Z
  4025. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  4026. &parseStart.year,
  4027. &parseStart.month,
  4028. &parseStart.mday,
  4029. &parseStart.hour,
  4030. &parseStart.min,
  4031. &parseStart.sec,
  4032. &parseStart.tz_hour,
  4033. &parseStart.tz_min);
  4034. }
  4035. }
  4036. if(strstr((char*)stop, ".") != NULL)
  4037. {
  4038. // Original data with mini second
  4039. if(strstr((char*)stop, "Z") != NULL)
  4040. {
  4041. // Original data with Z
  4042. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  4043. &parseStop.year,
  4044. &parseStop.month,
  4045. &parseStop.mday,
  4046. &parseStop.hour,
  4047. &parseStop.min,
  4048. &parseStop.sec,
  4049. &parseStop.minSec);
  4050. }
  4051. else
  4052. {
  4053. // Original data without Z
  4054. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  4055. &parseStop.year,
  4056. &parseStop.month,
  4057. &parseStop.mday,
  4058. &parseStop.hour,
  4059. &parseStop.min,
  4060. &parseStop.sec,
  4061. &parseStop.minSec,
  4062. &parseStop.tz_hour,
  4063. &parseStop.tz_min);
  4064. }
  4065. }
  4066. else
  4067. {
  4068. // Original data without mini second
  4069. if(strstr((char*)stop, "Z") != NULL)
  4070. {
  4071. // Original data with Z
  4072. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  4073. &parseStop.year,
  4074. &parseStop.month,
  4075. &parseStop.mday,
  4076. &parseStop.hour,
  4077. &parseStop.min,
  4078. &parseStop.sec);
  4079. }
  4080. else
  4081. {
  4082. // Original data without Z
  4083. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  4084. &parseStop.year,
  4085. &parseStop.month,
  4086. &parseStop.mday,
  4087. &parseStop.hour,
  4088. &parseStop.min,
  4089. &parseStop.sec,
  4090. &parseStop.tz_hour,
  4091. &parseStop.tz_min);
  4092. }
  4093. }
  4094. // Calculate date time difference
  4095. if((parseStart.scanedElement >=6) &&
  4096. (parseStop.scanedElement >=6))
  4097. {
  4098. //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);
  4099. //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);
  4100. tmStart.tm_year = parseStart.year - 1900;
  4101. tmStart.tm_mon = parseStart.month - 1;
  4102. tmStart.tm_mday = parseStart.mday;
  4103. tmStart.tm_hour = parseStart.hour;
  4104. tmStart.tm_min = parseStart.min;
  4105. tmStart.tm_sec = parseStart.sec;
  4106. tmStart.tm_gmtoff = 0;
  4107. tbStart.time = mktime(&tmStart);
  4108. tbStart.timezone = 0;
  4109. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  4110. tmStop.tm_year = parseStop.year - 1900;
  4111. tmStop.tm_mon = parseStop.month - 1;
  4112. tmStop.tm_mday = parseStop.mday;
  4113. tmStop.tm_hour = parseStop.hour;
  4114. tmStop.tm_min = parseStop.min;
  4115. tmStop.tm_sec = parseStop.sec;
  4116. tmStop.tm_gmtoff = 0;
  4117. tbStop.time = mktime(&tmStop);
  4118. tbStop.timezone = 0;
  4119. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  4120. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  4121. //DEBUG_INFO("getStartStop(): %d\n", result);
  4122. }
  4123. else
  4124. {
  4125. DEBUG_WARN("Start or stop date parsing error.\r\n");
  4126. }
  4127. return result;
  4128. }
  4129. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4130. {
  4131. FILE *fp;
  4132. char profileFileName[128];
  4133. char *line = NULL;
  4134. size_t len = 0;
  4135. time_t CurrentTime;
  4136. struct tm *tmComposite;
  4137. struct ChargingProfileType maxProfile;
  4138. struct ChargingProfileType compositeProfile;
  4139. uint8_t limitMax=0;
  4140. int compositePeriodIdx = 0;
  4141. CurrentTime = time(NULL);
  4142. tmComposite=localtime(&CurrentTime);
  4143. 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);
  4144. if(isUnitA)
  4145. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4146. else
  4147. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4148. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4149. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4150. {
  4151. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4152. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4153. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4154. }
  4155. compositeProfile.id = 0;
  4156. compositeProfile.stackLevel = 99 ;
  4157. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  4158. maxProfile.id = -1;
  4159. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4160. system("rm -f /tmp/*.json");
  4161. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4162. // Search max profile
  4163. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4164. if((access(profileFileName, F_OK))!=-1)
  4165. {
  4166. fp = fopen(profileFileName, "r");
  4167. while(getline(&line, &len, fp) != -1)
  4168. {
  4169. json_object *obj = NULL;
  4170. obj = json_tokener_parse(line);
  4171. if(is_error(obj))
  4172. {
  4173. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4174. }
  4175. else
  4176. {
  4177. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4178. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4179. )
  4180. {
  4181. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4182. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4183. )
  4184. {
  4185. struct tm tmFrom, tmTo;
  4186. struct timeb tbFrom, tbTo;
  4187. 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) &&
  4188. (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))
  4189. {
  4190. tmFrom.tm_year -= 1900;
  4191. tmFrom.tm_mon -= 1;
  4192. tbFrom.time = mktime(&tmFrom);
  4193. tmTo.tm_year -= 1900;
  4194. tmTo.tm_mon -= 1;
  4195. tbTo.time = mktime(&tmTo);
  4196. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4197. {
  4198. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4199. {
  4200. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4201. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4202. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4203. }
  4204. if(maxProfile.id == -1)
  4205. DEBUG_INFO("MaxProfile found.\n");
  4206. else
  4207. DEBUG_INFO("MaxProfile updated.\n");
  4208. // Required item
  4209. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4210. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4211. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4212. if(isUnitA)
  4213. {
  4214. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4215. 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++)
  4216. {
  4217. 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"));
  4218. 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"));
  4219. /*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)
  4220. {
  4221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4222. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4223. else
  4224. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4225. }
  4226. else
  4227. {
  4228. 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"));
  4229. }*/
  4230. 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")));
  4231. }
  4232. }
  4233. else
  4234. {
  4235. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4236. 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++)
  4237. {
  4238. 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"));
  4239. 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"));
  4240. /*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)
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4243. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4244. else
  4245. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4246. }
  4247. else
  4248. {
  4249. 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"));
  4250. }*/
  4251. 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));
  4252. }
  4253. }
  4254. // Optional item
  4255. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4256. {
  4257. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4258. }
  4259. else
  4260. {
  4261. sprintf((char*)maxProfile.validFrom, " ");
  4262. }
  4263. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4264. {
  4265. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4266. }
  4267. else
  4268. {
  4269. sprintf((char*)maxProfile.validTo, " ");
  4270. }
  4271. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4272. {
  4273. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4274. }
  4275. else
  4276. {
  4277. sprintf((char*)maxProfile.recurrencyKind, " ");
  4278. }
  4279. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4280. {
  4281. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4282. }
  4283. else
  4284. {
  4285. sprintf((char*)maxProfile.transactionId, " ");
  4286. }
  4287. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4288. {
  4289. 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"));
  4290. }
  4291. else
  4292. {
  4293. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4294. }
  4295. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4296. {
  4297. 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")));
  4298. }
  4299. else
  4300. {
  4301. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4302. }
  4303. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4304. {
  4305. 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"));
  4306. }
  4307. else
  4308. {
  4309. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4310. }
  4311. }
  4312. }
  4313. }
  4314. else
  4315. {
  4316. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4317. {
  4318. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4319. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4320. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4321. }
  4322. if(maxProfile.id == -1)
  4323. DEBUG_INFO("MaxProfile found.\n");
  4324. else
  4325. DEBUG_INFO("MaxProfile updated.\n");
  4326. // Required item
  4327. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4328. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4329. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4330. if(isUnitA)
  4331. {
  4332. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4333. 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++)
  4334. {
  4335. 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"));
  4336. 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"));
  4337. /*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)
  4338. {
  4339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4340. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4341. else
  4342. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4343. }
  4344. else
  4345. {
  4346. 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"));
  4347. }*/
  4348. 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")));
  4349. }
  4350. }
  4351. else
  4352. {
  4353. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4354. 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++)
  4355. {
  4356. 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"));
  4357. 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"));
  4358. /*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)
  4359. {
  4360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4361. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4362. else
  4363. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4364. }
  4365. else
  4366. {
  4367. 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"));
  4368. }*/
  4369. 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));
  4370. }
  4371. }
  4372. // Optional item
  4373. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4374. {
  4375. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4376. }
  4377. else
  4378. {
  4379. sprintf((char*)maxProfile.validFrom, " ");
  4380. }
  4381. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4382. {
  4383. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4384. }
  4385. else
  4386. {
  4387. sprintf((char*)maxProfile.validTo, " ");
  4388. }
  4389. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4390. {
  4391. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4392. }
  4393. else
  4394. {
  4395. sprintf((char*)maxProfile.recurrencyKind, " ");
  4396. }
  4397. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4398. {
  4399. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4400. }
  4401. else
  4402. {
  4403. sprintf((char*)maxProfile.transactionId, " ");
  4404. }
  4405. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4406. {
  4407. 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"));
  4408. }
  4409. else
  4410. {
  4411. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4412. }
  4413. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4414. {
  4415. 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")));
  4416. }
  4417. else
  4418. {
  4419. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4420. }
  4421. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4422. {
  4423. 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"));
  4424. }
  4425. else
  4426. {
  4427. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4428. }
  4429. }
  4430. }
  4431. }
  4432. json_object_put(obj);
  4433. }
  4434. fclose(fp);
  4435. /*
  4436. if(maxProfile.id !=-1)
  4437. {
  4438. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4439. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4440. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4441. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4442. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4443. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4444. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4445. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4446. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4447. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4448. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4449. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4450. {
  4451. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4452. {
  4453. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4454. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4455. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4456. }
  4457. }
  4458. }
  4459. else
  4460. DEBUG_INFO("MaxProfile not found.\n");
  4461. DEBUG_INFO("------------------------------------\n");*/
  4462. }
  4463. if(maxProfile.id != -1)
  4464. {
  4465. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4466. {
  4467. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4468. {
  4469. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4470. 0:
  4471. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4472. }
  4473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4474. {
  4475. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4476. {
  4477. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4478. 0:
  4479. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4480. if(idxPeriod > 0)
  4481. {
  4482. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4483. {
  4484. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4485. }
  4486. }
  4487. }
  4488. }
  4489. }
  4490. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4491. {
  4492. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4493. {
  4494. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  4495. }
  4496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4497. {
  4498. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4499. {
  4500. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  4501. if(idxPeriod > 0)
  4502. {
  4503. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4504. {
  4505. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4506. }
  4507. }
  4508. }
  4509. }
  4510. }
  4511. else
  4512. {
  4513. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4514. {
  4515. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4516. {
  4517. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4518. 0:
  4519. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4520. }
  4521. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4522. {
  4523. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4524. {
  4525. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4526. 0:
  4527. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4528. if(idxPeriod > 0)
  4529. {
  4530. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4531. {
  4532. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4533. }
  4534. }
  4535. }
  4536. }
  4537. }
  4538. else
  4539. {
  4540. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4541. {
  4542. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4543. 0:
  4544. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4545. }
  4546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4547. {
  4548. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4549. {
  4550. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4551. 0:
  4552. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4553. if(idxPeriod > 0)
  4554. {
  4555. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4556. {
  4557. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4558. }
  4559. }
  4560. }
  4561. }
  4562. }
  4563. }
  4564. /*
  4565. DEBUG_INFO("MaxProfile after align.\n");
  4566. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4567. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4568. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4569. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4570. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4571. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4572. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4573. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4574. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4575. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4576. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4577. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4578. {
  4579. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4580. {
  4581. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4582. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4583. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4584. }
  4585. }
  4586. DEBUG_INFO("------------------------------------\n");*/
  4587. }
  4588. // Find each profile period quantity
  4589. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4590. {
  4591. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4592. limitMax = idx+1;
  4593. }
  4594. if(maxProfile.id != -1)
  4595. {
  4596. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4597. {
  4598. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4599. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4600. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4601. {
  4602. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4603. {
  4604. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4605. compositePeriodIdx++;
  4606. }
  4607. else
  4608. {
  4609. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4610. }
  4611. }
  4612. }
  4613. }
  4614. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  4615. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4616. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  4617. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  4618. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4619. {
  4620. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4621. {
  4622. compositeProfile.id = 1;
  4623. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4624. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4625. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4626. }
  4627. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4628. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4629. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4630. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4631. }
  4632. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4633. if(line)
  4634. free(line);
  4635. }
  4636. void checkCompositeSchedule(uint8_t evseId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4637. {
  4638. FILE *fp;
  4639. char profileFileName[128];
  4640. char *line = NULL;
  4641. size_t len = 0;
  4642. time_t CurrentTime;
  4643. struct tm *tmComposite;
  4644. struct ChargingProfileType maxProfile;
  4645. struct ChargingProfileType defaultTxProfile;
  4646. struct ChargingProfileType txProfile;
  4647. struct ChargingProfileType compositeProfile;
  4648. struct ChargingSchedulePeriodType tmpPeriod;
  4649. uint8_t limitMax=0;
  4650. uint8_t limitDef=0;
  4651. uint8_t limitTx=0;
  4652. int compositePeriodIdx = 0;
  4653. CurrentTime = time(NULL);
  4654. tmComposite=localtime(&CurrentTime);
  4655. 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);
  4656. if(isUnitA)
  4657. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4658. else
  4659. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4660. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4661. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4662. {
  4663. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4664. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4665. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4666. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4667. }
  4668. compositeProfile.id = 0;
  4669. compositeProfile.stackLevel = 99 ;
  4670. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  4671. maxProfile.id = -1;
  4672. defaultTxProfile.id = -1;
  4673. txProfile.id = -1;
  4674. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4675. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  4676. txProfile.chargingSchedule[idxSchedule].duration = -1;
  4677. system("rm -f /tmp/*.json");
  4678. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4679. /*
  4680. * Search valid charging profile
  4681. */
  4682. //DEBUG_INFO("====================================\n");
  4683. // Search tx profile
  4684. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", evseId);
  4685. if((access(profileFileName, F_OK))!=-1)
  4686. {
  4687. fp = fopen(profileFileName, "r");
  4688. while(getline(&line, &len, fp) != -1)
  4689. {
  4690. json_object *obj = NULL;
  4691. obj = json_tokener_parse(line);
  4692. if(is_error(obj))
  4693. {
  4694. DEBUG_ERROR("Parse txProfile from file error.\n");
  4695. }
  4696. else
  4697. {
  4698. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  4699. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  4700. )
  4701. {
  4702. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4703. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4704. )
  4705. {
  4706. struct tm tmFrom, tmTo;
  4707. struct timeb tbFrom, tbTo;
  4708. 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) &&
  4709. (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))
  4710. {
  4711. tmFrom.tm_year -= 1900;
  4712. tmFrom.tm_mon -= 1;
  4713. tbFrom.time = mktime(&tmFrom);
  4714. tmTo.tm_year -= 1900;
  4715. tmTo.tm_mon -= 1;
  4716. tbTo.time = mktime(&tmTo);
  4717. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4718. {
  4719. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4720. {
  4721. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4722. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4723. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4724. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4725. }
  4726. if(txProfile.id == -1)
  4727. DEBUG_INFO("TxProfile found.\n");
  4728. else
  4729. DEBUG_INFO("TxProfile updated.\n");
  4730. // Required item
  4731. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4732. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4733. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4734. if(isUnitA)
  4735. {
  4736. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4737. 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++)
  4738. {
  4739. 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"));
  4740. 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"));
  4741. /*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)
  4742. {
  4743. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4744. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4745. else
  4746. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4747. }
  4748. else
  4749. {
  4750. 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"));
  4751. }*/
  4752. 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")));
  4753. }
  4754. }
  4755. else
  4756. {
  4757. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4758. 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++)
  4759. {
  4760. 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"));
  4761. 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"));
  4762. /*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)
  4763. {
  4764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4765. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4766. else
  4767. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4768. }
  4769. else
  4770. {
  4771. 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"));
  4772. }*/
  4773. 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));
  4774. }
  4775. }
  4776. // Optional item
  4777. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4778. {
  4779. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4780. }
  4781. else
  4782. {
  4783. sprintf((char*)txProfile.validFrom, " ");
  4784. }
  4785. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4786. {
  4787. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4788. }
  4789. else
  4790. {
  4791. sprintf((char*)txProfile.validTo, " ");
  4792. }
  4793. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4794. {
  4795. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4796. }
  4797. else
  4798. {
  4799. sprintf((char*)txProfile.recurrencyKind, " ");
  4800. }
  4801. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4802. {
  4803. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4804. }
  4805. else
  4806. {
  4807. sprintf((char*)txProfile.transactionId, " ");
  4808. }
  4809. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4810. {
  4811. 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"));
  4812. }
  4813. else
  4814. {
  4815. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4816. }
  4817. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4818. {
  4819. 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")));
  4820. }
  4821. else
  4822. {
  4823. 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));
  4824. }
  4825. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4826. {
  4827. 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"));
  4828. }
  4829. else
  4830. {
  4831. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4832. }
  4833. }
  4834. }
  4835. }
  4836. else
  4837. {
  4838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4839. {
  4840. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4841. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4842. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4843. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4844. }
  4845. if(txProfile.id == -1)
  4846. DEBUG_INFO("TxProfile found.\n");
  4847. else
  4848. DEBUG_INFO("TxProfile updated.\n");
  4849. // Required item
  4850. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4851. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4852. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4853. if(isUnitA)
  4854. {
  4855. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4856. 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++)
  4857. {
  4858. 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"));
  4859. 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"));
  4860. /*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)
  4861. {
  4862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4863. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4864. else
  4865. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4866. }
  4867. else
  4868. {
  4869. 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"));
  4870. }*/
  4871. 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")));
  4872. }
  4873. }
  4874. else
  4875. {
  4876. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4877. 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++)
  4878. {
  4879. 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"));
  4880. 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"));
  4881. /*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)
  4882. {
  4883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4884. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4885. else
  4886. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4887. }
  4888. else
  4889. {
  4890. 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"));
  4891. }*/
  4892. 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));
  4893. }
  4894. }
  4895. // Optional item
  4896. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4897. {
  4898. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4899. }
  4900. else
  4901. {
  4902. sprintf((char*)txProfile.validFrom, " ");
  4903. }
  4904. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4905. {
  4906. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4907. }
  4908. else
  4909. {
  4910. sprintf((char*)txProfile.validTo, " ");
  4911. }
  4912. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4913. {
  4914. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4915. }
  4916. else
  4917. {
  4918. sprintf((char*)txProfile.recurrencyKind, " ");
  4919. }
  4920. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4921. {
  4922. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4923. }
  4924. else
  4925. {
  4926. sprintf((char*)txProfile.transactionId, " ");
  4927. }
  4928. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4929. {
  4930. 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"));
  4931. }
  4932. else
  4933. {
  4934. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4935. }
  4936. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4937. {
  4938. 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")));
  4939. }
  4940. else
  4941. {
  4942. 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));
  4943. }
  4944. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4945. {
  4946. 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"));
  4947. }
  4948. else
  4949. {
  4950. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4951. }
  4952. }
  4953. }
  4954. }
  4955. json_object_put(obj);
  4956. }
  4957. fclose(fp);
  4958. /*
  4959. if(txProfile.id != -1)
  4960. {
  4961. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4962. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4963. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4964. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4965. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4966. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4967. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4968. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  4969. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4970. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4971. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4972. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4973. {
  4974. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4975. {
  4976. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4977. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4978. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4979. }
  4980. }
  4981. }
  4982. else
  4983. DEBUG_INFO("TxProfile not found.\n");*/
  4984. }
  4985. // Search default tx profile
  4986. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", evseId);
  4987. if((access(profileFileName, F_OK))==-1)
  4988. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  4989. if((access(profileFileName, F_OK))!=-1)
  4990. {
  4991. fp = fopen(profileFileName, "r");
  4992. while(getline(&line, &len, fp) != -1)
  4993. {
  4994. json_object *obj = NULL;
  4995. obj = json_tokener_parse(line);
  4996. if(is_error(obj))
  4997. {
  4998. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  4999. }
  5000. else
  5001. {
  5002. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  5003. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  5004. )
  5005. {
  5006. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  5007. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5008. )
  5009. {
  5010. struct tm tmFrom, tmTo;
  5011. struct timeb tbFrom, tbTo;
  5012. 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) &&
  5013. (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))
  5014. {
  5015. tmFrom.tm_year -= 1900;
  5016. tmFrom.tm_mon -= 1;
  5017. tbFrom.time = mktime(&tmFrom);
  5018. tmTo.tm_year -= 1900;
  5019. tmTo.tm_mon -= 1;
  5020. tbTo.time = mktime(&tmTo);
  5021. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  5022. {
  5023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5024. {
  5025. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5026. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5027. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5028. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  5029. }
  5030. if(defaultTxProfile.id == -1)
  5031. DEBUG_INFO("TxDefaultProfile found.\n");
  5032. else
  5033. DEBUG_INFO("TxDefaultProfile updated.\n");
  5034. // Required item
  5035. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5036. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5037. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5038. if(isUnitA)
  5039. {
  5040. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5041. 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++)
  5042. {
  5043. 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"));
  5044. 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"));
  5045. /*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)
  5046. {
  5047. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5048. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5049. else
  5050. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5051. }
  5052. else
  5053. {
  5054. 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"));
  5055. }*/
  5056. 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")));
  5057. }
  5058. }
  5059. else
  5060. {
  5061. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5062. 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++)
  5063. {
  5064. 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"));
  5065. 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"));
  5066. /*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)
  5067. {
  5068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5069. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5070. else
  5071. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5072. }
  5073. else
  5074. {
  5075. 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"));
  5076. }*/
  5077. 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));
  5078. }
  5079. }
  5080. // Optional item
  5081. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5082. {
  5083. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5084. }
  5085. else
  5086. {
  5087. sprintf((char*)defaultTxProfile.validFrom, " ");
  5088. }
  5089. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5090. {
  5091. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5092. }
  5093. else
  5094. {
  5095. sprintf((char*)defaultTxProfile.validTo, " ");
  5096. }
  5097. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5098. {
  5099. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5100. }
  5101. else
  5102. {
  5103. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  5104. }
  5105. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5106. {
  5107. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5108. }
  5109. else
  5110. {
  5111. sprintf((char*)defaultTxProfile.transactionId, " ");
  5112. }
  5113. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5114. {
  5115. 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"));
  5116. }
  5117. else
  5118. {
  5119. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5120. }
  5121. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5122. {
  5123. 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")));
  5124. }
  5125. else
  5126. {
  5127. 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));
  5128. }
  5129. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5130. {
  5131. 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"));
  5132. }
  5133. else
  5134. {
  5135. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5136. }
  5137. }
  5138. }
  5139. }
  5140. else
  5141. {
  5142. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5143. {
  5144. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5145. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5146. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5147. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  5148. }
  5149. if(defaultTxProfile.id == -1)
  5150. DEBUG_INFO("TxDefaultProfile found.\n");
  5151. else
  5152. DEBUG_INFO("TxDefaultProfile updated.\n");
  5153. // Required item
  5154. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5155. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5156. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5157. if(isUnitA)
  5158. {
  5159. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5160. 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++)
  5161. {
  5162. 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"));
  5163. 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"));
  5164. /*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)
  5165. {
  5166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5167. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5168. else
  5169. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5170. }
  5171. else
  5172. {
  5173. 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"));
  5174. }*/
  5175. 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")));
  5176. }
  5177. }
  5178. else
  5179. {
  5180. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5181. 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++)
  5182. {
  5183. 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"));
  5184. 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"));
  5185. /*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)
  5186. {
  5187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5188. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5189. else
  5190. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5191. }
  5192. else
  5193. {
  5194. 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"));
  5195. }*/
  5196. 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));
  5197. }
  5198. }
  5199. // Optional item
  5200. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5201. {
  5202. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5203. }
  5204. else
  5205. {
  5206. sprintf((char*)defaultTxProfile.validFrom, " ");
  5207. }
  5208. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5209. {
  5210. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5211. }
  5212. else
  5213. {
  5214. sprintf((char*)defaultTxProfile.validTo, " ");
  5215. }
  5216. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5217. {
  5218. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5219. }
  5220. else
  5221. {
  5222. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  5223. }
  5224. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5225. {
  5226. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5227. }
  5228. else
  5229. {
  5230. sprintf((char*)defaultTxProfile.transactionId, " ");
  5231. }
  5232. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5233. {
  5234. 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"));
  5235. }
  5236. else
  5237. {
  5238. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5239. }
  5240. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5241. {
  5242. 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")));
  5243. }
  5244. else
  5245. {
  5246. 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));
  5247. }
  5248. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5249. {
  5250. 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"));
  5251. }
  5252. else
  5253. {
  5254. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5255. }
  5256. }
  5257. }
  5258. }
  5259. json_object_put(obj);
  5260. }
  5261. fclose(fp);
  5262. /*
  5263. if(defaultTxProfile.id != -1)
  5264. {
  5265. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5266. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5267. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5268. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5269. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5270. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5271. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5272. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5273. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5274. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5275. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5276. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5277. {
  5278. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5279. {
  5280. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5281. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5282. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5283. }
  5284. }
  5285. }
  5286. else
  5287. DEBUG_INFO("TxDefaultProfile not found.\n");
  5288. DEBUG_INFO("------------------------------------\n");*/
  5289. }
  5290. // Search max profile
  5291. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  5292. if((access(profileFileName, F_OK))!=-1)
  5293. {
  5294. fp = fopen(profileFileName, "r");
  5295. while(getline(&line, &len, fp) != -1)
  5296. {
  5297. json_object *obj = NULL;
  5298. obj = json_tokener_parse(line);
  5299. if(is_error(obj))
  5300. {
  5301. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  5302. }
  5303. else
  5304. {
  5305. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  5306. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  5307. )
  5308. {
  5309. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  5310. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5311. )
  5312. {
  5313. struct tm tmFrom, tmTo;
  5314. struct timeb tbFrom, tbTo;
  5315. 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) &&
  5316. (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))
  5317. {
  5318. tmFrom.tm_year -= 1900;
  5319. tmFrom.tm_mon -= 1;
  5320. tbFrom.time = mktime(&tmFrom);
  5321. tmTo.tm_year -= 1900;
  5322. tmTo.tm_mon -= 1;
  5323. tbTo.time = mktime(&tmTo);
  5324. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  5325. {
  5326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5327. {
  5328. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5329. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5330. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5331. }
  5332. if(maxProfile.id == -1)
  5333. DEBUG_INFO("MaxProfile found.\n");
  5334. else
  5335. DEBUG_INFO("MaxProfile updated.\n");
  5336. // Required item
  5337. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5338. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5339. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5340. if(isUnitA)
  5341. {
  5342. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5343. 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++)
  5344. {
  5345. 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"));
  5346. 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"));
  5347. /*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)
  5348. {
  5349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5350. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5351. else
  5352. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5353. }
  5354. else
  5355. {
  5356. 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"));
  5357. }*/
  5358. 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")));
  5359. }
  5360. }
  5361. else
  5362. {
  5363. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5364. 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++)
  5365. {
  5366. 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"));
  5367. 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"));
  5368. /*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)
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5371. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5372. else
  5373. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5374. }
  5375. else
  5376. {
  5377. 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"));
  5378. }*/
  5379. 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));
  5380. }
  5381. }
  5382. // Optional item
  5383. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5384. {
  5385. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5386. }
  5387. else
  5388. {
  5389. sprintf((char*)maxProfile.validFrom, " ");
  5390. }
  5391. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5392. {
  5393. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5394. }
  5395. else
  5396. {
  5397. sprintf((char*)maxProfile.validTo, " ");
  5398. }
  5399. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5400. {
  5401. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5402. }
  5403. else
  5404. {
  5405. sprintf((char*)maxProfile.recurrencyKind, " ");
  5406. }
  5407. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5408. {
  5409. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5410. }
  5411. else
  5412. {
  5413. sprintf((char*)maxProfile.transactionId, " ");
  5414. }
  5415. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5416. {
  5417. 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"));
  5418. }
  5419. else
  5420. {
  5421. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5422. }
  5423. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5424. {
  5425. 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")));
  5426. }
  5427. else
  5428. {
  5429. 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));
  5430. }
  5431. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5432. {
  5433. 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"));
  5434. }
  5435. else
  5436. {
  5437. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5438. }
  5439. }
  5440. }
  5441. }
  5442. else
  5443. {
  5444. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5445. {
  5446. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5447. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5448. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5449. }
  5450. if(maxProfile.id == -1)
  5451. DEBUG_INFO("MaxProfile found.\n");
  5452. else
  5453. DEBUG_INFO("MaxProfile updated.\n");
  5454. // Required item
  5455. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5456. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5457. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5458. if(isUnitA)
  5459. {
  5460. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5461. 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++)
  5462. {
  5463. 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"));
  5464. 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"));
  5465. /*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)
  5466. {
  5467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5468. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5469. else
  5470. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5471. }
  5472. else
  5473. {
  5474. 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"));
  5475. }*/
  5476. 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")));
  5477. }
  5478. }
  5479. else
  5480. {
  5481. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5482. 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++)
  5483. {
  5484. 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"));
  5485. 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"));
  5486. /*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)
  5487. {
  5488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5489. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5490. else
  5491. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5492. }
  5493. else
  5494. {
  5495. 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"));
  5496. }*/
  5497. 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));
  5498. }
  5499. }
  5500. // Optional item
  5501. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5502. {
  5503. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5504. }
  5505. else
  5506. {
  5507. sprintf((char*)maxProfile.validFrom, " ");
  5508. }
  5509. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5510. {
  5511. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5512. }
  5513. else
  5514. {
  5515. sprintf((char*)maxProfile.validTo, " ");
  5516. }
  5517. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5518. {
  5519. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5520. }
  5521. else
  5522. {
  5523. sprintf((char*)maxProfile.recurrencyKind, " ");
  5524. }
  5525. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5526. {
  5527. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5528. }
  5529. else
  5530. {
  5531. sprintf((char*)maxProfile.transactionId, " ");
  5532. }
  5533. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5534. {
  5535. 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"));
  5536. }
  5537. else
  5538. {
  5539. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5540. }
  5541. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5542. {
  5543. 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")));
  5544. }
  5545. else
  5546. {
  5547. 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));
  5548. }
  5549. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5550. {
  5551. 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"));
  5552. }
  5553. else
  5554. {
  5555. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5556. }
  5557. }
  5558. }
  5559. }
  5560. json_object_put(obj);
  5561. }
  5562. fclose(fp);
  5563. /*
  5564. if(maxProfile.id !=-1)
  5565. {
  5566. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5567. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5568. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5569. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5570. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5571. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5572. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5573. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5574. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5575. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5576. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5577. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5578. {
  5579. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5580. {
  5581. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5582. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5583. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5584. }
  5585. }
  5586. }
  5587. else
  5588. DEBUG_INFO("MaxProfile not found.\n");
  5589. DEBUG_INFO("------------------------------------\n");*/
  5590. }
  5591. /*
  5592. * Align found profile start schedule & periods
  5593. */
  5594. //DEBUG_INFO("====================================\n");
  5595. /*
  5596. // For local test usage, force modify found profile start schedule info
  5597. 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);
  5598. 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);
  5599. 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);
  5600. */
  5601. if(txProfile.id != -1)
  5602. {
  5603. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5604. {
  5605. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5606. {
  5607. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5608. 0:
  5609. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5610. }
  5611. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5612. {
  5613. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5614. {
  5615. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5616. 0:
  5617. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5618. if(idxPeriod > 0)
  5619. {
  5620. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5621. {
  5622. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5623. }
  5624. }
  5625. }
  5626. }
  5627. }
  5628. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5629. {
  5630. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5631. {
  5632. 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?
  5633. 0:
  5634. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5635. }
  5636. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5637. {
  5638. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5639. {
  5640. 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?
  5641. 0:
  5642. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5643. if(idxPeriod > 0)
  5644. {
  5645. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5646. {
  5647. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5648. }
  5649. }
  5650. }
  5651. }
  5652. }
  5653. else
  5654. {
  5655. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5656. {
  5657. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5658. {
  5659. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5660. 0:
  5661. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5662. }
  5663. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5664. {
  5665. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5666. {
  5667. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5668. 0:
  5669. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5670. if(idxPeriod > 0)
  5671. {
  5672. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5673. {
  5674. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5675. }
  5676. }
  5677. }
  5678. }
  5679. }
  5680. else
  5681. {
  5682. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5683. {
  5684. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5685. 0:
  5686. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5687. }
  5688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5689. {
  5690. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5691. {
  5692. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5693. 0:
  5694. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5695. if(idxPeriod > 0)
  5696. {
  5697. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5698. {
  5699. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5700. }
  5701. }
  5702. }
  5703. }
  5704. }
  5705. }
  5706. /*
  5707. DEBUG_INFO("txProfile after align.\n");
  5708. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  5709. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  5710. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  5711. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  5712. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  5713. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  5714. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  5715. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5716. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  5717. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5718. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5719. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5720. {
  5721. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5722. {
  5723. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5724. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5725. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5726. }
  5727. }*/
  5728. }
  5729. if(defaultTxProfile.id != -1)
  5730. {
  5731. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5732. {
  5733. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5734. {
  5735. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5736. 0:
  5737. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5738. }
  5739. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5740. {
  5741. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5742. {
  5743. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5744. 0:
  5745. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5746. if(idxPeriod > 0)
  5747. {
  5748. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5749. {
  5750. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5751. }
  5752. }
  5753. }
  5754. }
  5755. }
  5756. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5757. {
  5758. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5759. {
  5760. 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?
  5761. 0:
  5762. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5763. }
  5764. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5765. {
  5766. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5767. {
  5768. 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?
  5769. 0:
  5770. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5771. if(idxPeriod > 0)
  5772. {
  5773. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5774. {
  5775. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5776. }
  5777. }
  5778. }
  5779. }
  5780. }
  5781. else
  5782. {
  5783. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5784. {
  5785. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5786. {
  5787. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5788. 0:
  5789. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5790. }
  5791. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5792. {
  5793. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5794. {
  5795. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5796. 0:
  5797. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5798. if(idxPeriod > 0)
  5799. {
  5800. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5801. {
  5802. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5803. }
  5804. }
  5805. }
  5806. }
  5807. }
  5808. else
  5809. {
  5810. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5811. {
  5812. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5813. 0:
  5814. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5815. }
  5816. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5817. {
  5818. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5819. {
  5820. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5821. 0:
  5822. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5823. if(idxPeriod > 0)
  5824. {
  5825. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5826. {
  5827. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5828. }
  5829. }
  5830. }
  5831. }
  5832. }
  5833. }
  5834. /*
  5835. DEBUG_INFO("defaultTxProfile after align.\n");
  5836. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5837. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5838. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5839. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5840. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5841. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5842. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5843. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5844. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5845. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5846. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5848. {
  5849. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5850. {
  5851. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5852. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5853. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5854. }
  5855. }
  5856. DEBUG_INFO("------------------------------------\n");*/
  5857. }
  5858. if(maxProfile.id != -1)
  5859. {
  5860. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5861. {
  5862. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5863. {
  5864. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5865. 0:
  5866. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5867. }
  5868. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5869. {
  5870. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5871. {
  5872. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5873. 0:
  5874. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5875. if(idxPeriod > 0)
  5876. {
  5877. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5878. {
  5879. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5880. }
  5881. }
  5882. }
  5883. }
  5884. }
  5885. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5886. {
  5887. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5888. {
  5889. 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?
  5890. 0:
  5891. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5892. }
  5893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5894. {
  5895. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5896. {
  5897. 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?
  5898. 0:
  5899. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5900. if(idxPeriod > 0)
  5901. {
  5902. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5903. {
  5904. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5905. }
  5906. }
  5907. }
  5908. }
  5909. }
  5910. else
  5911. {
  5912. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5913. {
  5914. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5915. {
  5916. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5917. 0:
  5918. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5919. }
  5920. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5921. {
  5922. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5923. {
  5924. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5925. 0:
  5926. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5927. if(idxPeriod > 0)
  5928. {
  5929. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5930. {
  5931. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5932. }
  5933. }
  5934. }
  5935. }
  5936. }
  5937. else
  5938. {
  5939. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5940. {
  5941. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5942. 0:
  5943. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5944. }
  5945. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5946. {
  5947. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5948. {
  5949. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5950. 0:
  5951. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5952. if(idxPeriod > 0)
  5953. {
  5954. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5955. {
  5956. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5957. }
  5958. }
  5959. }
  5960. }
  5961. }
  5962. }
  5963. /*
  5964. DEBUG_INFO("MaxProfile after align.\n");
  5965. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5966. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5967. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5968. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5969. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5970. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5971. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5972. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5973. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5974. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5975. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5976. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5977. {
  5978. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5979. {
  5980. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5981. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5982. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5983. }
  5984. }
  5985. DEBUG_INFO("------------------------------------\n");*/
  5986. }
  5987. /*
  5988. * Merge to conposite schedule
  5989. */
  5990. //DEBUG_INFO("====================================\n");
  5991. // Find each profile period quantity
  5992. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5993. {
  5994. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5995. limitMax = idx+1;
  5996. }
  5997. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5998. {
  5999. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  6000. limitDef = idx+1;
  6001. }
  6002. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  6003. {
  6004. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  6005. limitTx = idx+1;
  6006. }
  6007. // TxProfile found, composite schedule based on it
  6008. if(txProfile.id != -1)
  6009. {
  6010. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  6011. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  6012. {
  6013. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  6014. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  6015. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  6016. {
  6017. if(maxProfile.id != -1)
  6018. {
  6019. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6020. {
  6021. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  6022. {
  6023. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6024. {
  6025. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  6026. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  6027. 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);
  6028. }
  6029. else
  6030. {
  6031. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  6032. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  6033. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  6034. }
  6035. }
  6036. if(idxMaxPeriod == (limitMax-1))
  6037. {
  6038. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6039. {
  6040. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6041. {
  6042. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6043. compositePeriodIdx++;
  6044. }
  6045. else
  6046. {
  6047. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6048. }
  6049. }
  6050. }
  6051. }
  6052. }
  6053. else
  6054. {
  6055. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6056. {
  6057. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  6058. compositePeriodIdx++;
  6059. }
  6060. else
  6061. {
  6062. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  6063. }
  6064. }
  6065. }
  6066. if(idxTxPeriod == (limitTx-1))
  6067. {
  6068. if(defaultTxProfile.id != -1)
  6069. {
  6070. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  6071. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  6072. {
  6073. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  6074. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  6075. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  6076. {
  6077. if(maxProfile.id != -1)
  6078. {
  6079. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6080. {
  6081. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  6082. {
  6083. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6084. {
  6085. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6086. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6087. 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);
  6088. }
  6089. else
  6090. {
  6091. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6092. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6093. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  6094. }
  6095. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6096. {
  6097. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6098. {
  6099. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6100. compositePeriodIdx++;
  6101. }
  6102. else
  6103. {
  6104. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6105. }
  6106. }
  6107. // Delete duplicate period
  6108. if(compositePeriodIdx > 1)
  6109. {
  6110. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6111. {
  6112. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6113. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6114. compositePeriodIdx -= 1;
  6115. }
  6116. }
  6117. }
  6118. else
  6119. {
  6120. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6121. {
  6122. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6123. compositePeriodIdx++;
  6124. }
  6125. else
  6126. {
  6127. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6128. }
  6129. break;
  6130. }
  6131. }
  6132. }
  6133. else
  6134. {
  6135. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6136. {
  6137. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6138. compositePeriodIdx++;
  6139. }
  6140. else
  6141. {
  6142. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6143. }
  6144. }
  6145. }
  6146. }
  6147. }
  6148. }
  6149. }
  6150. }
  6151. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  6152. else if(defaultTxProfile.id != -1)
  6153. {
  6154. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  6155. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  6156. {
  6157. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  6158. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  6159. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  6160. {
  6161. if(maxProfile.id != -1)
  6162. {
  6163. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6164. {
  6165. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  6166. {
  6167. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6168. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6169. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6170. {
  6171. 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);
  6172. }
  6173. else
  6174. {
  6175. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  6176. }
  6177. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6178. {
  6179. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6180. {
  6181. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6182. compositePeriodIdx++;
  6183. }
  6184. else
  6185. {
  6186. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6187. }
  6188. }
  6189. // Delete duplicate period
  6190. if(compositePeriodIdx > 1)
  6191. {
  6192. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6193. {
  6194. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6195. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6196. compositePeriodIdx -= 1;
  6197. }
  6198. }
  6199. }
  6200. else
  6201. {
  6202. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6203. {
  6204. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6205. compositePeriodIdx++;
  6206. }
  6207. else
  6208. {
  6209. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6210. }
  6211. break;
  6212. }
  6213. }
  6214. }
  6215. else
  6216. {
  6217. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6218. {
  6219. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6220. compositePeriodIdx++;
  6221. }
  6222. else
  6223. {
  6224. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6225. }
  6226. }
  6227. }
  6228. }
  6229. }
  6230. // Fill other period by MaxProfile
  6231. if(maxProfile.id != -1)
  6232. {
  6233. if(compositePeriodIdx==0)
  6234. {
  6235. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  6236. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  6237. {
  6238. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6239. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6240. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6241. {
  6242. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6243. {
  6244. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6245. compositePeriodIdx++;
  6246. }
  6247. else
  6248. {
  6249. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6250. }
  6251. }
  6252. }
  6253. }
  6254. else
  6255. {
  6256. int lastCompositePeriodIdx = compositePeriodIdx;
  6257. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6258. {
  6259. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6260. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6261. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6262. {
  6263. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  6264. {
  6265. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  6266. {
  6267. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6268. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6269. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  6270. }
  6271. else
  6272. {
  6273. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6274. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6275. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  6276. }
  6277. }
  6278. if(tmpPeriod.limit != -1)
  6279. {
  6280. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  6281. {
  6282. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  6283. {
  6284. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6285. compositePeriodIdx++;
  6286. }
  6287. else
  6288. {
  6289. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6290. }
  6291. }
  6292. // Delete duplicate period
  6293. if(compositePeriodIdx > 1)
  6294. {
  6295. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6296. {
  6297. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6298. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6299. compositePeriodIdx -= 1;
  6300. }
  6301. }
  6302. }
  6303. }
  6304. }
  6305. }
  6306. }
  6307. if(compositeProfile.chargingSchedule[idxSchedule].duration < durationReq)
  6308. {
  6309. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6310. {
  6311. if((idxPeriod >= 0) && (compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1))
  6312. {
  6313. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = compositeProfile.chargingSchedule[idxSchedule].duration;
  6314. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  6315. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].numberPhases;
  6316. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  6317. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6318. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6319. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6320. DEBUG_INFO("------------------------------------------------\n");
  6321. break;
  6322. }
  6323. }
  6324. }
  6325. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  6326. DEBUG_INFO("Connector-%d composite schedule ready.\n", evseId);
  6327. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  6328. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  6329. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  6330. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6331. {
  6332. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  6333. {
  6334. compositeProfile.id = 1;
  6335. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6336. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6337. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6338. }
  6339. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  6340. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  6341. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  6342. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  6343. }
  6344. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  6345. if(line)
  6346. free(line);
  6347. ShmOCPP20Data->CSUMsg.bits[(evseId==0?0:evseId-1)].ChargingProfileConf = ON;
  6348. }
  6349. //==========================================
  6350. // Init all share memory
  6351. //==========================================
  6352. int InitShareMemory()
  6353. {
  6354. int result = PASS;
  6355. int MeterSMId;
  6356. //creat ShmSysConfigAndInfo
  6357. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  6358. {
  6359. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  6360. result = FAIL;
  6361. }
  6362. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6363. {
  6364. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  6365. result = FAIL;
  6366. }
  6367. else
  6368. {}
  6369. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  6370. {
  6371. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  6372. result = FAIL;
  6373. }
  6374. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6375. {
  6376. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  6377. result = FAIL;
  6378. }
  6379. else
  6380. {}
  6381. //creat ShmPsuData
  6382. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  6383. {
  6384. DEBUG_ERROR("shmget ShmPsuData NG\n");
  6385. result = FAIL;
  6386. }
  6387. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6388. {
  6389. DEBUG_ERROR("shmat ShmPsuData NG\n");
  6390. result = FAIL;
  6391. }
  6392. else
  6393. {}
  6394. //creat ShmOCPP20Data
  6395. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  6396. {
  6397. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  6398. result = FAIL;
  6399. }
  6400. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6401. {
  6402. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  6403. result = FAIL;
  6404. }
  6405. else
  6406. {}
  6407. /****************************** For Initial Settings************************************************/
  6408. /*
  6409. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  6410. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  6411. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  6412. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  6413. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  6414. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  6415. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  6416. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  6417. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  6418. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  6419. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  6420. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  6421. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  6422. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  6423. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  6424. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  6425. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  6426. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  6427. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  6428. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  6429. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  6430. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  6431. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  6432. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  6433. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  6434. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  6435. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  6436. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  6437. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  6438. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  6439. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  6440. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  6441. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  6442. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  6443. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  6444. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  6445. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  6446. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  6447. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  6448. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  6449. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  6450. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  6451. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  6452. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  6453. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  6454. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  6455. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  6456. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  6457. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  6458. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  6459. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  6460. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  6461. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  6462. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  6463. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  6464. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  6465. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  6466. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  6467. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  6468. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  6469. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  6470. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  6471. */
  6472. return result;
  6473. }
  6474. int ProcessShareMemory()
  6475. {
  6476. int result = PASS;
  6477. if(InitShareMemory() == FAIL)
  6478. {
  6479. DEBUG_ERROR("InitShareMemory NG\n");
  6480. if(ShmStatusCodeData!=NULL)
  6481. {
  6482. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  6483. }
  6484. result = FAIL;
  6485. }
  6486. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  6487. {
  6488. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  6489. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6490. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  6491. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  6492. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  6493. ) // 'D' means DC
  6494. {
  6495. // DO series
  6496. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  6497. {
  6498. gunTotalNumber += 1;
  6499. gunType[gun_index] = GUN_TYPE_DO;
  6500. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  6503. {
  6504. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6505. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6506. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  6507. }
  6508. }
  6509. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6510. {
  6511. case Gun_Type_Chademo:
  6512. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  6513. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  6514. {
  6515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6516. {
  6517. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6518. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6519. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  6520. }
  6521. }
  6522. break;
  6523. case Gun_Type_CCS_2:
  6524. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  6525. for (int index = 0; index < CCS_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6528. {
  6529. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6530. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6531. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  6532. }
  6533. }
  6534. break;
  6535. case Gun_Type_GB:
  6536. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  6537. for (int index = 0; index < GB_QUANTITY; index++)
  6538. {
  6539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6540. {
  6541. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6542. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6543. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  6544. }
  6545. }
  6546. break;
  6547. case Gun_Type_AC:
  6548. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  6549. for (int index = 0; index < AC_QUANTITY; index++)
  6550. {
  6551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6552. {
  6553. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6554. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6555. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  6556. }
  6557. }
  6558. break;
  6559. default:
  6560. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  6561. break;
  6562. }
  6563. }
  6564. }
  6565. else
  6566. {
  6567. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  6568. {
  6569. gunTotalNumber += 1;
  6570. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6571. {
  6572. case Gun_Type_Chademo:
  6573. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  6574. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  6575. break;
  6576. case Gun_Type_CCS_2:
  6577. gunType[gun_index] = GUN_TYPE_CCS;
  6578. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  6579. break;
  6580. case Gun_Type_GB:
  6581. gunType[gun_index] = GUN_TYPE_GBT;
  6582. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  6583. break;
  6584. case Gun_Type_AC:
  6585. gunType[gun_index] = GUN_TYPE_AC;
  6586. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  6587. break;
  6588. default:
  6589. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  6590. break;
  6591. }
  6592. }
  6593. }
  6594. }
  6595. else
  6596. {
  6597. DEBUG_ERROR("Model name parsing fail.\n");
  6598. result = FAIL;
  6599. }
  6600. if(result != PASS)sleep(5);
  6601. return result;
  6602. }
  6603. //---------------------common routine---------------------------//
  6604. void checkNetworkProfile(void)
  6605. {
  6606. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  6607. json_object *priority;
  6608. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  6609. if(!is_error(priority))
  6610. {
  6611. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  6612. {
  6613. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  6614. {
  6615. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  6616. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  6617. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  6618. {
  6619. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  6620. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  6621. break;
  6622. }
  6623. }
  6624. }
  6625. }
  6626. json_object_put(priority);
  6627. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  6628. }
  6629. void checkRemoteStart(uint8_t evseIdx)
  6630. {
  6631. uint8_t tempIndex;
  6632. int isAllowStart = TRUE;
  6633. char cmdBuf[512];
  6634. //check Transaction active
  6635. if(gunType[evseIdx-1] == GUN_TYPE_CHAdeMO)
  6636. {
  6637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6638. {
  6639. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6640. }
  6641. else
  6642. {
  6643. tempIndex = (evseIdx-1);
  6644. }
  6645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6646. {
  6647. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6648. {
  6649. 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))
  6650. {
  6651. //Reserved
  6652. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  6653. }
  6654. 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))
  6655. {
  6656. //Reserved
  6657. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  6658. isAllowStart = FALSE;
  6659. }
  6660. else
  6661. {
  6662. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6663. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6664. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6665. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6666. {
  6667. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  6668. isAllowStart = FALSE;
  6669. }
  6670. }//END FOR ELSE
  6671. }
  6672. }// END FOR CHAdeMO_QUANTITY
  6673. }
  6674. else if(gunType[evseIdx-1] == GUN_TYPE_CCS)
  6675. {
  6676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6677. {
  6678. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6679. }
  6680. else
  6681. {
  6682. tempIndex = (evseIdx-1);
  6683. }
  6684. for (int index = 0; index < CCS_QUANTITY; index++)
  6685. {
  6686. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6687. {
  6688. 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))
  6689. {
  6690. //Reserved
  6691. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  6692. }
  6693. 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))
  6694. {
  6695. //Reserved
  6696. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  6697. isAllowStart = FALSE;
  6698. }
  6699. else
  6700. {
  6701. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6702. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6703. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6704. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6705. {
  6706. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  6707. isAllowStart = FALSE;
  6708. }
  6709. }// END FOR ELSE
  6710. }
  6711. }// END FOR CCS_QUANTITY
  6712. }
  6713. else if(gunType[evseIdx-1] == GUN_TYPE_GBT)
  6714. {
  6715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6716. {
  6717. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6718. }
  6719. else
  6720. {
  6721. tempIndex = (evseIdx-1);
  6722. }
  6723. for (int index = 0; index < GB_QUANTITY; index++)
  6724. {
  6725. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6726. {
  6727. 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))
  6728. {
  6729. //Reserved
  6730. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  6731. }
  6732. 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))
  6733. {
  6734. //Reserved
  6735. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  6736. isAllowStart = FALSE;
  6737. }
  6738. else
  6739. {
  6740. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6741. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6742. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6743. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6744. {
  6745. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  6746. isAllowStart = FALSE;
  6747. }
  6748. }// END FOR ELSE
  6749. }
  6750. } // END FOR GB_QUANTITY
  6751. }
  6752. else if(gunType[evseIdx-1] == GUN_TYPE_DO)
  6753. {
  6754. tempIndex = (evseIdx-1);
  6755. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6756. {
  6757. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  6758. {
  6759. 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))
  6760. {
  6761. //Reserved
  6762. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  6763. }
  6764. 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))
  6765. {
  6766. //Reserved
  6767. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  6768. isAllowStart = FALSE;
  6769. }
  6770. else
  6771. {
  6772. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6773. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6774. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6775. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6776. {
  6777. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  6778. isAllowStart = FALSE;
  6779. }
  6780. }// END FOR ELSE
  6781. }
  6782. } // END FOR GB_QUANTITY
  6783. }
  6784. else
  6785. {
  6786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6787. {
  6788. tempIndex = 2;
  6789. }
  6790. else
  6791. {
  6792. tempIndex = (evseIdx-1);
  6793. }
  6794. for (int index = 0; index < AC_QUANTITY; index++)
  6795. {
  6796. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6797. {
  6798. 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))
  6799. {
  6800. //Reserved
  6801. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  6802. }
  6803. 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))
  6804. {
  6805. //Reserved
  6806. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  6807. isAllowStart = FALSE;
  6808. }
  6809. else
  6810. {
  6811. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6812. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6813. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6814. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6815. {
  6816. DEBUG_WARN("AC connector not allow start cause busy.\n");
  6817. isAllowStart = FALSE;
  6818. }
  6819. }//END FOR ELSE
  6820. }
  6821. }// END FOR AC_QUANTITY
  6822. }
  6823. if(isAllowStart == TRUE)
  6824. {
  6825. if(ShmOCPP20Data->RequestStartTransaction[evseIdx -1].chargingProfile.id > 0)
  6826. {
  6827. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  6828. {
  6829. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdx);
  6830. system(cmdBuf);
  6831. }
  6832. }
  6833. ShmOCPP20Data->CsMsg.bits[evseIdx-1].RequestStartTransactionReq = ON;
  6834. }
  6835. }
  6836. void CheckSystemValue(void)
  6837. {
  6838. char filenmae[100]={0};
  6839. char str[100]={0};
  6840. int tempIndex = 0;
  6841. //===============================
  6842. // EVSE operation check
  6843. //===============================
  6844. //===============================
  6845. // Heartbeat check
  6846. //===============================
  6847. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  6848. {
  6849. //parameter for test
  6850. if(HeartBeatWithNOResponse < 1)
  6851. sendHeartbeatRequest(0);
  6852. //==============================================
  6853. // Reset Waiting Time
  6854. //==============================================
  6855. HeartBeatWithNOResponse += 1;
  6856. }
  6857. //===============================
  6858. // CSU Trigger Authorize Request
  6859. //===============================
  6860. if(isWebsocketSendable &&
  6861. (server_sign == TRUE) &&
  6862. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6863. (authorizeRetryTimes < 3))
  6864. {
  6865. sendAuthorizeRequest(0);
  6866. authorizeRetryTimes = authorizeRetryTimes + 1;
  6867. if(authorizeRetryTimes < 3)
  6868. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6869. }
  6870. else if((server_sign == TRUE) &&
  6871. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6872. (authorizeRetryTimes >= 3))
  6873. {
  6874. authorizeRetryTimes = 0;
  6875. SetOcppConnStatus(FALSE);
  6876. server_sign = FALSE;
  6877. }
  6878. else if((server_sign == FALSE) &&
  6879. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true") == 0) &&
  6880. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  6881. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6882. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6883. {
  6884. sendAuthorizeRequest(0);
  6885. }
  6886. //===============================
  6887. // NotifyMonitoringReportRequest
  6888. //===============================
  6889. if(isWebsocketSendable &&
  6890. (server_sign == TRUE) &&
  6891. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6892. {
  6893. ShmOCPP20Data->NotifyMonitoringReport.requestId = ShmOCPP20Data->GetMonitoringReport.requestId;
  6894. ShmOCPP20Data->NotifyMonitoringReport.tbc = 0;
  6895. ShmOCPP20Data->NotifyMonitoringReport.seqNo = 0;
  6896. getNowDatetime(ShmOCPP20Data->NotifyMonitoringReport.generatedAt);
  6897. sendNotifyMonitoringReportRequest();
  6898. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6899. }
  6900. if(isWebsocketSendable &&
  6901. (server_sign == TRUE) &&
  6902. (ShmOCPP20Data->GetReport.requestId > 0))
  6903. {
  6904. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6905. {
  6906. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6907. {
  6908. /*
  6909. * TODO:
  6910. * 1. Report component that are active
  6911. */
  6912. }
  6913. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6914. {
  6915. /*
  6916. * TODO:
  6917. * 1. Report component that are available
  6918. */
  6919. }
  6920. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6921. {
  6922. /*
  6923. * TODO:
  6924. * 1. Report component that are enable
  6925. */
  6926. }
  6927. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6928. {
  6929. /*
  6930. * TODO:
  6931. * 1. Report component that are problem
  6932. */
  6933. }
  6934. else
  6935. {
  6936. /*
  6937. * TODO:
  6938. * 1. Process unknown criteria condition
  6939. */
  6940. }
  6941. }
  6942. ShmOCPP20Data->GetReport.requestId = 0;
  6943. }
  6944. if(isWebsocketSendable &&
  6945. (server_sign == TRUE) &&
  6946. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6947. {
  6948. uint8_t reportIdx = 0;
  6949. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  6950. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  6951. {
  6952. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6953. {
  6954. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6955. {
  6956. 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))
  6957. {
  6958. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6959. reportIdx++;
  6960. }
  6961. }
  6962. else
  6963. {
  6964. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6965. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6966. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6967. else
  6968. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6969. sendNotifyReportRequest();
  6970. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6971. reportIdx = 0;
  6972. idx_var--;
  6973. }
  6974. }
  6975. }
  6976. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  6977. {
  6978. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6979. {
  6980. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6981. {
  6982. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6983. reportIdx++;
  6984. }
  6985. else
  6986. {
  6987. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6988. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6989. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6990. else
  6991. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6992. sendNotifyReportRequest();
  6993. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6994. reportIdx = 0;
  6995. idx_var--;
  6996. }
  6997. }
  6998. }
  6999. else
  7000. {
  7001. /*
  7002. * TODO:
  7003. * 1. Fill out summary inventory to response message, currently not support
  7004. */
  7005. }
  7006. if(reportIdx > 0)
  7007. {
  7008. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  7009. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  7010. ShmOCPP20Data->NotifyReport.seqNo += 1;
  7011. else
  7012. ShmOCPP20Data->NotifyReport.seqNo = 0;
  7013. sendNotifyReportRequest();
  7014. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  7015. reportIdx = 0;
  7016. }
  7017. ShmOCPP20Data->GetBaseReport.requestId = 0;
  7018. }
  7019. if(isWebsocketSendable &&
  7020. (server_sign == TRUE) &&
  7021. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  7022. {
  7023. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  7024. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  7025. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  7026. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  7027. else
  7028. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  7029. sendNotifyEventRequest();
  7030. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  7031. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  7032. }
  7033. if(isWebsocketSendable &&
  7034. (server_sign == TRUE) &&
  7035. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  7036. {
  7037. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  7038. {
  7039. /*
  7040. * TODO:
  7041. * 1.
  7042. */
  7043. }
  7044. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  7045. {
  7046. /*
  7047. * TODO:
  7048. * 1.
  7049. */
  7050. }
  7051. else
  7052. {
  7053. /*
  7054. * TODO:
  7055. * 1.
  7056. */
  7057. }
  7058. sendGet15118EVCertificateRequest();
  7059. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  7060. }
  7061. if(isWebsocketSendable &&
  7062. (server_sign == TRUE) &&
  7063. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  7064. {
  7065. sendSecurityEventNotificationRequest();
  7066. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  7067. }
  7068. if(isWebsocketSendable &&
  7069. (server_sign == TRUE) &&
  7070. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  7071. {
  7072. sendNotifyCustomerInformationRequest();
  7073. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  7074. }
  7075. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7076. {
  7077. // ClockAlign MeterValue
  7078. 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))
  7079. {
  7080. //check Transaction active
  7081. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7082. {
  7083. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7084. {
  7085. tempIndex = ((gun_index==2) ? 1: 0);
  7086. }
  7087. else
  7088. {
  7089. tempIndex = gun_index;
  7090. }
  7091. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7092. {
  7093. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7094. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7095. {
  7096. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7097. }
  7098. }// End for CHAdeMO
  7099. }
  7100. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7101. {
  7102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7103. {
  7104. tempIndex = ((gun_index==2) ? 1: 0);
  7105. }
  7106. else
  7107. {
  7108. tempIndex = gun_index;
  7109. }
  7110. for (int index = 0; index < CCS_QUANTITY; index++)
  7111. {
  7112. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7113. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7114. {
  7115. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7116. }
  7117. } // End for CCS
  7118. }
  7119. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7120. {
  7121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7122. {
  7123. tempIndex = ((gun_index==2) ? 1: 0);
  7124. }
  7125. else
  7126. {
  7127. tempIndex = gun_index;
  7128. }
  7129. for (int index = 0; index < GB_QUANTITY; index++)
  7130. {
  7131. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7132. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7133. {
  7134. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7135. }
  7136. }// End for GB
  7137. }
  7138. else if(gunType[gun_index] == GUN_TYPE_DO)
  7139. {
  7140. tempIndex = gun_index;
  7141. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7142. {
  7143. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7144. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7145. {
  7146. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7147. }
  7148. }
  7149. }
  7150. else
  7151. {
  7152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7153. {
  7154. tempIndex = 2;
  7155. }
  7156. else
  7157. {
  7158. tempIndex = gun_index;
  7159. }
  7160. for (int index = 0; index < AC_QUANTITY; index++)
  7161. {
  7162. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7163. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7164. {
  7165. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7166. }
  7167. }//End for AC
  7168. }
  7169. }
  7170. }
  7171. //===============================
  7172. // Each connector operation check
  7173. //===============================
  7174. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  7175. {
  7176. //==========================================
  7177. // Check remote start without connector id
  7178. //==========================================
  7179. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  7180. {
  7181. int evseIdInt = -1;
  7182. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  7183. {
  7184. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  7185. {
  7186. evseIdInt = (gun_index+1);
  7187. DEBUG_INFO("Detect connector of evse-%02d connected ready to start.\n", evseIdInt);
  7188. checkRemoteStart(evseIdInt);
  7189. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7190. break;
  7191. }
  7192. }
  7193. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  7194. {
  7195. DEBUG_WARN("Remote start request without evse id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  7196. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7197. }
  7198. }
  7199. //==========================================
  7200. // csu trigger DataTransferReq
  7201. //==========================================
  7202. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  7203. {
  7204. sendDataTransferRequest(gun_index);
  7205. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  7206. }
  7207. //==============================================
  7208. // Charger status notification & Transaction event report
  7209. //==============================================
  7210. //--- Check Mode Change ---//
  7211. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7212. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7213. {
  7214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7215. {
  7216. tempIndex = ((gun_index==2) ? 1: 0);
  7217. }
  7218. else
  7219. {
  7220. tempIndex = gun_index;
  7221. }
  7222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7223. {
  7224. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7225. {
  7226. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  7227. {
  7228. //if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7229. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7230. /*if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7231. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7232. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7233. {
  7234. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7235. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7236. else
  7237. {
  7238. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7239. {
  7240. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7241. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7242. }
  7243. }
  7244. }*/
  7245. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  7246. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  7247. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7248. {
  7249. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7250. if((access(filenmae,F_OK))!=-1)
  7251. {
  7252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7253. sprintf(str,"rm -f %s",filenmae);
  7254. system(str);
  7255. }
  7256. }
  7257. }
  7258. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7259. #if 1 // for TempStopTransaction
  7260. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7261. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7262. {
  7263. checkTempStopTransaction(gun_index);
  7264. }
  7265. #endif
  7266. }
  7267. }
  7268. }
  7269. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7270. {
  7271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7272. {
  7273. tempIndex = ((gun_index==2) ? 1: 0);
  7274. }
  7275. else
  7276. {
  7277. tempIndex = gun_index;
  7278. }
  7279. for (int index = 0; index < CCS_QUANTITY; index++)
  7280. {
  7281. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7282. {
  7283. 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]*/ )
  7284. {
  7285. //if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7286. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7287. /*if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7288. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7289. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7290. {
  7291. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7292. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7293. else
  7294. {
  7295. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7296. {
  7297. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7298. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7299. }
  7300. }
  7301. }*/
  7302. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  7303. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  7304. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7305. {
  7306. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7307. if((access(filenmae,F_OK))!=-1)
  7308. {
  7309. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7310. sprintf(str,"rm -f %s",filenmae);
  7311. system(str);
  7312. }
  7313. }
  7314. }
  7315. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7316. #if 1 // for TempStopTransaction
  7317. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7318. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7319. {
  7320. checkTempStopTransaction(gun_index);
  7321. }
  7322. #endif
  7323. }
  7324. }
  7325. }
  7326. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7327. {
  7328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7329. {
  7330. tempIndex = ((gun_index==2) ? 1: 0);
  7331. }
  7332. else
  7333. {
  7334. tempIndex = gun_index;
  7335. }
  7336. for (int index = 0; index < GB_QUANTITY; index++)
  7337. {
  7338. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7339. {
  7340. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  7341. {
  7342. //if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7343. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7344. /*if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7345. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7346. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]))
  7347. {
  7348. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7349. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7350. else
  7351. {
  7352. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7353. {
  7354. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7355. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7356. }
  7357. }
  7358. }*/
  7359. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  7360. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  7361. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7362. {
  7363. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7364. if((access(filenmae,F_OK))!=-1)
  7365. {
  7366. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7367. sprintf(str,"rm -f %s",filenmae);
  7368. system(str);
  7369. }
  7370. }
  7371. }
  7372. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7373. #if 1 // for TempStopTransaction
  7374. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7375. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7376. {
  7377. checkTempStopTransaction(gun_index);
  7378. }
  7379. #endif
  7380. }
  7381. }
  7382. }
  7383. else if(gunType[gun_index] == GUN_TYPE_DO)
  7384. {
  7385. tempIndex = gun_index;
  7386. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7387. {
  7388. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7389. {
  7390. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  7391. {
  7392. //if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_AUTHORIZING)
  7393. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7394. /*if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  7395. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE) &&
  7396. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]))
  7397. {
  7398. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  7399. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7400. else
  7401. {
  7402. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7403. {
  7404. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7405. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7406. }
  7407. }
  7408. }*/
  7409. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  7410. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  7411. 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
  7412. {
  7413. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7414. if((access(filenmae,F_OK))!=-1)
  7415. {
  7416. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7417. sprintf(str,"rm -f %s",filenmae);
  7418. system(str);
  7419. }
  7420. }
  7421. }
  7422. 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);
  7423. #if 1 // for TempStopTransaction
  7424. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  7425. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7426. {
  7427. checkTempStopTransaction(gun_index);
  7428. }
  7429. #endif
  7430. }
  7431. }
  7432. }
  7433. else
  7434. {
  7435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7436. {
  7437. tempIndex = 2;
  7438. }
  7439. else
  7440. {
  7441. tempIndex = gun_index;
  7442. }
  7443. for (int index = 0; index < AC_QUANTITY; index++)
  7444. {
  7445. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7446. {
  7447. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  7448. {
  7449. //if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7450. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7451. /*if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7452. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7453. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) && (AcPreviousSystemStatus[index] != 99))
  7454. {
  7455. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7456. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7457. else
  7458. {
  7459. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7460. {
  7461. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7462. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7463. }
  7464. }
  7465. }*/
  7466. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  7467. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  7468. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7469. {
  7470. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7471. if((access(filenmae,F_OK))!=-1)
  7472. {
  7473. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7474. sprintf(str,"rm -f %s",filenmae);
  7475. system(str);
  7476. }
  7477. }
  7478. }
  7479. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7480. #if 1 // for TempStopTransaction
  7481. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7482. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7483. {
  7484. checkTempStopTransaction(gun_index);
  7485. }
  7486. #endif
  7487. }
  7488. }// END
  7489. }
  7490. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  7491. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  7492. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") == 0) &&
  7493. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  7494. {
  7495. sendStatusNotificationRequest(gun_index);
  7496. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  7497. }
  7498. //==============================================
  7499. // CSU Trigger or timer timeout refresh Smart Charging Profile
  7500. //==============================================
  7501. if((ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON) ||
  7502. ((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))))
  7503. {
  7504. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  7505. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  7506. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  7507. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  7508. }
  7509. //==============================================
  7510. // CSU transaction event
  7511. //==============================================
  7512. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON || cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  7513. {
  7514. sendTransactionEventRequest(gun_index);
  7515. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  7516. cpinitateMsg.bits[gun_index].TriggerTransactionEventReq = OFF;
  7517. //storeTempStopTransaction(gun_index);
  7518. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  7519. }
  7520. //==============================================
  7521. // Meter report
  7522. //==============================================
  7523. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  7524. {
  7525. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger, FALSE);
  7526. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  7527. }
  7528. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  7529. {
  7530. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock, FALSE);
  7531. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  7532. }
  7533. // Sample period MeterValue
  7534. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0) &&
  7535. (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)))
  7536. {
  7537. //check Transaction active
  7538. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7539. {
  7540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7541. {
  7542. tempIndex = ((gun_index==2) ? 1: 0);
  7543. }
  7544. else
  7545. {
  7546. tempIndex = gun_index;
  7547. }
  7548. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7549. {
  7550. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7551. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7552. {
  7553. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7554. {
  7555. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7556. }
  7557. }
  7558. }// End for CHAdeMO
  7559. }
  7560. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7561. {
  7562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7563. {
  7564. tempIndex = ((gun_index==2) ? 1: 0);
  7565. }
  7566. else
  7567. {
  7568. tempIndex = gun_index;
  7569. }
  7570. for (int index = 0; index < CCS_QUANTITY; index++)
  7571. {
  7572. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7573. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7574. {
  7575. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7576. {
  7577. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7578. }
  7579. }
  7580. } // End for CCS
  7581. }
  7582. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7583. {
  7584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7585. {
  7586. tempIndex = ((gun_index==2) ? 1: 0);
  7587. }
  7588. else
  7589. {
  7590. tempIndex = gun_index;
  7591. }
  7592. for (int index = 0; index < GB_QUANTITY; index++)
  7593. {
  7594. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7595. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7596. {
  7597. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7598. {
  7599. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7600. }
  7601. }
  7602. }// End for GB
  7603. }
  7604. else if(gunType[gun_index] == GUN_TYPE_DO)
  7605. {
  7606. tempIndex = gun_index;
  7607. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7608. {
  7609. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7610. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7611. {
  7612. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7613. {
  7614. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7615. }
  7616. }
  7617. }
  7618. }
  7619. else
  7620. {
  7621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7622. {
  7623. tempIndex = 2;
  7624. }
  7625. else
  7626. {
  7627. tempIndex = gun_index;
  7628. }
  7629. for (int index = 0; index < AC_QUANTITY; index++)
  7630. {
  7631. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7632. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7633. {
  7634. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7635. {
  7636. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7637. }
  7638. }
  7639. }//End for AC
  7640. }
  7641. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7642. {
  7643. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7644. {
  7645. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, FALSE);
  7646. }
  7647. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7648. }
  7649. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  7650. }
  7651. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value) > 0) &&
  7652. (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)))
  7653. {
  7654. //check Transaction active
  7655. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7656. {
  7657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7658. {
  7659. tempIndex = ((gun_index==2) ? 1: 0);
  7660. }
  7661. else
  7662. {
  7663. tempIndex = gun_index;
  7664. }
  7665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7666. {
  7667. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7668. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7669. {
  7670. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7671. {
  7672. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7673. }
  7674. }
  7675. }// End for CHAdeMO
  7676. }
  7677. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7678. {
  7679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7680. {
  7681. tempIndex = ((gun_index==2) ? 1: 0);
  7682. }
  7683. else
  7684. {
  7685. tempIndex = gun_index;
  7686. }
  7687. for (int index = 0; index < CCS_QUANTITY; index++)
  7688. {
  7689. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7690. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7691. {
  7692. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7693. {
  7694. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7695. }
  7696. }
  7697. } // End for CCS
  7698. }
  7699. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7700. {
  7701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7702. {
  7703. tempIndex = ((gun_index==2) ? 1: 0);
  7704. }
  7705. else
  7706. {
  7707. tempIndex = gun_index;
  7708. }
  7709. for (int index = 0; index < GB_QUANTITY; index++)
  7710. {
  7711. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7712. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7713. {
  7714. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7715. {
  7716. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7717. }
  7718. }
  7719. }// End for GB
  7720. }
  7721. else if(gunType[gun_index] == GUN_TYPE_DO)
  7722. {
  7723. tempIndex = gun_index;
  7724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7725. {
  7726. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7727. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7728. {
  7729. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7730. {
  7731. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7732. }
  7733. }
  7734. }
  7735. }
  7736. else
  7737. {
  7738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7739. {
  7740. tempIndex = 2;
  7741. }
  7742. else
  7743. {
  7744. tempIndex = gun_index;
  7745. }
  7746. for (int index = 0; index < AC_QUANTITY; index++)
  7747. {
  7748. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7749. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7750. {
  7751. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7752. {
  7753. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7754. }
  7755. }
  7756. }//End for AC
  7757. }
  7758. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7759. {
  7760. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7761. {
  7762. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, TRUE);
  7763. }
  7764. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7765. }
  7766. refreshStartTimer(&clientTime.SampledDataTxEnded[gun_index]);
  7767. }
  7768. //==============================================
  7769. // Check Connector reserved
  7770. //==============================================
  7771. //===============================
  7772. // Check if Reserve is expired
  7773. //===============================
  7774. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  7775. {
  7776. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  7777. {
  7778. DEBUG_INFO("reserve expired.\n");
  7779. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  7780. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  7781. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  7782. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  7783. }
  7784. }//END OF Check if Reserve is expired
  7785. //==========================================
  7786. // csu trigger FirmwareStatusNotificationReq
  7787. //==========================================
  7788. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  7789. {
  7790. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  7791. }
  7792. //==========================================
  7793. // csu cleared charging limit request
  7794. //==========================================
  7795. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  7796. {
  7797. sendClearedChargingLimitRequest(gun_index);
  7798. }
  7799. //==========================================
  7800. // csu trigger CancelReservationConf
  7801. //==========================================
  7802. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  7803. {
  7804. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  7805. }
  7806. //==========================================
  7807. // csu notify EV charging need request
  7808. //==========================================
  7809. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  7810. {
  7811. sendNotifyEVChargingNeedsRequest(gun_index);
  7812. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  7813. }
  7814. //==========================================
  7815. // csu notify EV charging schedule request
  7816. //==========================================
  7817. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq == ON))
  7818. {
  7819. sendNotifyEVChargingScheduleRequest(gun_index);
  7820. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  7821. }
  7822. //==========================================
  7823. // csu trigger ChangeAvailabilityConf
  7824. //==========================================
  7825. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  7826. {
  7827. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  7828. }
  7829. //==========================================
  7830. // csu trigger UnlockConnectorConf
  7831. //==========================================
  7832. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  7833. {
  7834. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  7835. }
  7836. //==========================================
  7837. // csu trigger ReserveNowConf
  7838. //==========================================
  7839. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  7840. {
  7841. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  7842. }
  7843. //==========================================
  7844. // csu trigger ReserveNowConf
  7845. //==========================================
  7846. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  7847. {
  7848. sendReservationStatusUpdateRequest(gun_index);
  7849. }
  7850. //==========================================
  7851. // csu trigger LogStatusNotificationReq
  7852. //==========================================
  7853. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  7854. {
  7855. if(isCancelUploadLog == TRUE)
  7856. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7857. else
  7858. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  7859. }
  7860. //==========================================
  7861. // csu trigger SignCertificateReq
  7862. //==========================================
  7863. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  7864. {
  7865. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  7866. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  7867. {
  7868. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  7869. }
  7870. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  7871. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  7872. {
  7873. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  7874. }
  7875. }
  7876. }
  7877. }
  7878. //==========================================
  7879. // send request routine
  7880. //==========================================
  7881. int sendAuthorizeRequest(int gun_index)
  7882. {
  7883. mtrace();
  7884. int result = FAIL;
  7885. char message[4096]={0};
  7886. char guid[37];
  7887. char tempdata[128]={0};
  7888. json_object *Authorize = json_object_new_object();
  7889. json_object *idToken = json_object_new_object();
  7890. DEBUG_INFO("sendAuthorizeRequest...\n");
  7891. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  7892. //Local Authorize
  7893. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "true")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  7894. {
  7895. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  7896. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7897. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  7898. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  7899. result = PASS;
  7900. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7901. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7902. authorizeRetryTimes = 0;
  7903. return result;
  7904. }
  7905. 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)) ||
  7906. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true") == 0)))
  7907. {
  7908. // Query idtag from cache
  7909. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  7910. // Query idtag from list
  7911. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7912. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  7913. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7914. {
  7915. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  7916. {
  7917. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7918. }
  7919. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  7920. {
  7921. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7922. }
  7923. // Return authorize result if does not connect to server
  7924. if(!ShmOCPP20Data->OcppConnStatus)
  7925. {
  7926. DEBUG_INFO("Local Authorization Fail.\n");
  7927. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7928. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7929. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  7930. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7931. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7932. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7933. authorizeRetryTimes = 0;
  7934. return result;
  7935. }
  7936. }
  7937. else
  7938. {
  7939. DEBUG_INFO("Local Authorization get result.\n");
  7940. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  7941. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7942. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  7943. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  7944. else
  7945. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  7946. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7947. result = PASS;
  7948. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7949. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7950. authorizeRetryTimes = 0;
  7951. return result;
  7952. }
  7953. }
  7954. //get data from shared memory
  7955. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7956. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  7957. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  7958. if(strcmp((char*)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenType_eMAID]) == 0)
  7959. {
  7960. memset(&ShmOCPP20Data->Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  7961. int parseCertResult = FAIL;
  7962. json_object *iso15118CertificateHashData = json_object_new_array();
  7963. // Read CERTIFICATE_PnCAuth file content
  7964. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  7965. {
  7966. memset(ShmOCPP20Data->Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.certificate));
  7967. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  7968. char *line = NULL;
  7969. size_t len = 0;
  7970. while(getline(&line, &len, fp) != -1)
  7971. {
  7972. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  7973. strcat((char *)ShmOCPP20Data->Authorize.certificate, line);
  7974. }
  7975. fclose(fp);
  7976. }
  7977. if(strlen((char*)ShmOCPP20Data->Authorize.certificate) > 0)
  7978. json_object_object_add(Authorize, "certificate", json_object_new_string((char*)ShmOCPP20Data->Authorize.certificate));
  7979. char parseData[512] = {0};
  7980. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  7981. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  7982. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  7983. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  7984. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  7985. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  7986. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  7987. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  7988. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  7989. strcpy((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  7990. for(int idx=0; idx < 4; idx++)
  7991. {
  7992. if(strlen((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  7993. {
  7994. json_object *OCSPRequestDataType = json_object_new_object();
  7995. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  7996. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  7997. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  7998. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].serialNumber));
  7999. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL));
  8000. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  8001. parseCertResult = PASS;
  8002. }
  8003. }
  8004. if(parseCertResult == PASS)
  8005. {
  8006. json_object_object_add(Authorize, "iso15118CertificateHashData", iso15118CertificateHashData);
  8007. }
  8008. else
  8009. {
  8010. sprintf((char*)ShmOCPP20Data->Authorize.Response_certificateStatus, "NoCertificateAvailable");
  8011. sprintf((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Invalid");
  8012. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON;
  8013. }
  8014. }
  8015. json_object_object_add(Authorize, "idToken", idToken);
  8016. random_uuid(guid);
  8017. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  8018. json_object_put(Authorize);
  8019. LWS_Send(message);
  8020. sprintf(tempdata, "Authorize,%d", gun_index);
  8021. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8022. {
  8023. result = PASS;
  8024. }
  8025. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  8026. return result;
  8027. }
  8028. int sendBootNotificationRequest()
  8029. {
  8030. mtrace();
  8031. int result = FAIL;
  8032. char message[4096]={0};
  8033. char guid[37]={0};
  8034. char tempdata[128]={0};
  8035. json_object *BootNotification = json_object_new_object();
  8036. json_object *chargingStation = json_object_new_object();
  8037. json_object *modem = json_object_new_object();
  8038. DEBUG_INFO("sendBootNotificationRequest...\n");
  8039. // Fill BootNotification fields
  8040. DB_getBooType();
  8041. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  8042. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8043. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8044. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  8045. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  8046. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  8047. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  8048. {
  8049. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  8050. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  8051. json_object_object_add(chargingStation, "modem", modem);
  8052. }
  8053. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  8054. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  8055. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  8056. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  8057. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  8058. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  8059. random_uuid(guid);
  8060. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  8061. json_object_put(BootNotification);
  8062. LWS_Send(message);
  8063. sprintf(tempdata, "BootNotification,0");
  8064. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8065. {
  8066. result = PASS;
  8067. }
  8068. return result;
  8069. }
  8070. int sendClearedChargingLimitRequest(int gun_index)
  8071. {
  8072. mtrace();
  8073. int result = FAIL;
  8074. char message[4096]={0};
  8075. char guid[37]={0};
  8076. char tempdata[128]={0};
  8077. json_object *ClearedChargingLimit = json_object_new_object();
  8078. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  8079. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  8080. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  8081. random_uuid(guid);
  8082. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  8083. json_object_put(ClearedChargingLimit);
  8084. LWS_Send(message);
  8085. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  8086. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8087. {
  8088. result = PASS;
  8089. }
  8090. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  8091. return result;
  8092. }
  8093. int sendDataTransferRequest(int gun_index)
  8094. {
  8095. mtrace();
  8096. char message[1000]={0};
  8097. char guid[37]={0};
  8098. char tempdata[65]={0};
  8099. int result = FAIL;
  8100. DEBUG_INFO("sendDataTransferRequest...\n");
  8101. random_uuid(guid);
  8102. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  8103. MESSAGE_TYPE_CALL,
  8104. guid,
  8105. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  8106. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  8107. ShmOCPP20Data->DataTransfer[gun_index].data);
  8108. LWS_Send(message);
  8109. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  8110. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8111. {
  8112. result = PASS;
  8113. }
  8114. return result;
  8115. }
  8116. int sendFirmwareStatusNotificationRequest(char *status)
  8117. {
  8118. mtrace();
  8119. int result = FAIL;
  8120. char message[110]={0};
  8121. char guid[37]={0};
  8122. char tempdata[65]={0};
  8123. json_object *FirmwareStatusNotification = json_object_new_object();
  8124. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  8125. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  8126. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  8127. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  8128. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  8129. random_uuid(guid);
  8130. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8131. json_object_put(FirmwareStatusNotification);
  8132. LWS_SendNow(message);
  8133. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  8134. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8135. {
  8136. result = PASS;
  8137. }
  8138. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  8139. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  8140. //record status
  8141. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  8142. {
  8143. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  8144. }
  8145. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  8146. {
  8147. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  8148. }
  8149. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  8150. {
  8151. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  8152. }
  8153. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  8154. {
  8155. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  8156. }
  8157. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  8158. {
  8159. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  8160. }
  8161. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  8162. {
  8163. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  8164. }
  8165. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  8166. {
  8167. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  8168. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8169. }
  8170. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  8171. {
  8172. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  8173. }
  8174. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  8175. {
  8176. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  8177. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8178. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8179. }
  8180. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  8181. {
  8182. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  8183. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8184. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8185. }
  8186. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  8187. {
  8188. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  8189. }
  8190. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  8191. {
  8192. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  8193. }
  8194. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  8195. {
  8196. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  8197. }
  8198. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  8199. {
  8200. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  8201. }
  8202. return result;
  8203. }
  8204. int sendGet15118EVCertificateRequest()
  8205. {
  8206. mtrace();
  8207. int result = FAIL;
  8208. char message[4096]={0};
  8209. char guid[37]={0};
  8210. char tempdata[128]={0};
  8211. json_object *Get15118EVCertificate = json_object_new_object();
  8212. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  8213. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  8214. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  8215. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  8216. random_uuid(guid);
  8217. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  8218. json_object_put(Get15118EVCertificate);
  8219. LWS_Send(message);
  8220. sprintf(tempdata, "Get15118EVCertificate,0");
  8221. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8222. {
  8223. result = PASS;
  8224. }
  8225. return result;
  8226. }
  8227. int sendGetCertificateStatusRequest()
  8228. {
  8229. mtrace();
  8230. int result = FAIL;
  8231. char message[4096]={0};
  8232. char guid[37]={0};
  8233. char tempdata[128]={0};
  8234. json_object *GetCertificateStatus = json_object_new_object();
  8235. json_object *ocspRequestData = json_object_new_object();
  8236. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  8237. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  8238. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  8239. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  8240. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  8241. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  8242. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  8243. random_uuid(guid);
  8244. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  8245. json_object_put(GetCertificateStatus);
  8246. LWS_Send(message);
  8247. sprintf(tempdata, "GetCertificateStatus,0");
  8248. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8249. {
  8250. result = PASS;
  8251. }
  8252. return result;
  8253. }
  8254. int sendHeartbeatRequest()
  8255. {
  8256. mtrace();
  8257. int result = FAIL;
  8258. char message[40096]={0};
  8259. char guid[37]={0};
  8260. char tempdata[128]={0};
  8261. DEBUG_INFO("sendHeartbeatRequest...\n");
  8262. random_uuid(guid);
  8263. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{}]"
  8264. , MESSAGE_TYPE_CALL
  8265. , guid );
  8266. LWS_Send(message);
  8267. sprintf(tempdata, "Heartbeat,%d", 0);
  8268. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8269. {
  8270. result = PASS;
  8271. }
  8272. return result;
  8273. }
  8274. int sendLogStatusNotificationRequest(char *status)
  8275. {
  8276. mtrace();
  8277. int result = FAIL;
  8278. char message[4096]={0};
  8279. char guid[37]={0};
  8280. char tempdata[128]={0};
  8281. json_object *LogStatusNotification = json_object_new_object();
  8282. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8283. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  8284. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  8285. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  8286. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  8287. random_uuid(guid);
  8288. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8289. json_object_put(LogStatusNotification);
  8290. LWS_SendNow(message);
  8291. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8292. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8293. {
  8294. result = PASS;
  8295. }
  8296. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  8297. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  8298. //record status
  8299. if(strcmp(status,"BadMessage")==0)
  8300. {
  8301. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  8302. }
  8303. else if(strcmp(status,"Idle")==0)
  8304. {
  8305. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  8306. }
  8307. else if(strcmp(status,"NotSupportedOperation")==0)
  8308. {
  8309. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  8310. }
  8311. else if(strcmp(status,"PermissionDenied")==0)
  8312. {
  8313. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  8314. }
  8315. else if(strcmp(status,"Uploaded")==0)
  8316. {
  8317. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  8318. }
  8319. else if(strcmp(status,"UploadFailure")==0)
  8320. {
  8321. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  8322. }
  8323. else if(strcmp(status,"Uploading")==0)
  8324. {
  8325. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  8326. }
  8327. return result;
  8328. }
  8329. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType, uint8_t isSampledDataTxEnd)
  8330. {
  8331. mtrace();
  8332. int result = FAIL;
  8333. char guid[37]={0};
  8334. char tempdata[65]={0};
  8335. int tempIndex = 0;
  8336. DEBUG_INFO("sendMeterValuesRequest...\n");
  8337. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  8338. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  8339. //set value
  8340. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  8341. //UTC Date time
  8342. struct timeval tmnow;
  8343. struct tm *tm;
  8344. char buf[28];//, usec_buf[6];
  8345. gettimeofday(&tmnow, NULL);
  8346. time_t t;
  8347. t = time(NULL);
  8348. /*UTC time and date*/
  8349. tm = gmtime(&t);
  8350. if(dataType == ReadingContextEnumType_Sample_Clock)
  8351. {
  8352. struct tm *tmTarget;
  8353. struct timeb tbTarget;
  8354. tbTarget.time = mktime(tm);
  8355. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  8356. tmTarget = gmtime(&tbTarget.time);
  8357. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  8358. }
  8359. else
  8360. {
  8361. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8362. }
  8363. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  8364. struct ChargingInfoData *targetChargingInfoData = getTargetChargingInfoData(gun_index);
  8365. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  8366. //idx_sample=0;
  8367. //********************************(1)Current.Import L1************************************************/
  8368. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8369. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8370. (dataType == ReadingContextEnumType_Trigger))
  8371. {
  8372. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8373. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrent*100))/100.0;
  8374. if(gunType[gun_index] == GUN_TYPE_AC)
  8375. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8376. else
  8377. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8378. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  8379. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8380. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8381. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  8382. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  8383. }
  8384. //idx_sample=1;
  8385. //********************************(2)Energy.Active.Import.Register ************************************************/
  8386. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8387. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8388. (dataType == ReadingContextEnumType_Trigger))
  8389. {
  8390. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8391. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(targetChargingInfoData->PowerConsumption*100))/100.0;
  8392. if(gunType[gun_index] == GUN_TYPE_AC)
  8393. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8394. else
  8395. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8396. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  8397. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  8398. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8399. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  8400. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8401. }
  8402. //idx_sample=2;
  8403. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  8404. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8405. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8406. (dataType == ReadingContextEnumType_Trigger))
  8407. {
  8408. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8409. if(dataType == ReadingContextEnumType_Sample_Clock)
  8410. {
  8411. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousClockPowerConsumption[gun_index]);
  8412. periousClockPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8413. }
  8414. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  8415. {
  8416. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  8417. periousPeriodicPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8418. }
  8419. else
  8420. {
  8421. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  8422. }
  8423. if(gunType[gun_index] == GUN_TYPE_AC)
  8424. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8425. else
  8426. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8427. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  8428. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  8429. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8430. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  8431. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8432. }
  8433. //idx_sample=3;
  8434. //********************************(4)Power.Active.Import************************************************/
  8435. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8436. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8437. (dataType == ReadingContextEnumType_Trigger))
  8438. {
  8439. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8440. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(targetChargingInfoData->PresentChargingPower*100))/100.0;
  8441. if(gunType[gun_index] == GUN_TYPE_AC)
  8442. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8443. else
  8444. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8445. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  8446. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  8447. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8448. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  8449. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  8450. }
  8451. //idx_sample=4;
  8452. //***********************************************(5)VOLTAGE L1******************************************************/
  8453. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8454. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8455. (dataType == ReadingContextEnumType_Trigger))
  8456. {
  8457. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8458. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltage*100))/100.0;
  8459. if(gunType[gun_index] == GUN_TYPE_AC)
  8460. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8461. else
  8462. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8463. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  8464. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8465. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8466. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  8467. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  8468. }
  8469. //***********************************************(6)SOC******************************************************/
  8470. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8471. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8472. (dataType == ReadingContextEnumType_Trigger))
  8473. {
  8474. 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))
  8475. {
  8476. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = targetChargingInfoData->EvBatterySoc;
  8477. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  8478. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  8479. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8480. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  8481. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  8482. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  8483. }
  8484. }
  8485. //********************************(7)Current.Import L2************************************************/
  8486. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8487. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8488. (dataType == ReadingContextEnumType_Trigger))
  8489. {
  8490. // Only for AC 3 phase
  8491. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8492. {
  8493. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL2*100))/100.0;
  8494. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8495. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  8496. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8497. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8498. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  8499. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  8500. }
  8501. }
  8502. //********************************(8)Current.Import L3************************************************/
  8503. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8504. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8505. (dataType == ReadingContextEnumType_Trigger))
  8506. {
  8507. // Only for AC 3 phase
  8508. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8509. {
  8510. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL3*100))/100.0;
  8511. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8512. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  8513. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8514. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8515. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  8516. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  8517. }
  8518. }
  8519. //***********************************************(9)VOLTAGE L2******************************************************/
  8520. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8521. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8522. (dataType == ReadingContextEnumType_Trigger))
  8523. {
  8524. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8525. {
  8526. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL2*100))/100.0;
  8527. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8528. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8529. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8530. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8531. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8532. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8533. }
  8534. }
  8535. //***********************************************(10)VOLTAGE L3******************************************************/
  8536. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8537. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8538. (dataType == ReadingContextEnumType_Trigger))
  8539. {
  8540. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8541. {
  8542. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL3*100))/100.0;
  8543. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8544. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8545. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8546. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8547. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8548. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8549. }
  8550. }
  8551. //***********************************************(11)Current.Offered******************************************************/
  8552. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8553. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8554. (dataType == ReadingContextEnumType_Trigger))
  8555. {
  8556. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8557. if(gunType[gun_index] == GUN_TYPE_AC)
  8558. {
  8559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8560. {
  8561. tempIndex = 2;
  8562. }
  8563. else
  8564. {
  8565. tempIndex = gun_index;
  8566. }
  8567. for (int index = 0; index < AC_QUANTITY; index++)
  8568. {
  8569. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8570. {
  8571. uint16_t currentOffer;
  8572. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8573. {
  8574. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8575. }
  8576. else
  8577. {
  8578. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8579. }
  8580. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8581. }
  8582. }
  8583. }
  8584. else
  8585. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t)(targetChargingInfoData->AvailableChargingCurrent/10);
  8586. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8587. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8588. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8589. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8590. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8591. }
  8592. //***********************************************(12)Power.Offered******************************************************/
  8593. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8594. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8595. (dataType == ReadingContextEnumType_Trigger))
  8596. {
  8597. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8598. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t)(targetChargingInfoData->AvailableChargingPower*100);
  8599. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8600. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8601. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8602. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8603. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8604. }
  8605. // Message create ====================================================================================================
  8606. random_uuid(guid);
  8607. json_object *MeterValueReq = json_object_new_object();
  8608. json_object *meterValues = json_object_new_array();
  8609. json_object *sampledValues = json_object_new_array();
  8610. json_object *sampledValuesBuffer = json_object_new_array();
  8611. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8612. {
  8613. json_object *meterValue = json_object_new_object();
  8614. json_object *MeterValueBuffer = json_object_new_object();
  8615. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8616. {
  8617. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8618. {
  8619. json_object *sampledValue = json_object_new_object();
  8620. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8621. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8622. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8623. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8624. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8625. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8626. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8627. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8628. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8629. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8630. {
  8631. json_object *signedMeterValue = json_object_new_object();
  8632. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8633. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8634. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8635. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8636. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8637. }
  8638. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8639. {
  8640. json_object *unitOfMeasure = json_object_new_object();
  8641. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8642. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8643. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8644. }
  8645. json_object_array_add(sampledValues, sampledValue);
  8646. // For StopTxn data
  8647. if((isSampledDataTxEnd == TRUE) &&
  8648. (((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)) ||
  8649. ((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))))
  8650. {
  8651. json_object *sampledValue = json_object_new_object();
  8652. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8653. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8654. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8655. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8656. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8657. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8658. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8659. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8660. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8661. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8662. {
  8663. json_object *signedMeterValue = json_object_new_object();
  8664. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8665. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8666. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8667. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8668. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8669. }
  8670. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8671. {
  8672. json_object *unitOfMeasure = json_object_new_object();
  8673. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8674. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8675. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8676. }
  8677. json_object_array_add(sampledValuesBuffer, sampledValue);
  8678. }
  8679. }
  8680. }
  8681. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8682. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8683. json_object_array_add(meterValues, meterValue);
  8684. // For StopTxn data
  8685. if((isSampledDataTxEnd == TRUE) && (dataType != ReadingContextEnumType_Trigger) &&
  8686. (json_object_array_length(sampledValuesBuffer) > 0))
  8687. {
  8688. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8689. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  8690. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  8691. meterValueBufferInsert(gun_index, dataType, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  8692. else
  8693. meterValueBufferReplace(200, gun_index, dataType, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  8694. json_object_put(MeterValueBuffer);
  8695. }
  8696. else
  8697. {
  8698. json_object_put(sampledValuesBuffer);
  8699. json_object_put(MeterValueBuffer);
  8700. }
  8701. idxMeter++;
  8702. }
  8703. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8704. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8705. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8706. ,MESSAGE_TYPE_CALL
  8707. ,guid
  8708. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8709. json_object_put(MeterValueReq);
  8710. if((dataType != ReadingContextEnumType_Trigger) &&
  8711. (dataType != ReadingContextEnumType_Sample_Clock))
  8712. {
  8713. // Transaction meter value send by TransactionEvent message
  8714. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8715. if(isSampledDataTxEnd != TRUE)
  8716. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8717. result = PASS;
  8718. }
  8719. else
  8720. {
  8721. // Put request guid to hash map
  8722. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8723. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8724. {
  8725. result = PASS;
  8726. }
  8727. if((dataType != ReadingContextEnumType_Trigger) &&
  8728. (dataType != ReadingContextEnumType_Sample_Clock))
  8729. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8730. else
  8731. {
  8732. if(FirstHeartBeat)
  8733. LWS_Send(queuedata);
  8734. }
  8735. }
  8736. return result;
  8737. }
  8738. int sendNotifyChargingLimitRequest(int gun_index)
  8739. {
  8740. mtrace();
  8741. int result = FAIL;
  8742. char message[4096]={0};
  8743. char guid[37]={0};
  8744. char tempdata[128]={0};
  8745. json_object *NotifyChargingLimit = json_object_new_object();
  8746. json_object *chargingLimit = json_object_new_object();
  8747. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8748. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8749. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8750. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8751. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8752. random_uuid(guid);
  8753. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8754. json_object_put(NotifyChargingLimit);
  8755. LWS_Send(message);
  8756. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8757. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8758. {
  8759. result = PASS;
  8760. }
  8761. return result;
  8762. }
  8763. int sendNotifyCustomerInformationRequest()
  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 *NotifyCustomerInformation = json_object_new_object();
  8771. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8772. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8773. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8774. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8775. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8776. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8777. random_uuid(guid);
  8778. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8779. json_object_put(NotifyCustomerInformation);
  8780. LWS_Send(message);
  8781. sprintf(tempdata, "NotifyCustomerInformation,0");
  8782. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8783. {
  8784. result = PASS;
  8785. }
  8786. return result;
  8787. }
  8788. int sendNotifyDisplayMessagesRequest()
  8789. {
  8790. mtrace();
  8791. int result = FAIL;
  8792. char message[4096]={0};
  8793. char guid[37]={0};
  8794. char tempdata[128]={0};
  8795. json_object *NotifyDisplayMessages = json_object_new_object();
  8796. json_object *messageInfos = json_object_new_array();
  8797. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8798. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8799. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8800. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8801. {
  8802. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8803. {
  8804. json_object *messageInfo = json_object_new_object();
  8805. json_object *message = json_object_new_object();
  8806. json_object *display = json_object_new_object();
  8807. json_object *evse = json_object_new_object();
  8808. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8809. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8810. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8811. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8812. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8813. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8814. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8815. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8816. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8817. json_object_object_add(messageInfo, "message", message);
  8818. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8819. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8820. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8821. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8822. json_object_object_add(display, "evse",evse);
  8823. json_object_object_add(messageInfo, "evse", display);
  8824. json_object_array_add(messageInfos, messageInfo);
  8825. }
  8826. }
  8827. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8828. random_uuid(guid);
  8829. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8830. json_object_put(NotifyDisplayMessages);
  8831. LWS_Send(message);
  8832. sprintf(tempdata, "NotifyDisplayMessages,0");
  8833. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8834. {
  8835. result = PASS;
  8836. }
  8837. return result;
  8838. }
  8839. int sendNotifyEVChargingNeedsRequest(int gun_index)
  8840. {
  8841. mtrace();
  8842. int result = FAIL;
  8843. char message[4096]={0};
  8844. char guid[37]={0};
  8845. char tempdata[128]={0};
  8846. json_object *NotifyEVChargingNeeds = json_object_new_object();
  8847. json_object *chargingNeeds = json_object_new_object();
  8848. json_object *acChargingParameters = json_object_new_object();
  8849. json_object *dcChargingParameters = json_object_new_object();
  8850. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8851. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8852. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8853. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8854. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8855. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8856. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8857. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8858. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8859. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8860. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8861. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8862. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8863. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8864. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8865. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8866. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8867. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8868. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8869. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8870. random_uuid(guid);
  8871. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8872. json_object_put(NotifyEVChargingNeeds);
  8873. LWS_Send(message);
  8874. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8875. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8876. {
  8877. result = PASS;
  8878. }
  8879. return result;
  8880. }
  8881. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8882. {
  8883. mtrace();
  8884. int result = FAIL;
  8885. char message[4096]={0};
  8886. char guid[37]={0};
  8887. char tempdata[128]={0};
  8888. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8889. json_object *chargingSchedule = json_object_new_object();
  8890. json_object *periods = json_object_new_array();
  8891. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8892. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8893. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8894. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8895. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8896. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8897. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8898. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8899. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8900. {
  8901. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8902. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8903. {
  8904. json_object *Period = json_object_new_object();
  8905. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8906. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8907. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8908. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8909. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8910. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8911. json_object_array_add(periods, Period);
  8912. }
  8913. }
  8914. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8915. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8916. random_uuid(guid);
  8917. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8918. json_object_put(NotifyEVChargingSchedule);
  8919. LWS_Send(message);
  8920. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8921. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8922. {
  8923. result = PASS;
  8924. }
  8925. return result;
  8926. }
  8927. int sendNotifyEventRequest()
  8928. {
  8929. mtrace();
  8930. int result = FAIL;
  8931. char message[4096]={0};
  8932. char guid[37]={0};
  8933. char tempdata[128]={0};
  8934. json_object *NotifyEvent = json_object_new_object();
  8935. json_object *eventDatas = json_object_new_array();
  8936. DEBUG_INFO("sendNotifyEventRequest...\n");
  8937. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8938. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8939. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8940. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8941. {
  8942. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8943. {
  8944. json_object *eventData = 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_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8949. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8950. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8951. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8952. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8953. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8954. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8955. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8956. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8957. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8958. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8959. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8960. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8961. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8962. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  8963. json_object_object_add(component, "evse",evse);
  8964. json_object_object_add(eventData, "component", component);
  8965. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  8966. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  8967. json_object_object_add(eventData, "variable", variable);
  8968. json_object_array_add(eventDatas, eventData);
  8969. }
  8970. }
  8971. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  8972. random_uuid(guid);
  8973. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  8974. json_object_put(NotifyEvent);
  8975. LWS_Send(message);
  8976. sprintf(tempdata, "NotifyEvent,0");
  8977. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8978. {
  8979. result = PASS;
  8980. }
  8981. return result;
  8982. }
  8983. int sendNotifyMonitoringReportRequest()
  8984. {
  8985. mtrace();
  8986. int result = FAIL;
  8987. char message[4096]={0};
  8988. char guid[37]={0};
  8989. char tempdata[128]={0};
  8990. json_object *NotifyMonitoringReport = json_object_new_object();
  8991. json_object *monitors = json_object_new_array();
  8992. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  8993. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  8994. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  8995. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  8996. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  8997. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  8998. {
  8999. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  9000. {
  9001. json_object *monitor = json_object_new_object();
  9002. json_object *component = json_object_new_object();
  9003. json_object *evse = json_object_new_object();
  9004. json_object *variable = json_object_new_object();
  9005. json_object *variableMonitorings = json_object_new_array();
  9006. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  9007. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  9008. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  9009. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  9010. json_object_object_add(component, "evse",evse);
  9011. json_object_object_add(monitor, "component", component);
  9012. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  9013. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  9014. json_object_object_add(monitor, "variable", variable);
  9015. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  9016. {
  9017. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  9018. {
  9019. json_object *variableMonitoring = json_object_new_object();
  9020. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  9021. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  9022. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  9023. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  9024. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  9025. json_object_array_add(variableMonitorings, variableMonitoring);
  9026. }
  9027. }
  9028. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  9029. json_object_array_add(monitors, monitor);
  9030. }
  9031. }
  9032. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  9033. random_uuid(guid);
  9034. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  9035. json_object_put(NotifyMonitoringReport);
  9036. LWS_Send(message);
  9037. sprintf(tempdata, "NotifyMonitoringReport,0");
  9038. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9039. {
  9040. result = PASS;
  9041. }
  9042. return result;
  9043. }
  9044. int sendNotifyReportRequest()
  9045. {
  9046. mtrace();
  9047. int result = FAIL;
  9048. char message[4096]={0};
  9049. char guid[37]={0};
  9050. char tempdata[128]={0};
  9051. json_object *NotifyReport = json_object_new_object();
  9052. json_object *reportDatas = json_object_new_array();
  9053. DEBUG_INFO("sendNotifyReportRequest...\n");
  9054. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  9055. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  9056. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  9057. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  9058. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  9059. {
  9060. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  9061. {
  9062. json_object *reportData = json_object_new_object();
  9063. json_object *component = json_object_new_object();
  9064. json_object *evse = json_object_new_object();
  9065. json_object *variable = json_object_new_object();
  9066. json_object *variableAttributes = json_object_new_array();
  9067. json_object *variableCharacteristics = json_object_new_object();
  9068. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  9069. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  9070. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  9071. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  9072. json_object_object_add(component, "evse",evse);
  9073. json_object_object_add(reportData, "component", component);
  9074. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  9075. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  9076. json_object_object_add(reportData, "variable",variable);
  9077. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  9078. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  9079. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  9080. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  9081. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  9082. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  9083. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  9084. {
  9085. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  9086. {
  9087. json_object *variableAttribute = json_object_new_object();
  9088. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  9089. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  9090. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  9091. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  9092. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  9093. json_object_array_add(variableAttributes, variableAttribute);
  9094. }
  9095. }
  9096. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  9097. json_object_array_add(reportDatas, reportData);
  9098. }
  9099. }
  9100. json_object_object_add(NotifyReport, "reportData", reportDatas);
  9101. random_uuid(guid);
  9102. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  9103. json_object_put(NotifyReport);
  9104. LWS_SendNow(message);
  9105. sprintf(tempdata, "NotifyReport,0");
  9106. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9107. {
  9108. result = PASS;
  9109. }
  9110. return result;
  9111. }
  9112. int sendPublishFirmwareStatusNotificationRequest()
  9113. {
  9114. mtrace();
  9115. int result = FAIL;
  9116. char message[4096]={0};
  9117. char guid[37]={0};
  9118. char tempdata[128]={0};
  9119. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  9120. json_object *locations = json_object_new_array();
  9121. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  9122. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  9123. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  9124. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  9125. {
  9126. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  9127. }
  9128. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  9129. random_uuid(guid);
  9130. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  9131. json_object_put(PublishFirmwareStatusNotification);
  9132. LWS_Send(message);
  9133. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  9134. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9135. {
  9136. result = PASS;
  9137. }
  9138. return result;
  9139. }
  9140. int sendReportChargingProfilesRequest(int gun_index)
  9141. {
  9142. mtrace();
  9143. int result = FAIL;
  9144. char message[4096]={0};
  9145. char guid[37]={0};
  9146. char tempdata[128]={0};
  9147. json_object *ReportChargingProfiles = json_object_new_object();
  9148. json_object *chargingProfiles = json_object_new_array();
  9149. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  9150. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  9151. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  9152. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  9153. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  9154. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  9155. {
  9156. json_object *chargingProfile = json_object_new_object();
  9157. json_object *chargingSchedules = json_object_new_array();
  9158. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  9159. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  9160. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  9161. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  9162. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  9163. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  9164. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  9165. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  9166. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  9167. {
  9168. json_object *chargingSchedule = json_object_new_object();
  9169. json_object *chargingSchedulePeriods = json_object_new_array();
  9170. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  9171. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  9172. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  9173. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  9174. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  9175. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  9176. {
  9177. json_object *chargingSchedulePeriod = json_object_new_object();
  9178. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  9179. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  9180. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  9181. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  9182. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  9183. }
  9184. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  9185. json_object_array_add(chargingSchedules, chargingSchedule);
  9186. }
  9187. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  9188. json_object_array_add(chargingProfiles, chargingProfile);
  9189. }
  9190. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  9191. random_uuid(guid);
  9192. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  9193. json_object_put(ReportChargingProfiles);
  9194. LWS_Send(message);
  9195. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  9196. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9197. {
  9198. result = PASS;
  9199. }
  9200. return result;
  9201. }
  9202. int sendReservationStatusUpdateRequest(int gun_index)
  9203. {
  9204. mtrace();
  9205. int result = FAIL;
  9206. char message[4096]={0};
  9207. char guid[37]={0};
  9208. char tempdata[128]={0};
  9209. json_object *ReservationStatusUpdate = json_object_new_object();
  9210. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  9211. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  9212. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  9213. random_uuid(guid);
  9214. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  9215. json_object_put(ReservationStatusUpdate);
  9216. LWS_Send(message);
  9217. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  9218. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9219. {
  9220. result = PASS;
  9221. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  9222. }
  9223. return result;
  9224. }
  9225. int sendSecurityEventNotificationRequest()
  9226. {
  9227. mtrace();
  9228. int result = FAIL;
  9229. char message[4096]={0};
  9230. char guid[37]={0};
  9231. char tempdata[128]={0};
  9232. struct timeval tmnow;
  9233. struct tm *tm;
  9234. char buf[28];//, usec_buf[6];
  9235. json_object *SecurityEventNotification = json_object_new_object();
  9236. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  9237. DB_getSecurityEventType();
  9238. gettimeofday(&tmnow, NULL);
  9239. time_t t;
  9240. t = time(NULL);
  9241. /*UTC time and date*/
  9242. tm = gmtime(&t);
  9243. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9244. #if 0 // remove temporally
  9245. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9246. strcat(buf,".");
  9247. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9248. strcat(buf,usec_buf);
  9249. #endif
  9250. printf("%s",buf);
  9251. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  9252. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  9253. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  9254. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  9255. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  9256. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  9257. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  9258. random_uuid(guid);
  9259. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  9260. json_object_put(SecurityEventNotification);
  9261. LWS_Send(message);
  9262. sprintf(tempdata, "SecurityEventNotification,0");
  9263. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9264. {
  9265. result = PASS;
  9266. }
  9267. return result;
  9268. }
  9269. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  9270. {
  9271. mtrace();
  9272. int result = FAIL;
  9273. char message[4096]={0};
  9274. char guid[37]={0};
  9275. char tempdata[128]={0};
  9276. json_object *SignCertificate = json_object_new_object();
  9277. DEBUG_INFO("sendSignCertificateRequest...\n");
  9278. // Read csr file content
  9279. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  9280. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?CSR_V2G:CSR_CP),"r");
  9281. char *line = NULL;
  9282. size_t len = 0;
  9283. while(getline(&line, &len, fp) != -1)
  9284. {
  9285. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  9286. {
  9287. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  9288. }
  9289. }
  9290. fclose(fp);
  9291. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  9292. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  9293. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  9294. random_uuid(guid);
  9295. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  9296. json_object_put(SignCertificate);
  9297. LWS_Send(message);
  9298. sprintf(tempdata, "SignCertificate,0");
  9299. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9300. {
  9301. result = PASS;
  9302. }
  9303. return result;
  9304. }
  9305. int sendStatusNotificationRequest(int gun_index)
  9306. {
  9307. mtrace();
  9308. int result = FAIL;
  9309. char message[600]={0};
  9310. char guid[37];
  9311. int currentStatus = 0;
  9312. struct timeval tmnow;
  9313. struct tm *tm;
  9314. char buf[28];//, usec_buf[6];
  9315. char tempdata[65]={0};
  9316. int tempIndex = 0;
  9317. uint8_t isStateChanged = TRUE;
  9318. DEBUG_INFO("sendStatusNotificationRequest...\n");
  9319. gettimeofday(&tmnow, NULL);
  9320. time_t t;
  9321. t = time(NULL);
  9322. /*UTC time and date*/
  9323. tm = gmtime(&t);
  9324. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9325. #if 0 // remove temporally
  9326. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9327. strcat(buf,".");
  9328. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9329. strcat(buf,usec_buf);
  9330. #endif
  9331. printf("%s",buf);
  9332. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  9333. ShmOCPP20Data->StatusNotification[gun_index].connectorId = 1;
  9334. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  9335. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  9336. /*
  9337. enum _SYSTEM_STATUS
  9338. {
  9339. S_BOOTING = 0,
  9340. S_IDLE, = 1
  9341. S_AUTHORIZING, =2
  9342. S_REASSIGN_CHECK, =3
  9343. S_REASSIGN, =4
  9344. S_PRECHARGE, =5
  9345. S_PREPARING_FOR_EV, =6
  9346. S_PREPARING_FOR_EVSE, =7
  9347. S_CHARGING, =8
  9348. S_TERMINATING, =9
  9349. S_COMPLETE, =10
  9350. S_ALARM, =11
  9351. S_FAULT =12
  9352. }
  9353. */
  9354. //check Transaction active
  9355. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  9356. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9357. {
  9358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9359. {
  9360. tempIndex = ((gun_index==2) ? 1: 0);
  9361. }
  9362. else
  9363. {
  9364. tempIndex = gun_index;
  9365. }
  9366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9367. {
  9368. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9369. {
  9370. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9371. {
  9372. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9373. {
  9374. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9375. }
  9376. else
  9377. {
  9378. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9379. }
  9380. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9381. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9382. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9383. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9384. }
  9385. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9386. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9387. ) //S_PRECHARGE
  9388. {
  9389. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9390. }
  9391. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9392. {
  9393. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9394. }
  9395. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9396. {
  9397. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9398. }
  9399. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9400. {
  9401. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9402. }
  9403. 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
  9404. {
  9405. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9406. }
  9407. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9408. {
  9409. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9410. }
  9411. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9412. {
  9413. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9414. }
  9415. } //end of the same index
  9416. }//end of for CHAdeMO_QUANTITY
  9417. }
  9418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9419. {
  9420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9421. {
  9422. tempIndex = ((gun_index==2) ? 1: 0);
  9423. }
  9424. else
  9425. {
  9426. tempIndex = gun_index;
  9427. }
  9428. for (int index = 0; index < CCS_QUANTITY; index++)
  9429. {
  9430. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9431. {
  9432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9433. {
  9434. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9435. {
  9436. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9437. }
  9438. else
  9439. {
  9440. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9441. }
  9442. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9443. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9444. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9445. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9446. }
  9447. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9448. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9449. ) //S_PRECHARGE
  9450. {
  9451. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9452. }
  9453. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9454. {
  9455. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9456. }
  9457. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9458. {
  9459. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9460. }
  9461. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9462. {
  9463. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9464. }
  9465. 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
  9466. {
  9467. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9468. }
  9469. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9470. {
  9471. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9472. }
  9473. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9474. {
  9475. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9476. }
  9477. } //end of the same index
  9478. } // end of for CCS_QUANTITY
  9479. }
  9480. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9481. {
  9482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9483. {
  9484. tempIndex = ((gun_index==2) ? 1: 0);
  9485. }
  9486. else
  9487. {
  9488. tempIndex = gun_index;
  9489. }
  9490. for (int index = 0; index < GB_QUANTITY; index++)
  9491. {
  9492. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9493. {
  9494. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9495. {
  9496. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9497. {
  9498. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9499. }
  9500. else
  9501. {
  9502. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9503. }
  9504. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9505. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9506. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9507. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9508. }
  9509. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9510. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9511. ) //S_PRECHARGE
  9512. {
  9513. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9514. }
  9515. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9516. {
  9517. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9518. }
  9519. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9520. {
  9521. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9522. }
  9523. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9524. {
  9525. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9526. }
  9527. 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
  9528. {
  9529. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9530. }
  9531. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9532. {
  9533. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9534. }
  9535. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9536. {
  9537. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9538. }
  9539. } //end of the same index
  9540. } // end of for GB_QUANTITY
  9541. }
  9542. else if(gunType[gun_index] == GUN_TYPE_DO)
  9543. {
  9544. tempIndex = gun_index;
  9545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9546. {
  9547. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9548. {
  9549. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9550. {
  9551. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9552. {
  9553. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9554. }
  9555. else
  9556. {
  9557. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9558. }
  9559. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9560. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9561. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9562. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9563. }
  9564. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9565. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9566. ) //S_PRECHARGE
  9567. {
  9568. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9569. }
  9570. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9571. {
  9572. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9573. }
  9574. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9575. {
  9576. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9577. }
  9578. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9579. {
  9580. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9581. }
  9582. 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
  9583. {
  9584. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9585. }
  9586. 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
  9587. {
  9588. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9589. }
  9590. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9591. {
  9592. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9593. }
  9594. } //end of the same index
  9595. }
  9596. }
  9597. else
  9598. {
  9599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9600. {
  9601. tempIndex = 2;
  9602. }
  9603. else
  9604. {
  9605. tempIndex = gun_index;
  9606. }
  9607. for (int index = 0; index < AC_QUANTITY; index++)
  9608. {
  9609. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9610. {
  9611. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9612. {
  9613. 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))
  9614. {
  9615. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9616. }
  9617. else
  9618. {
  9619. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9620. }
  9621. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9622. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9623. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9624. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9625. }
  9626. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9627. {
  9628. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9629. }
  9630. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9631. {
  9632. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9633. }
  9634. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9635. {
  9636. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9637. }
  9638. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9639. {
  9640. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9641. }
  9642. 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
  9643. {
  9644. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9645. }
  9646. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9647. {
  9648. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9649. }
  9650. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9651. {
  9652. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9653. }
  9654. }//end of the same index
  9655. }//end of for AC_QUANTITY
  9656. }
  9657. //it's option
  9658. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9659. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9660. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") != 0))
  9661. {
  9662. isStateChanged = FALSE;
  9663. }
  9664. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9665. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9666. random_uuid(guid);
  9667. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9668. , MESSAGE_TYPE_CALL
  9669. , guid
  9670. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9671. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9672. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9673. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9674. if((server_sign == TRUE) && isStateChanged)
  9675. {
  9676. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9677. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9678. LWS_Send(message);
  9679. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9680. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9681. {
  9682. result = PASS;
  9683. }
  9684. }
  9685. else
  9686. {
  9687. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9688. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9689. result = PASS;
  9690. }
  9691. return result;
  9692. }
  9693. int sendTransactionEventRequest(int gun_index)
  9694. {
  9695. mtrace();
  9696. int result = FAIL;
  9697. char message[QUEUE_MESSAGE_LENGTH]={0};
  9698. char guid[37]={0};
  9699. char tempdata[128]={0};
  9700. uint8_t tempIndex;
  9701. json_object *TransactionEvent = json_object_new_object();
  9702. json_object *transactionInfo = json_object_new_object();
  9703. json_object *idToken = json_object_new_object();
  9704. json_object *evse = json_object_new_object();
  9705. json_object *meterValues = json_object_new_array();
  9706. char TempStopTransaction[256];
  9707. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9708. DEBUG_INFO("sendTransactionEventRequest...\n");
  9709. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9710. {
  9711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9712. {
  9713. tempIndex = ((gun_index==2) ? 1: 0);
  9714. }
  9715. else
  9716. {
  9717. tempIndex = gun_index;
  9718. }
  9719. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9720. {
  9721. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9722. {
  9723. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9724. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9725. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9726. else
  9727. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9728. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9729. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9730. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9731. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9732. {
  9733. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9734. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9735. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9736. {
  9737. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9738. }
  9739. else
  9740. {
  9741. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9742. }
  9743. }
  9744. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9745. {
  9746. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9747. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9748. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9749. }
  9750. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9751. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9752. ) //S_PRECHARGE
  9753. {
  9754. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9755. {
  9756. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9757. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9758. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9759. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9760. }
  9761. else
  9762. {
  9763. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9764. }
  9765. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9766. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9767. }
  9768. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9769. {
  9770. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9771. {
  9772. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9773. {
  9774. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9775. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9776. }
  9777. else
  9778. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9779. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9780. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9781. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9782. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9783. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9784. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  9785. }
  9786. else
  9787. {
  9788. storeTempStopTransaction(gun_index);
  9789. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9790. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9791. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9792. }
  9793. }
  9794. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9795. {
  9796. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9797. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9798. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9799. if((access(TempStopTransaction,F_OK))!=-1)
  9800. {
  9801. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9802. }
  9803. }
  9804. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9805. {
  9806. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9807. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9808. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9809. }
  9810. 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
  9811. {
  9812. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9813. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9814. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9815. }
  9816. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9817. {
  9818. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9819. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9820. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9821. }
  9822. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9823. {
  9824. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9825. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9826. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9827. }
  9828. } //end of the same index
  9829. }//end of for CHAdeMO_QUANTITY
  9830. }
  9831. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9832. {
  9833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9834. {
  9835. tempIndex = ((gun_index==2) ? 1: 0);
  9836. }
  9837. else
  9838. {
  9839. tempIndex = gun_index;
  9840. }
  9841. for (int index = 0; index < CCS_QUANTITY; index++)
  9842. {
  9843. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9844. {
  9845. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9846. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9847. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9848. else
  9849. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9850. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9851. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9852. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9854. {
  9855. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9856. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9857. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9858. {
  9859. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9860. }
  9861. else
  9862. {
  9863. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9864. }
  9865. }
  9866. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9867. {
  9868. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9869. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9870. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9871. }
  9872. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9873. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9874. ) //S_PRECHARGE
  9875. {
  9876. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9877. {
  9878. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9879. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9880. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9881. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9882. }
  9883. else
  9884. {
  9885. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9886. }
  9887. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9888. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9889. }
  9890. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9891. {
  9892. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9893. {
  9894. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9895. {
  9896. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9897. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9898. }
  9899. else
  9900. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9901. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9902. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9903. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9904. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9905. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9906. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  9907. }
  9908. else
  9909. {
  9910. storeTempStopTransaction(gun_index);
  9911. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9912. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9913. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9914. }
  9915. }
  9916. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9917. {
  9918. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9919. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9920. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9921. if((access(TempStopTransaction,F_OK))!=-1)
  9922. {
  9923. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9924. }
  9925. }
  9926. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9927. {
  9928. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9929. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9930. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9931. }
  9932. 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
  9933. {
  9934. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9935. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9936. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9937. }
  9938. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9939. {
  9940. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9941. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9942. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9943. }
  9944. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9945. {
  9946. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9947. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9948. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9949. }
  9950. } //end of the same index
  9951. } // end of for CCS_QUANTITY
  9952. }
  9953. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9954. {
  9955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9956. {
  9957. tempIndex = ((gun_index==2) ? 1: 0);
  9958. }
  9959. else
  9960. {
  9961. tempIndex = gun_index;
  9962. }
  9963. for (int index = 0; index < GB_QUANTITY; index++)
  9964. {
  9965. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9966. {
  9967. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9968. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9969. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9970. else
  9971. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9972. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9973. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9974. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9975. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9976. {
  9977. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9978. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9979. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9980. {
  9981. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9982. }
  9983. else
  9984. {
  9985. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9986. }
  9987. }
  9988. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9989. {
  9990. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9991. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9992. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9993. }
  9994. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9995. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9996. ) //S_PRECHARGE
  9997. {
  9998. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9999. {
  10000. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10001. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  10002. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  10003. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10004. }
  10005. else
  10006. {
  10007. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10008. }
  10009. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10010. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10011. }
  10012. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10013. {
  10014. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10015. {
  10016. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  10017. {
  10018. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10019. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10020. }
  10021. else
  10022. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10023. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10024. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  10025. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  10026. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10027. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10028. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  10029. }
  10030. else
  10031. {
  10032. storeTempStopTransaction(gun_index);
  10033. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10034. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10035. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10036. }
  10037. }
  10038. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10039. {
  10040. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10041. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10042. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10043. if((access(TempStopTransaction,F_OK))!=-1)
  10044. {
  10045. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10046. }
  10047. }
  10048. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10049. {
  10050. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10051. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10052. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10053. }
  10054. 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
  10055. {
  10056. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10057. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10058. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10059. }
  10060. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10061. {
  10062. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10063. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10064. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10065. }
  10066. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10067. {
  10068. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10069. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10070. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10071. }
  10072. } //end of the same index
  10073. } // end of for GB_QUANTITY
  10074. }
  10075. else if(gunType[gun_index] == GUN_TYPE_DO)
  10076. {
  10077. tempIndex = gun_index;
  10078. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10079. {
  10080. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10081. {
  10082. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10083. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10084. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10085. else
  10086. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10087. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10088. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10089. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10090. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10091. {
  10092. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10093. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10094. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  10095. {
  10096. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10097. }
  10098. else
  10099. {
  10100. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10101. }
  10102. }
  10103. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10104. {
  10105. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10106. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10107. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10108. }
  10109. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10110. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10111. ) //S_PRECHARGE
  10112. {
  10113. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10114. {
  10115. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10116. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10117. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10118. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10119. }
  10120. else
  10121. {
  10122. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10123. }
  10124. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10125. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10126. }
  10127. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10128. {
  10129. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10130. {
  10131. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  10132. {
  10133. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10134. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10135. }
  10136. else
  10137. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10138. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10139. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10140. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10141. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10142. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10143. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  10144. }
  10145. else
  10146. {
  10147. storeTempStopTransaction(gun_index);
  10148. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10149. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10150. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10151. }
  10152. }
  10153. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10154. {
  10155. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10156. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10157. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10158. if((access(TempStopTransaction,F_OK))!=-1)
  10159. {
  10160. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10161. }
  10162. }
  10163. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10164. {
  10165. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10166. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10167. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10168. }
  10169. 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
  10170. {
  10171. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10172. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10173. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10174. }
  10175. 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
  10176. {
  10177. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10178. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10179. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10180. }
  10181. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10182. {
  10183. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10184. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10185. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10186. }
  10187. } //end of the same index
  10188. }
  10189. }
  10190. else
  10191. {
  10192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10193. {
  10194. tempIndex = 2;
  10195. }
  10196. else
  10197. {
  10198. tempIndex = gun_index;
  10199. }
  10200. for (int index = 0; index < AC_QUANTITY; index++)
  10201. {
  10202. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10203. {
  10204. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10205. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10206. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10207. else
  10208. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10209. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10210. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10211. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  10213. {
  10214. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10215. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10216. 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))
  10217. {
  10218. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10219. }
  10220. else
  10221. {
  10222. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10223. }
  10224. }
  10225. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10226. {
  10227. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10228. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10229. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10230. }
  10231. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10232. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10233. ) //S_PRECHARGE
  10234. {
  10235. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10236. {
  10237. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10238. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10239. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10240. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10241. }
  10242. else
  10243. {
  10244. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10245. }
  10246. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10247. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10248. }
  10249. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10250. {
  10251. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10252. {
  10253. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10254. {
  10255. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10256. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10257. }
  10258. else
  10259. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10260. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10261. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10262. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10263. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10264. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10265. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  10266. }
  10267. else
  10268. {
  10269. storeTempStopTransaction(gun_index);
  10270. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10271. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10272. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10273. }
  10274. }
  10275. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10276. {
  10277. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10278. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10279. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10280. if((access(TempStopTransaction,F_OK))!=-1)
  10281. {
  10282. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10283. }
  10284. }
  10285. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10286. {
  10287. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10288. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10289. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10290. }
  10291. 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
  10292. {
  10293. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10294. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10295. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10296. }
  10297. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10298. {
  10299. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10300. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10301. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10302. }
  10303. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10304. {
  10305. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10306. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10307. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10308. }
  10309. }//end of the same index
  10310. }//end of for AC_QUANTITY
  10311. }
  10312. // Check if this message is triggered by TriggerMessage
  10313. if(cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  10314. {
  10315. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10316. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Trigger]);
  10317. }
  10318. // Clear meterValue buffer for the next transaction
  10319. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10320. {
  10321. meterValueBufferClear(gun_index);
  10322. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Transaction_Begin, FALSE);
  10323. }
  10324. // Message
  10325. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  10326. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  10327. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  10328. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  10329. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  10330. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  10331. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  10332. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  10333. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  10334. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  10335. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  10336. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  10337. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  10338. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  10339. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  10340. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  10341. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  10342. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  10343. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10344. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  10345. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  10346. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  10347. {
  10348. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  10349. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  10350. json_object_object_add(TransactionEvent, "idToken", idToken);
  10351. }
  10352. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  10353. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  10354. json_object_object_add(TransactionEvent, "evse", evse);
  10355. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  10356. {
  10357. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  10358. {
  10359. json_object *meterValue = json_object_new_object();
  10360. json_object *sampledValues = json_object_new_array();
  10361. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  10362. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  10363. {
  10364. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  10365. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) ||
  10366. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) ||
  10367. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) ||
  10368. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  10369. {
  10370. 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)) ||
  10371. ((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) == NULL)))
  10372. {
  10373. json_object *sampledValue = json_object_new_object();
  10374. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  10375. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  10376. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  10377. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  10378. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  10379. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  10380. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  10381. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  10382. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  10383. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  10384. {
  10385. json_object *unitOfMeasure = json_object_new_object();
  10386. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  10387. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  10388. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  10389. }
  10390. json_object_array_add(sampledValues, sampledValue);
  10391. }
  10392. }
  10393. }
  10394. json_object_object_add(meterValue, "sampledValue", sampledValues);
  10395. json_object_array_add(meterValues, meterValue);
  10396. }
  10397. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10398. }
  10399. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10400. {
  10401. json_object *meterValues = json_object_new_array();
  10402. meterValueBufferQuery(gun_index, meterValues);
  10403. if(json_object_array_length(meterValues) > 0)
  10404. {
  10405. DEBUG_INFO("parsed meterValue: %s\n", json_object_to_json_string_ext(meterValues, JSON_C_TO_STRING_PLAIN));
  10406. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10407. }
  10408. }
  10409. random_uuid(guid);
  10410. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  10411. json_object_put(TransactionEvent);
  10412. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  10413. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  10414. {
  10415. result = PASS;
  10416. }
  10417. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  10418. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10419. {
  10420. OCPP_insert_transaction_msg(YES, message);
  10421. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  10422. }
  10423. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10424. {
  10425. OCPP_insert_transaction_msg(NO, message);
  10426. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  10427. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  10428. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  10429. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  10430. }
  10431. return result;
  10432. }
  10433. //==========================================
  10434. // send confirm routine
  10435. //==========================================
  10436. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  10437. {
  10438. mtrace();
  10439. int result = FAIL;
  10440. char message[4096]={0};
  10441. json_object *CancelReservation = json_object_new_object();
  10442. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  10443. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  10444. sprintf(message,"[%d,\"%s\",%s]"
  10445. ,MESSAGE_TYPE_CALLRESULT
  10446. ,uuid
  10447. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  10448. json_object_put(CancelReservation);
  10449. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  10450. LWS_Send(message);
  10451. result = TRUE;
  10452. return result;
  10453. }
  10454. int sendCertificateSignedConfirmation(char *uuid)
  10455. {
  10456. mtrace();
  10457. int result = FAIL;
  10458. char message[4096]={0};
  10459. json_object *CertificateSigned = json_object_new_object();
  10460. json_object *statusInfo = json_object_new_object();
  10461. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  10462. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10463. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10464. {
  10465. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10466. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10467. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10468. }
  10469. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10470. sprintf(message,"[%d,\"%s\",%s]"
  10471. ,MESSAGE_TYPE_CALLRESULT
  10472. ,uuid
  10473. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10474. json_object_put(CertificateSigned);
  10475. LWS_Send(message);
  10476. result = TRUE;
  10477. return result;
  10478. }
  10479. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10480. {
  10481. mtrace();
  10482. int result = FAIL;
  10483. char message[4096]={0};
  10484. json_object *ChangeAvailability = json_object_new_object();
  10485. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10486. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10487. sprintf(message,"[%d,\"%s\",%s]"
  10488. ,MESSAGE_TYPE_CALLRESULT
  10489. ,uuid
  10490. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10491. json_object_put(ChangeAvailability);
  10492. LWS_Send(message);
  10493. result = TRUE;
  10494. return result;
  10495. }
  10496. int sendClearCacheConfirmation(char *uuid)
  10497. {
  10498. mtrace();
  10499. int result = FAIL;
  10500. char message[4096]={0};
  10501. json_object *ClearCache = json_object_new_object();
  10502. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10503. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10504. sprintf(message,"[%d,\"%s\",%s]"
  10505. ,MESSAGE_TYPE_CALLRESULT
  10506. ,uuid
  10507. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10508. json_object_put(ClearCache);
  10509. LWS_Send(message);
  10510. result = TRUE;
  10511. return result;
  10512. }
  10513. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10514. {
  10515. mtrace();
  10516. int result = FAIL;
  10517. char message[500]={0};
  10518. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10519. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10520. LWS_Send(message);
  10521. return result;
  10522. }
  10523. int sendClearDisplayMessageConfirmation(char *uuid)
  10524. {
  10525. mtrace();
  10526. int result = FAIL;
  10527. char message[4096]={0};
  10528. json_object *ClearDisplayMessage = json_object_new_object();
  10529. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10530. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10531. sprintf(message,"[%d,\"%s\",%s]"
  10532. ,MESSAGE_TYPE_CALLRESULT
  10533. ,uuid
  10534. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10535. json_object_put(ClearDisplayMessage);
  10536. LWS_Send(message);
  10537. result = TRUE;
  10538. return result;
  10539. }
  10540. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10541. {
  10542. mtrace();
  10543. int result = FAIL;
  10544. char message[4096]={0};
  10545. json_object *ClearVariableMonitoring = json_object_new_object();
  10546. json_object *clearMonitoringResults = json_object_new_array();
  10547. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10548. for(int idx=0;idx<variableQuantity;idx++)
  10549. {
  10550. json_object *clearMonitoringResult = json_object_new_object();
  10551. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10552. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10553. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10554. }
  10555. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10556. sprintf(message,"[%d,\"%s\",%s]"
  10557. ,MESSAGE_TYPE_CALLRESULT
  10558. ,uuid
  10559. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10560. json_object_put(ClearVariableMonitoring);
  10561. LWS_Send(message);
  10562. result = TRUE;
  10563. return result;
  10564. }
  10565. int sendCostUpdatedConfirmation(char *uuid)
  10566. {
  10567. mtrace();
  10568. int result = FAIL;
  10569. char message[4096]={0};
  10570. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10571. sprintf(message,"[%d,\"%s\",{}]"
  10572. ,MESSAGE_TYPE_CALLRESULT
  10573. ,uuid);
  10574. LWS_Send(message);
  10575. result = TRUE;
  10576. return result;
  10577. }
  10578. int sendCustomerInformationConfirmation(char *uuid)
  10579. {
  10580. mtrace();
  10581. int result = FAIL;
  10582. char message[4096]={0};
  10583. json_object *CustomerInformation = json_object_new_object();
  10584. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10585. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10586. sprintf(message,"[%d,\"%s\",%s]"
  10587. ,MESSAGE_TYPE_CALLRESULT
  10588. ,uuid
  10589. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10590. json_object_put(CustomerInformation);
  10591. LWS_Send(message);
  10592. result = TRUE;
  10593. return result;
  10594. }
  10595. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10596. {
  10597. mtrace();
  10598. int result = FAIL;
  10599. char message[4096]={0};
  10600. json_object *DataTransfer = json_object_new_object();
  10601. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10602. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10603. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10604. sprintf(message,"[%d,\"%s\",%s]"
  10605. ,MESSAGE_TYPE_CALLRESULT
  10606. ,uuid
  10607. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10608. json_object_put(DataTransfer);
  10609. LWS_Send(message);
  10610. result = TRUE;
  10611. return result;
  10612. }
  10613. int sendDeleteCertificateConfirmation(char *uuid)
  10614. {
  10615. mtrace();
  10616. int result = FAIL;
  10617. char message[4096]={0};
  10618. json_object *DeleteCertificate = json_object_new_object();
  10619. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10620. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10621. sprintf(message,"[%d,\"%s\",%s]"
  10622. ,MESSAGE_TYPE_CALLRESULT
  10623. ,uuid
  10624. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10625. json_object_put(DeleteCertificate);
  10626. LWS_Send(message);
  10627. result = TRUE;
  10628. return result;
  10629. }
  10630. int sendGetBaseReportConfirmation(char *uuid)
  10631. {
  10632. mtrace();
  10633. int result = FAIL;
  10634. char message[4096]={0};
  10635. json_object *GetBaseReport = json_object_new_object();
  10636. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10637. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10638. sprintf(message,"[%d,\"%s\",%s]"
  10639. ,MESSAGE_TYPE_CALLRESULT
  10640. ,uuid
  10641. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10642. json_object_put(GetBaseReport);
  10643. LWS_Send(message);
  10644. result = TRUE;
  10645. return result;
  10646. }
  10647. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10648. {
  10649. mtrace();
  10650. int result = FAIL;
  10651. char message[4096]={0};
  10652. json_object *GetChargingProfiles = json_object_new_object();
  10653. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10654. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10655. sprintf(message,"[%d,\"%s\",%s]"
  10656. ,MESSAGE_TYPE_CALLRESULT
  10657. ,uuid
  10658. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10659. json_object_put(GetChargingProfiles);
  10660. LWS_Send(message);
  10661. result = TRUE;
  10662. return result;
  10663. }
  10664. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int evseIdInt, int nPeriod)
  10665. {
  10666. mtrace();
  10667. int result = FAIL;
  10668. char message[4096]={0};
  10669. int CompositeScheduleIndex = 0;
  10670. json_object *GetCompositeSchedule = json_object_new_object();
  10671. json_object *schedule = json_object_new_object();
  10672. json_object *chargingSchedule = json_object_new_object();
  10673. json_object *chargingSchedulePeriod = json_object_new_array();
  10674. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10675. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10676. CompositeScheduleIndex = (evseIdInt > 0) ?(evseIdInt -1) : 0;
  10677. json_object_object_add(schedule, "evseId", json_object_new_int(evseIdInt));
  10678. if(nPeriod == 0)
  10679. {
  10680. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10681. {
  10682. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10683. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10684. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10685. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10686. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10687. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10688. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10689. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10690. uint8_t isNullSchedulePeriod = TRUE;
  10691. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10692. {
  10693. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10694. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10695. {
  10696. json_object *Period = json_object_new_object();
  10697. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10698. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10699. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10700. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10701. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10702. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10703. json_object_array_add(chargingSchedulePeriod, Period);
  10704. isNullSchedulePeriod = FALSE;
  10705. }
  10706. }
  10707. if(isNullSchedulePeriod == TRUE)
  10708. {
  10709. json_object *Period = json_object_new_object();
  10710. json_object_object_add(Period, "startPeriod", json_object_new_int(0));
  10711. float limit = ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  10712. json_object_object_add(Period, "limit", json_object_new_double(limit));
  10713. json_object_array_add(chargingSchedulePeriod, Period);
  10714. }
  10715. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10716. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10717. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10718. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10719. }
  10720. }
  10721. else
  10722. {
  10723. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10724. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10725. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10726. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10727. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10728. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10729. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10730. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10731. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10732. {
  10733. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10734. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10735. {
  10736. json_object *Period = json_object_new_object();
  10737. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10738. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10739. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10740. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10741. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10742. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10743. json_object_array_add(chargingSchedulePeriod, Period);
  10744. }
  10745. }
  10746. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10747. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10748. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10749. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10750. }
  10751. sprintf(message,"[%d,\"%s\",%s]"
  10752. ,MESSAGE_TYPE_CALLRESULT
  10753. ,uuid
  10754. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10755. json_object_put(GetCompositeSchedule);
  10756. LWS_Send(message);
  10757. result = TRUE;
  10758. return result;
  10759. }
  10760. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10761. {
  10762. mtrace();
  10763. int result = FAIL;
  10764. char message[4096]={0};
  10765. json_object *GetGetDisplayMessages = json_object_new_object();
  10766. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10767. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10768. sprintf(message,"[%d,\"%s\",%s]"
  10769. ,MESSAGE_TYPE_CALLRESULT
  10770. ,uuid
  10771. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10772. json_object_put(GetGetDisplayMessages);
  10773. LWS_Send(message);
  10774. result = TRUE;
  10775. return result;
  10776. }
  10777. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10778. {
  10779. mtrace();
  10780. int result = FAIL;
  10781. char message[4096]={0};
  10782. json_object *GetInstalledCertificateIds = json_object_new_object();
  10783. json_object *certificateHashDataChains = json_object_new_array();
  10784. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10785. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10786. for(int idx=0;idx<certQuantity;idx++)
  10787. {
  10788. json_object *cert = json_object_new_object();
  10789. json_object *certificateHashData = json_object_new_object();
  10790. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10791. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10792. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10793. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10794. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10795. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10796. json_object_array_add(certificateHashDataChains, cert);
  10797. }
  10798. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10799. sprintf(message,"[%d,\"%s\",%s]"
  10800. ,MESSAGE_TYPE_CALLRESULT
  10801. ,uuid
  10802. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10803. json_object_put(GetInstalledCertificateIds);
  10804. LWS_Send(message);
  10805. result = TRUE;
  10806. return result;
  10807. }
  10808. int sendGetLocalListVersionConfirmation(char *uuid)
  10809. {
  10810. mtrace();
  10811. int result = FAIL;
  10812. char message[4096]={0};
  10813. json_object *GetLocalListVersion = json_object_new_object();
  10814. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10815. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10816. sprintf(message,"[%d,\"%s\",%s]"
  10817. ,MESSAGE_TYPE_CALLRESULT
  10818. ,uuid
  10819. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10820. json_object_put(GetLocalListVersion);
  10821. LWS_Send(message);
  10822. result = TRUE;
  10823. return result;
  10824. }
  10825. int sendGetLogConfirmation(char *uuid)
  10826. {
  10827. mtrace();
  10828. int result = FAIL;
  10829. char message[4096]={0};
  10830. json_object *GetLog = json_object_new_object();
  10831. DEBUG_INFO("sendGetLogConfirmation...\n");
  10832. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10833. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10834. sprintf(message,"[%d,\"%s\",%s]"
  10835. ,MESSAGE_TYPE_CALLRESULT
  10836. ,uuid
  10837. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10838. json_object_put(GetLog);
  10839. LWS_Send(message);
  10840. result = TRUE;
  10841. return result;
  10842. }
  10843. int sendGetMonitoringReportConfirmation(char *uuid)
  10844. {
  10845. mtrace();
  10846. int result = FAIL;
  10847. char message[4096]={0};
  10848. json_object *GetMonitoringReport = json_object_new_object();
  10849. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10850. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10851. sprintf(message,"[%d,\"%s\",%s]"
  10852. ,MESSAGE_TYPE_CALLRESULT
  10853. ,uuid
  10854. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10855. json_object_put(GetMonitoringReport);
  10856. LWS_Send(message);
  10857. result = TRUE;
  10858. return result;
  10859. }
  10860. int sendGetReportConfirmation(char *uuid)
  10861. {
  10862. mtrace();
  10863. int result = FAIL;
  10864. char message[4096]={0};
  10865. json_object *GetReport = json_object_new_object();
  10866. DEBUG_INFO("sendGetReportConfirmation...\n");
  10867. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10868. sprintf(message,"[%d,\"%s\",%s]"
  10869. ,MESSAGE_TYPE_CALLRESULT
  10870. ,uuid
  10871. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10872. json_object_put(GetReport);
  10873. LWS_Send(message);
  10874. result = TRUE;
  10875. return result;
  10876. }
  10877. int sendGetTransactionStatusConfirmation(char *uuid)
  10878. {
  10879. mtrace();
  10880. int result = FAIL;
  10881. char message[4096]={0};
  10882. json_object *GetTransactionStatus = json_object_new_object();
  10883. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10884. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator));
  10885. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue));
  10886. sprintf(message,"[%d,\"%s\",%s]"
  10887. ,MESSAGE_TYPE_CALLRESULT
  10888. ,uuid
  10889. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10890. json_object_put(GetTransactionStatus);
  10891. LWS_Send(message);
  10892. result = TRUE;
  10893. return result;
  10894. }
  10895. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10896. {
  10897. mtrace();
  10898. int result = FAIL;
  10899. char message[4096]={0};
  10900. json_object *GetVariables = json_object_new_object();
  10901. json_object *getVariableResults = json_object_new_array();
  10902. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10903. for(int idx=0;idx<variableQuantity;idx++)
  10904. {
  10905. json_object *variableResult = json_object_new_object();
  10906. json_object *component = json_object_new_object();
  10907. json_object *variable = json_object_new_object();
  10908. json_object *evse = json_object_new_object();
  10909. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10910. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10911. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10912. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10913. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10914. if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id > 0)
  10915. {
  10916. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10917. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10918. json_object_object_add(component, "evse", evse);
  10919. }
  10920. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10921. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10922. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10923. json_object_object_add(variableResult, "component", component);
  10924. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10925. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10926. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10927. json_object_object_add(variableResult, "variable", variable);
  10928. json_object_array_add(getVariableResults, variableResult);
  10929. }
  10930. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10931. sprintf(message,"[%d,\"%s\",%s]"
  10932. ,MESSAGE_TYPE_CALLRESULT
  10933. ,uuid
  10934. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10935. json_object_put(GetVariables);
  10936. LWS_Send(message);
  10937. result = TRUE;
  10938. return result;
  10939. }
  10940. int sendInstallCertificateConfirmation(char *uuid)
  10941. {
  10942. mtrace();
  10943. int result = FAIL;
  10944. char message[4096]={0};
  10945. json_object *InstallCertificate = json_object_new_object();
  10946. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10947. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10948. sprintf(message,"[%d,\"%s\",%s]"
  10949. ,MESSAGE_TYPE_CALLRESULT
  10950. ,uuid
  10951. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  10952. json_object_put(InstallCertificate);
  10953. LWS_Send(message);
  10954. result = TRUE;
  10955. return result;
  10956. }
  10957. int sendPublishFirmwareConfirmation(char *uuid)
  10958. {
  10959. mtrace();
  10960. int result = FAIL;
  10961. char message[4096]={0};
  10962. json_object *PublishFirmware = json_object_new_object();
  10963. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  10964. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  10965. sprintf(message,"[%d,\"%s\",%s]"
  10966. ,MESSAGE_TYPE_CALLRESULT
  10967. ,uuid
  10968. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  10969. json_object_put(PublishFirmware);
  10970. LWS_Send(message);
  10971. result = TRUE;
  10972. return result;
  10973. }
  10974. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  10975. {
  10976. mtrace();
  10977. int result = FAIL;
  10978. char message[4096]={0};
  10979. json_object *RemoteStartTransaction = json_object_new_object();
  10980. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  10981. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  10982. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  10983. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  10984. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  10985. sprintf(message,"[%d,\"%s\",%s]"
  10986. ,MESSAGE_TYPE_CALLRESULT
  10987. ,uuid
  10988. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  10989. json_object_put(RemoteStartTransaction);
  10990. LWS_Send(message);
  10991. result = TRUE;
  10992. return result;
  10993. }
  10994. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  10995. {
  10996. mtrace();
  10997. int result = FAIL;
  10998. char message[4096]={0};
  10999. json_object *RemoteStopTransaction = json_object_new_object();
  11000. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  11001. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  11002. sprintf(message,"[%d,\"%s\",%s]"
  11003. ,MESSAGE_TYPE_CALLRESULT
  11004. ,uuid
  11005. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  11006. json_object_put(RemoteStopTransaction);
  11007. LWS_Send(message);
  11008. result = TRUE;
  11009. return result;
  11010. }
  11011. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  11012. {
  11013. mtrace();
  11014. int result = FAIL;
  11015. char message[4096]={0};
  11016. json_object *ReserveNow = json_object_new_object();
  11017. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  11018. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  11019. sprintf(message,"[%d,\"%s\",%s]"
  11020. ,MESSAGE_TYPE_CALLRESULT
  11021. ,uuid
  11022. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  11023. json_object_put(ReserveNow);
  11024. LWS_Send(message);
  11025. result = TRUE;
  11026. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  11027. return result;
  11028. }
  11029. int sendResetConfirmation(char *uuid)
  11030. {
  11031. mtrace();
  11032. int result = FAIL;
  11033. char message[4096]={0};
  11034. json_object *Reset = json_object_new_object();
  11035. DEBUG_INFO("sendResetConfirmation...\n");
  11036. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  11037. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  11038. sprintf(message,"[%d,\"%s\",%s]"
  11039. ,MESSAGE_TYPE_CALLRESULT
  11040. ,uuid
  11041. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  11042. json_object_put(Reset);
  11043. LWS_Send(message);
  11044. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  11045. {
  11046. DB_updateBootType(BootReasonEnumType_RemoteReset);
  11047. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  11048. }
  11049. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  11050. {
  11051. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  11052. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  11053. }
  11054. result = TRUE;
  11055. return result;
  11056. }
  11057. int sendSendLocalListConfirmation(char *uuid)
  11058. {
  11059. mtrace();
  11060. int result = FAIL;
  11061. char message[4096]={0};
  11062. json_object *SendLocalList = json_object_new_object();
  11063. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  11064. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  11065. sprintf(message,"[%d,\"%s\",%s]"
  11066. ,MESSAGE_TYPE_CALLRESULT
  11067. ,uuid
  11068. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  11069. json_object_put(SendLocalList);
  11070. LWS_Send(message);
  11071. result = TRUE;
  11072. return result;
  11073. }
  11074. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  11075. {
  11076. mtrace();
  11077. int result = FAIL;
  11078. char message[4096]={0};
  11079. json_object *SetChargingProfile = json_object_new_object();
  11080. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  11081. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  11082. sprintf(message,"[%d,\"%s\",%s]"
  11083. ,MESSAGE_TYPE_CALLRESULT
  11084. ,uuid
  11085. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11086. json_object_put(SetChargingProfile);
  11087. LWS_Send(message);
  11088. result = TRUE;
  11089. return result;
  11090. }
  11091. int sendSetDisplayMessagesConfirmation(char *uuid)
  11092. {
  11093. mtrace();
  11094. int result = FAIL;
  11095. char message[4096]={0};
  11096. json_object *SetDisplayMessage = json_object_new_object();
  11097. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  11098. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  11099. sprintf(message,"[%d,\"%s\",%s]"
  11100. ,MESSAGE_TYPE_CALLRESULT
  11101. ,uuid
  11102. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  11103. json_object_put(SetDisplayMessage);
  11104. LWS_Send(message);
  11105. result = TRUE;
  11106. return result;
  11107. }
  11108. int sendSetMonitoringBaseConfirmation(char *uuid)
  11109. {
  11110. mtrace();
  11111. int result = FAIL;
  11112. char message[4096]={0};
  11113. json_object *SetMonitoringBase = json_object_new_object();
  11114. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  11115. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  11116. sprintf(message,"[%d,\"%s\",%s]"
  11117. ,MESSAGE_TYPE_CALLRESULT
  11118. ,uuid
  11119. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  11120. json_object_put(SetMonitoringBase);
  11121. LWS_Send(message);
  11122. result = TRUE;
  11123. return result;
  11124. }
  11125. int sendSetMonitoringLevelConfirmation(char *uuid)
  11126. {
  11127. mtrace();
  11128. int result = FAIL;
  11129. char message[4096]={0};
  11130. json_object *SetMonitoringLevel = json_object_new_object();
  11131. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  11132. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  11133. sprintf(message,"[%d,\"%s\",%s]"
  11134. ,MESSAGE_TYPE_CALLRESULT
  11135. ,uuid
  11136. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  11137. json_object_put(SetMonitoringLevel);
  11138. LWS_Send(message);
  11139. result = TRUE;
  11140. return result;
  11141. }
  11142. int sendSetNetworkProfileConfirmation(char *uuid)
  11143. {
  11144. mtrace();
  11145. int result = FAIL;
  11146. char message[4096]={0};
  11147. json_object *SetNetworkProfile = json_object_new_object();
  11148. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  11149. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  11150. sprintf(message,"[%d,\"%s\",%s]"
  11151. ,MESSAGE_TYPE_CALLRESULT
  11152. ,uuid
  11153. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  11154. json_object_put(SetNetworkProfile);
  11155. LWS_Send(message);
  11156. result = TRUE;
  11157. return result;
  11158. }
  11159. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  11160. {
  11161. mtrace();
  11162. int result = FAIL;
  11163. char message[4096]={0};
  11164. json_object *SetVariableMonitoring = json_object_new_object();
  11165. json_object *setMonitoringResults = json_object_new_array();
  11166. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  11167. for(int idx=0;idx<variableQuantity;idx++)
  11168. {
  11169. json_object *variableMonitorResult = json_object_new_object();
  11170. json_object *component = json_object_new_object();
  11171. json_object *variable = json_object_new_object();
  11172. json_object *evse = json_object_new_object();
  11173. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  11174. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  11175. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  11176. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  11177. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  11178. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  11179. json_object_object_add(component, "evse", evse);
  11180. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  11181. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  11182. json_object_object_add(variableMonitorResult, "component", component);
  11183. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  11184. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  11185. json_object_object_add(variableMonitorResult, "variable", variable);
  11186. json_object_array_add(setMonitoringResults, variableMonitorResult);
  11187. }
  11188. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  11189. sprintf(message,"[%d,\"%s\",%s]"
  11190. ,MESSAGE_TYPE_CALLRESULT
  11191. ,uuid
  11192. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  11193. json_object_put(SetVariableMonitoring);
  11194. LWS_Send(message);
  11195. result = TRUE;
  11196. return result;
  11197. }
  11198. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  11199. {
  11200. mtrace();
  11201. int result = FAIL;
  11202. char message[4096]={0};
  11203. json_object *SetVariable = json_object_new_object();
  11204. json_object *setVariableResults = json_object_new_array();
  11205. DEBUG_INFO("sendSetVariableConfirmation...\n");
  11206. for(int idx=0;idx<variableQuantity;idx++)
  11207. {
  11208. json_object *variableResult = json_object_new_object();
  11209. json_object *component = json_object_new_object();
  11210. json_object *variable = json_object_new_object();
  11211. json_object *evse = json_object_new_object();
  11212. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  11213. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  11214. if(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id > 0)
  11215. {
  11216. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  11217. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  11218. json_object_object_add(component, "evse", evse);
  11219. }
  11220. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  11221. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance) > 0)
  11222. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  11223. json_object_object_add(variableResult, "component", component);
  11224. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  11225. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance)>0)
  11226. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  11227. json_object_object_add(variableResult, "variable", variable);
  11228. json_object_array_add(setVariableResults, variableResult);
  11229. }
  11230. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  11231. sprintf(message,"[%d,\"%s\",%s]"
  11232. ,MESSAGE_TYPE_CALLRESULT
  11233. ,uuid
  11234. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  11235. json_object_put(SetVariable);
  11236. LWS_Send(message);
  11237. result = TRUE;
  11238. return result;
  11239. }
  11240. int sendTriggerMessageConfirmation(char *uuid)
  11241. {
  11242. mtrace();
  11243. int result = FAIL;
  11244. char message[4096]={0};
  11245. json_object *TriggerMessage = json_object_new_object();
  11246. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  11247. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  11248. sprintf(message,"[%d,\"%s\",%s]",
  11249. MESSAGE_TYPE_CALLRESULT,
  11250. uuid,
  11251. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  11252. json_object_put(TriggerMessage);
  11253. LWS_Send(message);
  11254. result = TRUE;
  11255. return result;
  11256. }
  11257. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  11258. {
  11259. mtrace();
  11260. int result = FAIL;
  11261. char message[4096]={0};
  11262. json_object *UnlockConnector = json_object_new_object();
  11263. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  11264. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  11265. sprintf(message,"[%d,\"%s\",%s]",
  11266. MESSAGE_TYPE_CALLRESULT,
  11267. uuid,
  11268. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  11269. json_object_put(UnlockConnector);
  11270. LWS_Send(message);
  11271. result = TRUE;
  11272. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  11273. return result;
  11274. }
  11275. int sendUnpublishFirmwareConfirmation(char *uuid)
  11276. {
  11277. mtrace();
  11278. int result = FAIL;
  11279. char message[4096]={0};
  11280. json_object *UnpublishFirmware = json_object_new_object();
  11281. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  11282. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  11283. sprintf(message,"[%d,\"%s\",%s]"
  11284. ,MESSAGE_TYPE_CALLRESULT
  11285. ,uuid
  11286. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  11287. json_object_put(UnpublishFirmware);
  11288. LWS_Send(message);
  11289. result = TRUE;
  11290. return result;
  11291. }
  11292. int sendUpdateFirmwareConfirmation(char *uuid)
  11293. {
  11294. mtrace();
  11295. int result = FAIL;
  11296. char message[4096]={0};
  11297. json_object *UpdateFirmware = json_object_new_object();
  11298. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  11299. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  11300. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  11301. sprintf(message,"[%d,\"%s\",%s]"
  11302. ,MESSAGE_TYPE_CALLRESULT
  11303. ,uuid
  11304. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  11305. json_object_put(UpdateFirmware);
  11306. LWS_Send(message);
  11307. result = TRUE;
  11308. return result;
  11309. }
  11310. int sendUnknownConfirmation(char *uuid)
  11311. {
  11312. mtrace();
  11313. int result = FAIL;
  11314. char message[256]={0};
  11315. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  11316. DEBUG_INFO("sendUnknownConfirmation...\n");
  11317. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  11318. LWS_Send(message);
  11319. result = TRUE;
  11320. return result;
  11321. }
  11322. //==========================================
  11323. // send CallError routine
  11324. //==========================================
  11325. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  11326. {
  11327. mtrace();
  11328. char message[220]={0};
  11329. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  11330. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  11331. LWS_Send(message);
  11332. }
  11333. //==========================================
  11334. // Handle server request routine Start
  11335. //==========================================
  11336. int handleCancelReservationRequest(char *uuid, char *payload)
  11337. {
  11338. mtrace();
  11339. int result = FAIL;
  11340. int gunNO = 0;
  11341. int reservationIdInt = -1;
  11342. DEBUG_INFO("handleCancelReservationRequest...\n");
  11343. json_object *CancelReservation;
  11344. CancelReservation = json_tokener_parse(payload);
  11345. if(!is_error(CancelReservation))
  11346. {
  11347. // Required data
  11348. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  11349. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  11350. }
  11351. json_object_put(CancelReservation);
  11352. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  11353. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  11354. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  11355. if(reservationIdInt != -1)
  11356. {
  11357. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11358. //check Transaction active
  11359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  11360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11361. {
  11362. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  11363. {
  11364. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11365. if(gunType[2] == GUN_TYPE_CHAdeMO)
  11366. {
  11367. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  11368. }
  11369. else
  11370. {
  11371. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  11372. }
  11373. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11374. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11375. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11376. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11377. goto end;
  11378. }
  11379. }
  11380. for (int index = 0; index < CCS_QUANTITY; index++)
  11381. {
  11382. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  11383. {
  11384. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11385. if(gunType[2] == GUN_TYPE_CCS)
  11386. {
  11387. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  11388. }
  11389. else
  11390. {
  11391. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  11392. }
  11393. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11394. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11395. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11396. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11397. goto end;
  11398. }
  11399. }
  11400. for (int index = 0; index < GB_QUANTITY; index++)
  11401. {
  11402. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  11403. {
  11404. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11405. if(gunType[2] == GUN_TYPE_GBT)
  11406. {
  11407. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  11408. }
  11409. else
  11410. {
  11411. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11412. }
  11413. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11414. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11415. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11416. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11417. goto end;
  11418. }
  11419. }
  11420. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11421. {
  11422. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  11423. {
  11424. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11425. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11426. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11427. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11428. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11429. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11430. goto end;
  11431. }
  11432. }
  11433. for (int index = 0; index < AC_QUANTITY; index++)
  11434. {
  11435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  11436. {
  11437. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11439. {
  11440. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  11441. }
  11442. else
  11443. {
  11444. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  11445. }
  11446. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11447. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11448. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11449. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11450. goto end;
  11451. }
  11452. }
  11453. }
  11454. //The reservationId does NOT match the reservationId
  11455. sendCancelReservationConfirmation(uuid, gunNO);
  11456. end:
  11457. // Fill in ocpp packet uuid
  11458. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  11459. return result;
  11460. }
  11461. int handleCertificateSignedRequest(char *uuid, char *payload)
  11462. {
  11463. mtrace();
  11464. int result = FAIL;
  11465. json_object *CertificateSigned;
  11466. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11467. CertificateSigned = json_tokener_parse(payload);
  11468. if(!is_error(CertificateSigned))
  11469. {
  11470. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  11471. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  11472. // Required data
  11473. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  11474. // Optional data
  11475. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  11476. {
  11477. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  11478. }
  11479. else
  11480. {
  11481. if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11482. {
  11483. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]);
  11484. }
  11485. else if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11486. {
  11487. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]);
  11488. }
  11489. }
  11490. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11491. {
  11492. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  11493. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11494. fclose(fp);
  11495. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11496. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11497. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  11498. {
  11499. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11500. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  11501. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  11502. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  11503. }
  11504. else
  11505. {
  11506. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11507. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11508. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11509. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11510. }
  11511. }
  11512. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11513. {
  11514. FILE *fp = fopen("/Storage/OCPP/tempV2G.pem", "w");
  11515. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11516. fclose(fp);
  11517. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11518. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11519. if(certVerify(PRIVATE_KEY_V2G, "/Storage/OCPP/tempV2G.pem") == PASS)
  11520. {
  11521. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11522. system("rm -f /Storage/OCPP/certV2G_fallback.pem");
  11523. rename(CERTIFICATE_V2G, "/Storage/OCPP/certV2G_fallback.pem");
  11524. rename("/Storage/OCPP/tempV2G.pem", CERTIFICATE_V2G);
  11525. }
  11526. else
  11527. {
  11528. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11529. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11530. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11531. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11532. }
  11533. }
  11534. else
  11535. {
  11536. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11537. }
  11538. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11539. }
  11540. else
  11541. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11542. json_object_put(CertificateSigned);
  11543. sendCertificateSignedConfirmation(uuid);
  11544. return result;
  11545. }
  11546. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11547. {
  11548. mtrace();
  11549. int result = FAIL;
  11550. int evseId = 0, gunIndex = 0;
  11551. char operationalStatus[16]={0};
  11552. char comfirmstr[20];
  11553. //int specificId = FALSE;
  11554. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11555. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11556. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11557. json_object *ChangeAvailability;
  11558. ChangeAvailability = json_tokener_parse(payload);
  11559. if(!is_error(ChangeAvailability))
  11560. {
  11561. // Required data
  11562. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11563. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11564. // Requested evse. (When omitted, the message refers to the Charging Station as a whole.)
  11565. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11566. {
  11567. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id") != NULL)
  11568. {
  11569. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11570. if(evseId > 0){}
  11571. //specificId = TRUE;
  11572. else
  11573. goto end;
  11574. }
  11575. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11576. {
  11577. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11578. if(gunIndex != 1)
  11579. goto end;
  11580. }
  11581. }
  11582. }
  11583. json_object_put(ChangeAvailability);
  11584. if((evseId != 0) && (evseId <= gunTotalNumber))
  11585. {
  11586. ShmOCPP20Data->ChangeAvailability[evseId-1].evse.id = evseId;
  11587. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11588. }
  11589. else if(evseId == 0)
  11590. {
  11591. for(int i=0; i < gunTotalNumber; i++)
  11592. {
  11593. ShmOCPP20Data->ChangeAvailability[i].evse.id = i+1;
  11594. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11595. }
  11596. }
  11597. /*if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11598. {
  11599. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = 1;
  11600. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11601. }
  11602. else if(gunIndex == 0)
  11603. {
  11604. for(int i=0; i < gunTotalNumber; i++)
  11605. {
  11606. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = 1;
  11607. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11608. }
  11609. }*/
  11610. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11611. {
  11612. //----------------------evseId is 0 ------------------------------------------------//
  11613. if(evseId == 0)
  11614. {
  11615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11616. {
  11617. for(int i=0; i < gunTotalNumber; i++)
  11618. {
  11619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11620. {
  11621. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11622. {
  11623. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11624. {
  11625. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11626. goto end;
  11627. }
  11628. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11629. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11631. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11632. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11633. {
  11634. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11635. goto end;
  11636. }
  11637. }
  11638. }//END FOR CHAdeMO_QUANTITY
  11639. for (int index = 0; index < CCS_QUANTITY; index++)
  11640. {
  11641. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11642. {
  11643. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11644. {
  11645. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11646. goto end;
  11647. }
  11648. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11649. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11650. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11651. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11652. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11653. {
  11654. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11655. goto end;
  11656. }
  11657. }
  11658. }//END FOR CCS_QUANTITY
  11659. for (int index = 0; index < GB_QUANTITY; index++)
  11660. {
  11661. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11662. {
  11663. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11664. {
  11665. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11666. goto end;
  11667. }
  11668. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11669. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11670. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11671. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11672. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11673. {
  11674. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11675. goto end;
  11676. }
  11677. }
  11678. }// END FOR GB_QUANTITY
  11679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11680. {
  11681. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11682. {
  11683. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11684. {
  11685. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11686. goto end;
  11687. }
  11688. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11689. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11690. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11691. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11692. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11693. {
  11694. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11695. goto end;
  11696. }
  11697. }
  11698. }// END FOR DO_QUANTITY
  11699. for (int index = 0; index < AC_QUANTITY; index++)
  11700. {
  11701. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11702. {
  11703. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11704. {
  11705. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11706. goto end;
  11707. }
  11708. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11709. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11710. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11711. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11712. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11713. {
  11714. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11715. goto end;
  11716. }
  11717. }
  11718. }//END FOR AC_QUANTITY
  11719. }// END FOR gunTotalNumber
  11720. }
  11721. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11722. {
  11723. for(int i=0; i < gunTotalNumber; i++)
  11724. {
  11725. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11726. {
  11727. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11728. goto end;
  11729. }
  11730. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11731. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11732. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11733. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11734. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11735. {
  11736. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11737. goto end;
  11738. }
  11739. }
  11740. }
  11741. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11742. goto end;
  11743. }
  11744. //----------------------gunIndex is not 0 ------------------------------------------------//
  11745. //check Transaction active
  11746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11747. {
  11748. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO))
  11749. {
  11750. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11751. {
  11752. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11753. goto end;
  11754. }
  11755. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11756. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11757. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11758. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11759. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11760. {
  11761. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11762. goto end;
  11763. }
  11764. else
  11765. {
  11766. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11767. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11768. goto end;
  11769. }
  11770. }
  11771. }//END FOR CHAdeMO_QUANTITY
  11772. for (int index = 0; index < CCS_QUANTITY; index++)
  11773. {
  11774. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS))
  11775. {
  11776. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11777. {
  11778. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11779. goto end;
  11780. }
  11781. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11782. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11783. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11784. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11785. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11786. {
  11787. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11788. goto end;
  11789. }
  11790. else
  11791. {
  11792. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11793. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11794. goto end;
  11795. }
  11796. }
  11797. }//END FOR CCS_QUANTITY
  11798. for (int index = 0; index < GB_QUANTITY; index++)
  11799. {
  11800. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))
  11801. {
  11802. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11803. {
  11804. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11805. goto end;
  11806. }
  11807. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11808. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11809. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11810. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11811. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11812. {
  11813. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11814. goto end;
  11815. }
  11816. else
  11817. {
  11818. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11819. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11820. goto end;
  11821. }
  11822. }
  11823. }// END FOR GB_QUANTITY
  11824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11825. {
  11826. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))
  11827. {
  11828. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11829. {
  11830. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11831. goto end;
  11832. }
  11833. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11834. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11835. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11836. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11837. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11838. {
  11839. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11840. goto end;
  11841. }
  11842. else
  11843. {
  11844. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11845. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11846. goto end;
  11847. }
  11848. }
  11849. }// END FOR DO_QUANTITY
  11850. for (int index = 0; index < AC_QUANTITY; index++)
  11851. {
  11852. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC))
  11853. {
  11854. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11855. {
  11856. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11857. goto end;
  11858. }
  11859. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11860. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11861. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11862. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11863. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11864. {
  11865. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11866. goto end;
  11867. }
  11868. else
  11869. {
  11870. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11871. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11872. goto end;
  11873. }
  11874. }
  11875. }//END FOR AC_QUANTITY
  11876. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11877. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11878. {
  11879. //----------------------gunIndex is 0 ------------------------------------------------//
  11880. if(evseId == 0)
  11881. {
  11882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11883. {
  11884. for(int i=0; i < gunTotalNumber; i++)
  11885. {
  11886. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11887. {
  11888. 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
  11889. {
  11890. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11891. goto end;
  11892. }
  11893. }//END FOR CHAdeMO_QUANTITY
  11894. for (int index = 0; index < CCS_QUANTITY; index++)
  11895. {
  11896. 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
  11897. {
  11898. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11899. goto end;
  11900. }
  11901. }//END FOR CCS_QUANTITY
  11902. for (int index = 0; index < GB_QUANTITY; index++)
  11903. {
  11904. 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
  11905. {
  11906. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11907. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11908. goto end;
  11909. }
  11910. }// END FOR GB_QUANTITY
  11911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11912. {
  11913. 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
  11914. {
  11915. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11916. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11917. goto end;
  11918. }
  11919. }// END FOR DO_QUANTITY
  11920. for (int index = 0; index < AC_QUANTITY; index++)
  11921. {
  11922. 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
  11923. {
  11924. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11925. goto end;
  11926. }
  11927. }//END FOR CHAdeMO_QUANTITY
  11928. }// END FOR gunTotalNumber
  11929. }
  11930. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11931. {
  11932. for(int i=0; i < gunTotalNumber; i++)
  11933. {
  11934. for (int index = 0; index < AC_QUANTITY; index++)
  11935. {
  11936. 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
  11937. {
  11938. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11939. goto end;
  11940. }
  11941. }//END FOR CHAdeMO_QUANTITY
  11942. } // END FOR gunTotalNumber
  11943. }
  11944. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11945. goto end;
  11946. }
  11947. //----------------------gunIndex is not 0 ------------------------------------------------//
  11948. //check Transaction active
  11949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11950. {
  11951. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11952. {
  11953. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11954. goto end;
  11955. }
  11956. }//END FOR CHAdeMO_QUANTITY
  11957. for (int index = 0; index < CCS_QUANTITY; index++)
  11958. {
  11959. if ((((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11960. {
  11961. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11962. goto end;
  11963. }
  11964. }//END FOR CCS_QUANTITY
  11965. for (int index = 0; index < GB_QUANTITY; index++)
  11966. {
  11967. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11968. {
  11969. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11970. goto end;
  11971. }
  11972. }// END FOR GB_QUANTITY
  11973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11974. {
  11975. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11976. {
  11977. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11978. goto end;
  11979. }
  11980. }// END FOR DO_QUANTITY
  11981. for (int index = 0; index < AC_QUANTITY; index++)
  11982. {
  11983. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11984. {
  11985. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11986. goto end;
  11987. }
  11988. }//END FOR AC_QUANTITY
  11989. }//END FOR AvailabilityEnumTypeStr[Operative]
  11990. end:
  11991. if((evseId > 0) && (evseId <= gunTotalNumber))
  11992. {
  11993. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].Response_status, "%s", comfirmstr );
  11994. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11995. ShmOCPP20Data->CsMsg.bits[evseId-1].ChangeAvailabilityReq = ON;
  11996. }
  11997. else if(evseId == 0)
  11998. {
  11999. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  12000. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  12001. {
  12002. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  12003. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  12004. }
  12005. }
  12006. else
  12007. {
  12008. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  12009. }
  12010. sendChangeAvailabilityConfirmation(uuid, (evseId==0?evseId:evseId-1));
  12011. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12012. return result;
  12013. }
  12014. int handleClearCacheRequest(char *uuid, char *payload)
  12015. {
  12016. mtrace();
  12017. int result = FAIL;
  12018. char rmFileCmd[100]={0};
  12019. struct stat stats;
  12020. DEBUG_INFO("handleClearCacheRequest...\n");
  12021. stat("/Storage/OCPP", &stats);
  12022. // Check for directory existence
  12023. if (S_ISDIR(stats.st_mode) == 1)
  12024. {}
  12025. else
  12026. {
  12027. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  12028. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  12029. system(rmFileCmd);
  12030. }
  12031. if(DB_cleanLocalCache() != PASS)
  12032. {
  12033. DEBUG_INFO("open AuthorizationCache file failed\n");
  12034. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  12035. }
  12036. else
  12037. {
  12038. DEBUG_INFO("open AuthorizationCache file successful\n");
  12039. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  12040. }
  12041. sendClearCacheConfirmation(uuid);
  12042. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12043. return result;
  12044. }
  12045. int handleClearChargingProfileRequest(char *uuid, char *payload)
  12046. {
  12047. mtrace();
  12048. int result = FAIL;
  12049. int resultRename;
  12050. int evseIdInt, chargingProfileIdInt, stackLevelInt;
  12051. char chargingProfilePurposeStr[26]={0};
  12052. int tempevseIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  12053. char tempchargingProfilePurposeStr[26]={0};
  12054. char sstr[160]={0};
  12055. char str[100]={0};
  12056. int c = 0;
  12057. char *loc;
  12058. char fname[200]={0};
  12059. char comfirmstr[20]={0};
  12060. char word[1600]={0};
  12061. int clearflag = FALSE;
  12062. int chargingProfileIdIsNULL = FALSE;
  12063. int evseIsNULL = FALSE;
  12064. int chargingProfilePurposeIsNULL = FALSE;
  12065. int stackLevelIsNULL = FALSE;
  12066. //int GotoEnd = FALSE;
  12067. FILE *fptr1, *fptr2;
  12068. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  12069. int n_chargingProfile=0;
  12070. int isEmptyFile = FALSE;
  12071. char sLineWord[1600]={0};
  12072. char chargingProfiles[10][100]={0};
  12073. int ChargeProfileCount = 0;
  12074. int ch;
  12075. evseIdInt = chargingProfileIdInt = stackLevelInt = 0;
  12076. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  12077. json_object *ClearChargingProfile;
  12078. ClearChargingProfile = json_tokener_parse(payload);
  12079. if(!is_error(ClearChargingProfile))
  12080. {
  12081. // Optional data
  12082. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  12083. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  12084. else
  12085. chargingProfileIdIsNULL = TRUE;
  12086. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  12087. evseIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  12088. else
  12089. evseIsNULL = TRUE;
  12090. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  12091. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  12092. else
  12093. chargingProfilePurposeIsNULL = TRUE;
  12094. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  12095. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  12096. else
  12097. stackLevelIsNULL = TRUE;
  12098. }
  12099. json_object_put(ClearChargingProfile);
  12100. if(evseIsNULL == FALSE)
  12101. {
  12102. switch(evseIdInt)
  12103. {
  12104. case 0:
  12105. if(chargingProfilePurposeIsNULL == TRUE)
  12106. {
  12107. int l = 0;
  12108. strcpy(fname, ChargingStationMaxProfile_JSON);
  12109. if((access(fname,F_OK))!=-1)
  12110. {
  12111. strcpy(chargingProfiles[l], fname);
  12112. l = l + 1;
  12113. }
  12114. strcpy(fname, TxDefaultProfile_0_JSON);
  12115. if((access(fname,F_OK))!=-1)
  12116. {
  12117. strcpy(chargingProfiles[l], fname);
  12118. l = l + 1;
  12119. }
  12120. ChargeProfileCount = l;
  12121. }
  12122. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  12123. {
  12124. strcpy(fname, ChargingStationMaxProfile_JSON);
  12125. if((access(fname,F_OK))!=-1)
  12126. {
  12127. strcpy(chargingProfiles[0], fname);
  12128. ChargeProfileCount = 1;
  12129. }
  12130. }
  12131. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12132. {
  12133. strcpy(fname, TxDefaultProfile_0_JSON);
  12134. if((access(fname,F_OK))!=-1)
  12135. {
  12136. strcpy(chargingProfiles[0], fname);
  12137. ChargeProfileCount = 1;
  12138. }
  12139. }
  12140. break;
  12141. default:
  12142. if(chargingProfilePurposeIsNULL == TRUE)
  12143. {
  12144. int m = 0;
  12145. memset(fname, 0, ARRAY_SIZE(fname));
  12146. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12147. if((access(fname,F_OK))!=-1)
  12148. {
  12149. strcpy(chargingProfiles[m], fname);
  12150. m = m + 1;
  12151. }
  12152. memset(fname, 0, ARRAY_SIZE(fname));
  12153. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12154. if((access(fname,F_OK))!=-1)
  12155. {
  12156. strcpy(chargingProfiles[m], fname);
  12157. m = m + 1;
  12158. }
  12159. ChargeProfileCount = m;
  12160. }
  12161. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12162. {
  12163. //strcpy(fname, TxDefaultProfile_1_JSON);
  12164. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12165. if((access(fname,F_OK))!=-1)
  12166. {
  12167. strcpy(chargingProfiles[0], fname);
  12168. ChargeProfileCount = 1;
  12169. }
  12170. }
  12171. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  12172. {
  12173. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12174. if((access(fname,F_OK))!=-1)
  12175. {
  12176. strcpy(chargingProfiles[0], fname);
  12177. ChargeProfileCount = 1;
  12178. }
  12179. }
  12180. //strcpy(fname, ChargePointMaxProfile_JSON );
  12181. break;
  12182. }
  12183. }
  12184. else // Check all Charging Profiles
  12185. {
  12186. int i = 0;
  12187. char fnametemp[200]={0};
  12188. ChargeProfileCount = 0;
  12189. //Check ChargePointMaxProfile.json exit
  12190. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12191. {
  12192. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  12193. i = i + 1;
  12194. }
  12195. //Check TxDefaultProfile_%d.json
  12196. for(int j=1; j <= gunTotalNumber; j++)
  12197. {
  12198. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12199. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  12200. if((access(fnametemp,F_OK))!=-1)
  12201. {
  12202. strcpy(chargingProfiles[i], fnametemp);
  12203. i = i + 1;
  12204. }
  12205. }
  12206. //Check TxProfile_%d.json
  12207. for(int j=1; j <= gunTotalNumber; j++)
  12208. {
  12209. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12210. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  12211. if((access(fnametemp,F_OK))!=-1)
  12212. {
  12213. strcpy(chargingProfiles[i], fnametemp);
  12214. i = i + 1;
  12215. }
  12216. }
  12217. ChargeProfileCount = i;
  12218. }// End connectorIsNULL is TRUE
  12219. if(ChargeProfileCount == 0)
  12220. {
  12221. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12222. goto end;
  12223. }
  12224. if(evseIsNULL == FALSE && (evseIdInt != 0) && ( (evseIdInt-1) > gunTotalNumber) )
  12225. {
  12226. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12227. goto end;
  12228. }
  12229. if((evseIsNULL == FALSE) && (evseIdInt == 0) )
  12230. {
  12231. memset(str, 0, ARRAY_SIZE(str));
  12232. // clear temp file
  12233. sprintf(str,"rm -f %s",temp);
  12234. system(str);
  12235. for(int k=0; k < ChargeProfileCount; k++)
  12236. {
  12237. memset(str, 0, ARRAY_SIZE(str));
  12238. //clear file in C
  12239. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12240. system(str);
  12241. }
  12242. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12243. goto end;
  12244. }
  12245. else if(evseIsNULL == TRUE)
  12246. {
  12247. for(int k=0; k < ChargeProfileCount; k++)
  12248. {
  12249. fptr1 = fopen(chargingProfiles[k], "r");
  12250. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  12251. //Check Charging Profile Count
  12252. while(fscanf(fptr1, "%s", word) != EOF)
  12253. {
  12254. //DEBUG_INFO("word=%s\n",word);
  12255. if(strstr(word, "id")!= NULL)
  12256. {
  12257. //DEBUG_INFO("test id \n");
  12258. n_chargingProfile = n_chargingProfile + 1;
  12259. //DEBUG_INFO("id Found\n");
  12260. }
  12261. }
  12262. rewind(fptr1);
  12263. //search Charging Profile Element
  12264. //int i= 0;
  12265. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12266. {
  12267. //------------------------tempconnectorIdInt------------------------//
  12268. loc = strstr(sLineWord, "evseId");
  12269. c = 0;
  12270. memset(sstr ,0, sizeof(sstr) );
  12271. while (loc[strlen("evseId")+2+c] != ',')
  12272. {
  12273. sstr[c] = loc[strlen("evseId")+2+c];
  12274. c++;
  12275. }
  12276. sstr[c] = '\0';
  12277. tempevseIdInt = atoi(sstr);
  12278. printf("file's gun number is %d\n", tempevseIdInt);
  12279. //--------------------------id--------------------//
  12280. c = 0;
  12281. loc = strstr(sLineWord, "id");
  12282. memset(sstr ,0, ARRAY_SIZE(sstr));
  12283. while (loc[strlen("id")+2+c] != ',')
  12284. {
  12285. sstr[c] = loc[strlen("id")+2+c];
  12286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12287. c++;
  12288. }
  12289. sstr[c] = '\0';
  12290. tempchargingProfileIdInt = atoi(sstr);
  12291. //stackLevel
  12292. c = 0;
  12293. loc = strstr(sLineWord, "stackLevel");
  12294. memset(sstr ,0, ARRAY_SIZE(sstr));
  12295. while (loc[strlen("stackLevel")+2+c] != ',')
  12296. {
  12297. sstr[c] = loc[strlen("stackLevel")+2+c];
  12298. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12299. c++;
  12300. }
  12301. sstr[c] = '\0';
  12302. tempstackLevelInt = atoi(sstr);
  12303. c = 0;
  12304. loc = strstr(sLineWord, "chargingProfilePurpose");
  12305. memset(sstr ,0, ARRAY_SIZE(sstr));
  12306. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12307. {
  12308. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12309. c++;
  12310. }
  12311. sstr[c] = '\0';
  12312. strcpy(tempchargingProfilePurposeStr, sstr);
  12313. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12314. {
  12315. //------- not write to fptr2-------//
  12316. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12317. //clearflag = TRUE;
  12318. }
  12319. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  12320. {
  12321. //------- not write to fptr2-------//
  12322. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12323. }
  12324. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12325. {
  12326. //------- not write to fptr2-------//
  12327. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12328. }
  12329. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  12330. {
  12331. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12332. }
  12333. else
  12334. {
  12335. fprintf(fptr2, sLineWord);//writing data into file
  12336. }
  12337. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12338. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12339. if(clearflag == TRUE)
  12340. {
  12341. fclose(fptr1);
  12342. fclose(fptr2);
  12343. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12344. system(str);
  12345. // clear temp file
  12346. sprintf(str,"rm -f %s",temp);
  12347. system(str);
  12348. }
  12349. else
  12350. {
  12351. fclose(fptr1);
  12352. fclose(fptr2);
  12353. memset(str, 0, ARRAY_SIZE(str));
  12354. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12355. system(str);
  12356. resultRename = rename(temp, chargingProfiles[k]);
  12357. if(resultRename == 0)
  12358. {
  12359. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  12360. }
  12361. else
  12362. {
  12363. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  12364. }
  12365. if(comfirmstr[0]== 0)
  12366. {
  12367. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12368. }
  12369. //Check chargingProfile is empty file
  12370. /*------ Read the file ----------------*/
  12371. fptr1=fopen(chargingProfiles[k],"r");
  12372. ch=fgetc(fptr1);
  12373. rewind(fptr1);
  12374. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12375. if(ch!=EOF)
  12376. {
  12377. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12378. {
  12379. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12380. if(sLineWord[0]=='\0')
  12381. {
  12382. isEmptyFile = TRUE;
  12383. break;
  12384. }
  12385. else
  12386. {
  12387. isEmptyFile = FALSE;
  12388. break;
  12389. }
  12390. }
  12391. }
  12392. else
  12393. isEmptyFile = TRUE;
  12394. fclose(fptr1);
  12395. if(isEmptyFile == TRUE)
  12396. {
  12397. memset(str, 0, ARRAY_SIZE(str));
  12398. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12399. system(str);
  12400. }
  12401. }
  12402. }// End of while(int k=0; k < ChargePointCount; k++)
  12403. }
  12404. else if((evseIsNULL == FALSE) && (evseIdInt != 0) )
  12405. {
  12406. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  12407. for(int k=0; k < ChargeProfileCount; k++)
  12408. {
  12409. fptr1 = fopen(chargingProfiles[k], "r");
  12410. fptr2 = fopen(temp, "w+");
  12411. //Check Charging Profile Count
  12412. while(fscanf(fptr1, "%s", word) != EOF)
  12413. {
  12414. //DEBUG_INFO("word=%s\n",word);
  12415. if(strstr(word, "id")!= NULL)
  12416. {
  12417. n_chargingProfile = n_chargingProfile + 1;
  12418. }
  12419. }
  12420. rewind(fptr1);
  12421. //search Charging Profile Element
  12422. //int i= 0;
  12423. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12424. {
  12425. //*************************tempevseIdInt*********************************/
  12426. loc = strstr(sLineWord, "evseId");
  12427. c = 0;
  12428. memset(sstr ,0, ARRAY_SIZE(sstr));
  12429. while (loc[strlen("evseId")+2+c] != ',')
  12430. {
  12431. sstr[c] = loc[strlen("evseId")+2+c];
  12432. c++;
  12433. }
  12434. sstr[c] = '\0';
  12435. tempevseIdInt = atoi(sstr);
  12436. //id
  12437. c = 0;
  12438. loc = strstr(sLineWord, "id");
  12439. memset(sstr ,0, ARRAY_SIZE(sstr));
  12440. while (loc[strlen("id")+2+c] != ',')
  12441. {
  12442. sstr[c] = loc[strlen("id")+2+c];
  12443. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12444. c++;
  12445. }
  12446. sstr[c] = '\0';
  12447. tempchargingProfileIdInt = atoi(sstr);
  12448. //stackLevel
  12449. c = 0;
  12450. loc = strstr(sLineWord, "stackLevel");
  12451. memset(sstr ,0, ARRAY_SIZE(sstr));
  12452. while (loc[strlen("stackLevel")+2+c] != ',')
  12453. {
  12454. sstr[c] = loc[strlen("stackLevel")+2+c];
  12455. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12456. c++;
  12457. }
  12458. sstr[c] = '\0';
  12459. tempstackLevelInt = atoi(sstr);
  12460. c = 0;
  12461. loc = strstr(sLineWord, "chargingProfilePurpose");
  12462. memset(sstr ,0, ARRAY_SIZE(sstr));
  12463. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12464. {
  12465. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12466. c++;
  12467. }
  12468. sstr[c] = '\0';
  12469. strcpy(tempchargingProfilePurposeStr, sstr);
  12470. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12471. {
  12472. //------- not write to fptr2-------//
  12473. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12474. //clearflag = TRUE;
  12475. }
  12476. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12477. {
  12478. //------- not write to fptr2-------//
  12479. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12480. }
  12481. else if(stackLevelIsNULL == TRUE)
  12482. {
  12483. //Clear Whole File
  12484. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12485. clearflag = TRUE;
  12486. break;
  12487. }
  12488. else
  12489. {
  12490. fprintf(fptr2, sLineWord);//writing data into file
  12491. }
  12492. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12493. }
  12494. if(clearflag == TRUE)
  12495. {
  12496. fclose(fptr1);
  12497. fclose(fptr2);
  12498. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12499. system(str);
  12500. // clear temp file
  12501. sprintf(str,"rm -f %s",temp);
  12502. system(str);
  12503. }
  12504. else
  12505. {
  12506. fclose(fptr1);
  12507. fclose(fptr2);
  12508. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12509. system(str);
  12510. resultRename = rename(temp, chargingProfiles[k]);
  12511. if(resultRename == 0)
  12512. {
  12513. DEBUG_INFO("File ChargingProfile renamed successfully");
  12514. }
  12515. else
  12516. {
  12517. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  12518. }
  12519. if(comfirmstr[0]== 0)
  12520. {
  12521. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12522. }
  12523. //Check chargingProfile is empty file
  12524. /*------ Read the file ----------------*/
  12525. fptr1=fopen(chargingProfiles[k],"r");
  12526. ch=fgetc(fptr1);
  12527. rewind(fptr1);
  12528. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12529. if(ch!=EOF)
  12530. {
  12531. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12532. {
  12533. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12534. if(sLineWord[0]=='\0')
  12535. {
  12536. isEmptyFile = TRUE;
  12537. break;
  12538. }
  12539. else
  12540. {
  12541. isEmptyFile = FALSE;
  12542. break;
  12543. }
  12544. }
  12545. }
  12546. else
  12547. isEmptyFile = TRUE;
  12548. fclose(fptr1);
  12549. if(isEmptyFile == TRUE)
  12550. {
  12551. memset(str, 0, ARRAY_SIZE(str));
  12552. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12553. system(str);
  12554. }
  12555. /*------- End of reading ---------------*/
  12556. }
  12557. } // while(int k=0; k < ChargeProfileCount; k++)
  12558. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12559. end:
  12560. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12561. {
  12562. if(evseIdInt == 0)
  12563. {
  12564. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12565. {
  12566. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12567. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12568. }
  12569. }
  12570. else
  12571. {
  12572. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12573. checkCompositeSchedule(evseIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[evseIdInt-1], 0, TRUE);
  12574. }
  12575. }
  12576. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12577. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12578. return result;
  12579. }
  12580. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12581. {
  12582. mtrace();
  12583. int result = FAIL;
  12584. json_object *ClearDisplayMessage;
  12585. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12586. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12587. ClearDisplayMessage = json_tokener_parse(payload);
  12588. if(!is_error(ClearDisplayMessage))
  12589. {
  12590. // Required data
  12591. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12592. {
  12593. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12594. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12595. }
  12596. }
  12597. json_object_put(ClearDisplayMessage);
  12598. sendCostUpdatedConfirmation(uuid);
  12599. return result;
  12600. }
  12601. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12602. {
  12603. mtrace();
  12604. int result = FAIL;
  12605. json_object *ClearVariableMonitorin;
  12606. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12607. ClearVariableMonitorin = json_tokener_parse(payload);
  12608. if(!is_error(ClearVariableMonitorin))
  12609. {
  12610. // Required data
  12611. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12612. {
  12613. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  12614. {
  12615. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  12616. /*
  12617. * TODO:
  12618. * 1. Check response
  12619. */
  12620. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12621. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12622. }
  12623. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  12624. }
  12625. }
  12626. json_object_put(ClearVariableMonitorin);
  12627. return result;
  12628. }
  12629. int handleCostUpdatedRequest(char *uuid, char *payload)
  12630. {
  12631. mtrace();
  12632. int result = FAIL;
  12633. json_object *CostUpdate;
  12634. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12635. CostUpdate = json_tokener_parse(payload);
  12636. if(!is_error(CostUpdate))
  12637. {
  12638. // Required data
  12639. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12640. {
  12641. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12642. }
  12643. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12644. {
  12645. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12646. }
  12647. }
  12648. json_object_put(CostUpdate);
  12649. sendCostUpdatedConfirmation(uuid);
  12650. return result;
  12651. }
  12652. int handleCustomerInformationRequest(char *uuid, char *payload)
  12653. {
  12654. mtrace();
  12655. int result = FAIL;
  12656. json_object *CustomerInformation;
  12657. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12658. CustomerInformation = json_tokener_parse(payload);
  12659. if(!is_error(CustomerInformation))
  12660. {
  12661. // Required data
  12662. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12663. {
  12664. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12665. }
  12666. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12667. {
  12668. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12669. }
  12670. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12671. {
  12672. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12673. }
  12674. // Optional data
  12675. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12676. {
  12677. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12678. {
  12679. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12680. }
  12681. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12682. {
  12683. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12684. }
  12685. }
  12686. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12687. {
  12688. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12689. {
  12690. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12691. }
  12692. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12693. {
  12694. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12695. }
  12696. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12697. {
  12698. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12699. }
  12700. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12701. {
  12702. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12703. }
  12704. }
  12705. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12706. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12707. }
  12708. else
  12709. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12710. json_object_put(CustomerInformation);
  12711. sendCustomerInformationConfirmation(uuid);
  12712. return result;
  12713. }
  12714. void createFirmwareVersionByDataTransfer(void)
  12715. {
  12716. json_object *FirmwareDataTransfer = json_object_new_object();
  12717. // AC & DC model
  12718. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12719. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12720. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12721. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12722. // DC model
  12723. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12724. {
  12725. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12726. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12727. (gunType[3] != GUN_TYPE_UNKNOWN))
  12728. {
  12729. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12730. }
  12731. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  12732. {
  12733. // DS DM DW
  12734. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12735. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12736. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12737. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12738. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12739. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12740. }
  12741. else
  12742. {
  12743. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12744. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12745. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12746. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12747. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12748. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12749. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12750. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12751. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12752. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12753. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12754. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12755. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12756. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12757. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12758. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12759. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12760. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12761. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12762. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12763. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12764. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12765. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12766. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12767. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12768. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12769. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12770. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12771. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12772. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12773. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12774. }
  12775. }
  12776. // 4G model
  12777. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12778. {
  12779. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12780. }
  12781. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12782. json_object_put(FirmwareDataTransfer);
  12783. }
  12784. int handleDataTransferRequest(char *uuid, char *payload)
  12785. {
  12786. mtrace();
  12787. int result = PASS;
  12788. DEBUG_INFO("handleDataTransferRequest...\n");
  12789. if((uuid != NULL) && (payload != NULL))
  12790. {
  12791. json_object *DataTransfer;
  12792. DataTransfer = json_tokener_parse(payload);
  12793. if(!is_error(DataTransfer))
  12794. {
  12795. // Required data
  12796. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12797. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12798. // Optional data
  12799. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12800. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12801. if(json_object_object_get(DataTransfer, "data") != NULL)
  12802. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12803. result = PASS;
  12804. }
  12805. json_object_put(DataTransfer);
  12806. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12807. {
  12808. // Send all moudle firmware version on EVSE
  12809. createFirmwareVersionByDataTransfer();
  12810. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12811. }
  12812. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12813. {
  12814. system("/usr/bin/run_tmate_restart.sh &");
  12815. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12816. }
  12817. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12818. {
  12819. json_object *data;
  12820. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12821. if(!is_error(data))
  12822. {
  12823. 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))
  12824. {
  12825. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12826. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12827. if(json_object_object_get(data, "SOC") != NULL)
  12828. {
  12829. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12830. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12831. }
  12832. if(json_object_object_get(data, "Energy") != NULL)
  12833. {
  12834. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12835. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12836. }
  12837. if(json_object_object_get(data, "Duration") != NULL)
  12838. {
  12839. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12840. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12841. }
  12842. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12843. }
  12844. else
  12845. {
  12846. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12847. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12848. }
  12849. }
  12850. else
  12851. {
  12852. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12853. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12854. }
  12855. json_object_put(data);
  12856. }
  12857. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12858. {
  12859. json_object *data;
  12860. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12861. if(!is_error(data))
  12862. {
  12863. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12864. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12865. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12866. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12867. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12868. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12869. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12870. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12871. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12872. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12873. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12874. }
  12875. else
  12876. {
  12877. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12878. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12879. }
  12880. json_object_put(data);
  12881. }
  12882. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12883. {
  12884. json_object *data;
  12885. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12886. if(!is_error(data))
  12887. {
  12888. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12889. if(json_object_object_get(data, "Content_Type") != NULL)
  12890. {
  12891. 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))
  12892. {
  12893. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12894. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12895. {
  12896. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12897. }
  12898. }
  12899. else
  12900. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12901. }
  12902. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12903. }
  12904. else
  12905. {
  12906. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12907. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12908. }
  12909. json_object_put(data);
  12910. }
  12911. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12912. {
  12913. json_object *data;
  12914. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12915. if(!is_error(data))
  12916. {
  12917. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12918. if(json_object_object_get(data, "ConnectorId") != NULL)
  12919. {
  12920. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12921. }
  12922. if(json_object_object_get(data, "Page_Index") != NULL)
  12923. {
  12924. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  12925. }
  12926. if(json_object_object_get(data, "Duration") != NULL)
  12927. {
  12928. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  12929. }
  12930. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  12931. }
  12932. else
  12933. {
  12934. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12935. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12936. }
  12937. json_object_put(data);
  12938. }
  12939. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  12940. {
  12941. json_object *data;
  12942. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12943. if(!is_error(data))
  12944. {
  12945. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12946. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  12947. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  12948. {
  12949. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  12950. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  12951. else
  12952. {
  12953. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12954. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12955. }
  12956. }
  12957. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  12958. {
  12959. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  12960. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  12961. else
  12962. {
  12963. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12964. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12965. }
  12966. }
  12967. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  12968. {
  12969. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  12970. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  12971. else
  12972. {
  12973. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12974. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12975. }
  12976. }
  12977. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  12978. {
  12979. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  12980. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  12981. else
  12982. {
  12983. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12984. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12985. }
  12986. }
  12987. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  12988. {
  12989. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  12990. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  12991. else
  12992. {
  12993. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12994. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12995. }
  12996. }
  12997. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  12998. {
  12999. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  13000. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  13001. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  13002. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  13003. else
  13004. {
  13005. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13006. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13007. }
  13008. }
  13009. if(json_object_object_get(data, "isAuthentication") != NULL)
  13010. {
  13011. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  13012. {
  13013. case 0:
  13014. case 1:
  13015. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  13016. break;
  13017. default:
  13018. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13019. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13020. break;
  13021. }
  13022. }
  13023. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  13024. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13025. }
  13026. else
  13027. {
  13028. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13029. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13030. }
  13031. json_object_put(data);
  13032. }
  13033. else
  13034. {
  13035. // Can not find valid message id
  13036. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  13037. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  13038. ,ShmOCPP20Data->DataTransfer[0].vendorId
  13039. ,ShmOCPP20Data->DataTransfer[0].messageId
  13040. ,ShmOCPP20Data->DataTransfer[0].data);
  13041. }
  13042. }
  13043. else
  13044. {
  13045. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  13046. result = FAIL;
  13047. }
  13048. sendDataTransferConfirmation(uuid, 0);
  13049. return result;
  13050. }
  13051. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13052. {
  13053. mtrace();
  13054. int result = FAIL;
  13055. json_object *DeleteCertificate;
  13056. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13057. DeleteCertificate = json_tokener_parse(payload);
  13058. if(!is_error(DeleteCertificate))
  13059. {
  13060. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  13061. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  13062. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13063. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13064. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13065. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13066. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13067. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13068. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13069. DEBUG_INFO("serialNumber: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber);
  13070. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  13071. {
  13072. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  13073. }
  13074. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  13075. {
  13076. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  13077. }
  13078. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  13079. {
  13080. ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  13081. }
  13082. char temp[256] = {0};
  13083. char compareData[256] = {0};
  13084. int isMatch = TRUE;
  13085. // Check CentralSystemRootCertificate
  13086. if(access(ROOTCA_CS,F_OK) != -1)
  13087. {
  13088. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  13089. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  13090. for(int i = 0; compareData[i]; i++)
  13091. {
  13092. compareData[i] = tolower(compareData[i]);
  13093. }
  13094. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13095. isMatch = FALSE;
  13096. if(isMatch == TRUE)
  13097. {
  13098. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  13099. for(int i = 0; compareData[i]; i++)
  13100. {
  13101. compareData[i] = tolower(compareData[i]);
  13102. }
  13103. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13104. isMatch = FALSE;
  13105. }
  13106. if(isMatch == TRUE)
  13107. {
  13108. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  13109. for(int i = 0; compareData[i]; i++)
  13110. {
  13111. compareData[i] = tolower(compareData[i]);
  13112. }
  13113. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13114. isMatch = FALSE;
  13115. }
  13116. if(isMatch == TRUE)
  13117. {
  13118. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  13119. sprintf(temp, "rm -f %s", ROOTCA_CS);
  13120. system(temp);
  13121. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13122. goto End;
  13123. }
  13124. }
  13125. // Check ManufacturerRootCertificate
  13126. if(access(ROOTCA_MF,F_OK) != -1)
  13127. {
  13128. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  13129. isMatch = TRUE;
  13130. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  13131. for(int i = 0; compareData[i]; i++)
  13132. {
  13133. compareData[i] = tolower(compareData[i]);
  13134. }
  13135. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13136. isMatch = FALSE;
  13137. if(isMatch == TRUE)
  13138. {
  13139. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  13140. for(int i = 0; compareData[i]; i++)
  13141. {
  13142. compareData[i] = tolower(compareData[i]);
  13143. }
  13144. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13145. isMatch = FALSE;
  13146. }
  13147. if(isMatch == TRUE)
  13148. {
  13149. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  13150. for(int i = 0; compareData[i]; i++)
  13151. {
  13152. compareData[i] = tolower(compareData[i]);
  13153. }
  13154. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13155. isMatch = FALSE;
  13156. }
  13157. if(isMatch == TRUE)
  13158. {
  13159. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  13160. sprintf(temp, "rm -f %s", ROOTCA_MF);
  13161. system(temp);
  13162. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13163. goto End;
  13164. }
  13165. }
  13166. if(access(ROOTCA_V2G,F_OK) != -1)
  13167. {
  13168. DEBUG_INFO("Checking V2GRootCertificate...\n");
  13169. isMatch = TRUE;
  13170. parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, compareData);
  13171. for(int i = 0; compareData[i]; i++)
  13172. {
  13173. compareData[i] = tolower(compareData[i]);
  13174. }
  13175. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13176. isMatch = FALSE;
  13177. if(isMatch == TRUE)
  13178. {
  13179. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, compareData);
  13180. for(int i = 0; compareData[i]; i++)
  13181. {
  13182. compareData[i] = tolower(compareData[i]);
  13183. }
  13184. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13185. isMatch = FALSE;
  13186. }
  13187. if(isMatch == TRUE)
  13188. {
  13189. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  13190. for(int i = 0; compareData[i]; i++)
  13191. {
  13192. compareData[i] = tolower(compareData[i]);
  13193. }
  13194. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13195. isMatch = FALSE;
  13196. }
  13197. if(isMatch == TRUE)
  13198. {
  13199. DEBUG_INFO("Deleting V2GRootCertificate...\n");
  13200. sprintf(temp, "rm -f %s", ROOTCA_V2G);
  13201. system(temp);
  13202. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13203. goto End;
  13204. }
  13205. }
  13206. if(access(ROOTCA_MO,F_OK) != -1)
  13207. {
  13208. DEBUG_INFO("Checking MORootCertificate...\n");
  13209. isMatch = TRUE;
  13210. parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, compareData);
  13211. for(int i = 0; compareData[i]; i++)
  13212. {
  13213. compareData[i] = tolower(compareData[i]);
  13214. }
  13215. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13216. isMatch = FALSE;
  13217. if(isMatch == TRUE)
  13218. {
  13219. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, compareData);
  13220. for(int i = 0; compareData[i]; i++)
  13221. {
  13222. compareData[i] = tolower(compareData[i]);
  13223. }
  13224. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13225. isMatch = FALSE;
  13226. }
  13227. if(isMatch == TRUE)
  13228. {
  13229. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, compareData);
  13230. for(int i = 0; compareData[i]; i++)
  13231. {
  13232. compareData[i] = tolower(compareData[i]);
  13233. }
  13234. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13235. isMatch = FALSE;
  13236. }
  13237. if(isMatch == TRUE)
  13238. {
  13239. DEBUG_INFO("Deleting MORootCertificate...\n");
  13240. sprintf(temp, "rm -f %s", ROOTCA_MO);
  13241. system(temp);
  13242. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13243. goto End;
  13244. }
  13245. }
  13246. // Check certCP
  13247. if(access(CERTIFICATE_CP,F_OK) != -1)
  13248. {
  13249. DEBUG_INFO("Checking certCP...\n");
  13250. isMatch = TRUE;
  13251. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  13252. for(int i = 0; compareData[i]; i++)
  13253. {
  13254. compareData[i] = tolower(compareData[i]);
  13255. }
  13256. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13257. isMatch = FALSE;
  13258. if(isMatch == TRUE)
  13259. {
  13260. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  13261. for(int i = 0; compareData[i]; i++)
  13262. {
  13263. compareData[i] = tolower(compareData[i]);
  13264. }
  13265. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13266. isMatch = FALSE;
  13267. }
  13268. if(isMatch == TRUE)
  13269. {
  13270. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  13271. for(int i = 0; compareData[i]; i++)
  13272. {
  13273. compareData[i] = tolower(compareData[i]);
  13274. }
  13275. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13276. isMatch = FALSE;
  13277. }
  13278. if(isMatch == TRUE)
  13279. {
  13280. DEBUG_INFO("Deleting certCP...\n");
  13281. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  13282. system(temp);
  13283. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13284. goto End;
  13285. }
  13286. }
  13287. }
  13288. else
  13289. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  13290. End:
  13291. json_object_put(DeleteCertificate);
  13292. ShmOCPP20Data->MsMsg.bits.DeleteCertificateReq = 1;
  13293. sendDeleteCertificateConfirmation(uuid);
  13294. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13295. return result;
  13296. }
  13297. int handleGetBaseReportRequest(char *uuid, char *payload)
  13298. {
  13299. mtrace();
  13300. int result = FAIL;
  13301. json_object *GetBaseRepor;
  13302. DEBUG_INFO("handleGetBaseReportRequest...\n");
  13303. GetBaseRepor = json_tokener_parse(payload);
  13304. if(!is_error(GetBaseRepor))
  13305. {
  13306. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  13307. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  13308. // Required data
  13309. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  13310. {
  13311. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  13312. }
  13313. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  13314. {
  13315. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  13316. }
  13317. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  13318. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13319. else
  13320. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13321. }
  13322. else
  13323. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13324. json_object_put(GetBaseRepor);
  13325. sendGetBaseReportConfirmation(uuid);
  13326. return result;
  13327. }
  13328. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  13329. {
  13330. mtrace();
  13331. int result = FAIL;
  13332. int gun_index = -1;
  13333. json_object *GetChargingProfiles;
  13334. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  13335. GetChargingProfiles = json_tokener_parse(payload);
  13336. if(!is_error(GetChargingProfiles))
  13337. {
  13338. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  13339. {
  13340. 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;
  13341. }
  13342. if(gun_index >-1)
  13343. {
  13344. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  13345. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  13346. // Required data
  13347. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  13348. {
  13349. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  13350. }
  13351. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  13352. {
  13353. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  13354. {
  13355. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  13356. }
  13357. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  13358. {
  13359. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  13360. }
  13361. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  13362. {
  13363. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  13364. {
  13365. 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)));
  13366. }
  13367. }
  13368. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  13369. {
  13370. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  13371. {
  13372. 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));
  13373. }
  13374. }
  13375. }
  13376. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  13377. }
  13378. else
  13379. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  13380. }
  13381. json_object_put(GetChargingProfiles);
  13382. sendGetChargingProfilesConfirmation(uuid, gun_index);
  13383. return result;
  13384. }
  13385. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  13386. {
  13387. mtrace();
  13388. int result = FAIL;
  13389. int evseIdInt, durationInt;
  13390. char chargingRateUnitStr[4]={0};
  13391. char comfirmstr[20];
  13392. int confirmPeriods = 0;
  13393. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  13394. json_object *GetCompositeSchedule;
  13395. GetCompositeSchedule = json_tokener_parse(payload);
  13396. if(!is_error(GetCompositeSchedule))
  13397. {
  13398. // Required data
  13399. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  13400. evseIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  13401. else
  13402. evseIdInt = -1;
  13403. if(json_object_object_get(GetCompositeSchedule, "duration"))
  13404. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  13405. else
  13406. durationInt = 86400;
  13407. // Optional data
  13408. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  13409. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  13410. }
  13411. json_object_put(GetCompositeSchedule);
  13412. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  13413. if((evseIdInt == 0) ||
  13414. ((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber)))
  13415. {
  13416. int gun_index = (evseIdInt==0?0:evseIdInt-1);
  13417. struct ChargingProfileType tmpProfile[1];
  13418. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  13419. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  13420. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  13421. {
  13422. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  13423. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, FALSE);
  13424. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  13425. }
  13426. else
  13427. {
  13428. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  13429. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, TRUE);
  13430. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  13431. }
  13432. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13433. {
  13434. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  13435. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  13436. }
  13437. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct ChargingScheduleType));
  13438. strcpy((char *)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.startDateTime, (char *)tmpProfile[0].chargingSchedule[0].startSchedule);
  13439. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13440. {
  13441. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  13442. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  13443. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  13444. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  13445. (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))
  13446. {
  13447. confirmPeriods = idx;
  13448. break;
  13449. }
  13450. }
  13451. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  13452. {
  13453. confirmPeriods += 1;
  13454. }
  13455. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13456. }
  13457. else
  13458. {
  13459. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  13460. }
  13461. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, evseIdInt, confirmPeriods);
  13462. return result;
  13463. }
  13464. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  13465. {
  13466. mtrace();
  13467. int result = FAIL;
  13468. json_object *GetDisplayMessages;
  13469. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  13470. GetDisplayMessages = json_tokener_parse(payload);
  13471. if(!is_error(GetDisplayMessages))
  13472. {
  13473. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  13474. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  13475. // Required data
  13476. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  13477. {
  13478. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  13479. }
  13480. // Optional data
  13481. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  13482. {
  13483. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  13484. }
  13485. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  13486. {
  13487. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  13488. }
  13489. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  13490. {
  13491. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  13492. {
  13493. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  13494. }
  13495. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  13496. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  13497. }
  13498. else
  13499. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  13500. }
  13501. json_object_put(GetDisplayMessages);
  13502. return result;
  13503. }
  13504. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13505. {
  13506. mtrace();
  13507. int result = FAIL;
  13508. int certCnt = 0;
  13509. unsigned char foundCertCnt = 0;
  13510. json_object *GetInstalledCertificateIds;
  13511. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13512. GetInstalledCertificateIds = json_tokener_parse(payload);
  13513. if(!is_error(GetInstalledCertificateIds))
  13514. {
  13515. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  13516. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  13517. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13518. // Optional data
  13519. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  13520. {
  13521. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  13522. {
  13523. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  13524. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13525. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "Accepted");
  13526. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  13527. // Check CSMSRootCertificate
  13528. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "CSMSRootCertificate")!= NULL)
  13529. {
  13530. if(access(ROOTCA_CS,F_OK) != -1)
  13531. {
  13532. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "CSMSRootCertificate");
  13533. char parseData[512] = {0};
  13534. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13535. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13536. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  13537. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13538. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13539. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13540. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13541. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13542. certCnt++;
  13543. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13544. }
  13545. else
  13546. {
  13547. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  13548. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13549. }
  13550. }
  13551. // Check ManufacturerRootCertificate
  13552. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "ManufacturerRootCertificate") != NULL)
  13553. {
  13554. if(access(ROOTCA_MF,F_OK) != -1)
  13555. {
  13556. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "ManufacturerRootCertificate");
  13557. char parseData[512] = {0};
  13558. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13559. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13560. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  13561. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13562. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13563. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13564. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13565. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13566. certCnt++;
  13567. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13568. }
  13569. else
  13570. {
  13571. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  13572. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13573. }
  13574. }
  13575. // Check MORootCertificate
  13576. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "MORootCertificate") != NULL)
  13577. {
  13578. if(access(ROOTCA_MO,F_OK) != -1)
  13579. {
  13580. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "MORootCertificate");
  13581. char parseData[512] = {0};
  13582. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13583. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13584. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, parseData) == PASS)
  13585. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13586. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13587. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13588. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13589. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13590. certCnt++;
  13591. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13592. }
  13593. else
  13594. {
  13595. DEBUG_INFO(">>> No MORootCertificate was found.\n");
  13596. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13597. }
  13598. }
  13599. // Check V2GRootCertificate
  13600. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GRootCertificate") != NULL)
  13601. {
  13602. if(access(ROOTCA_V2G,F_OK) != -1)
  13603. {
  13604. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GRootCertificate");
  13605. char parseData[512] = {0};
  13606. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13607. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13608. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13609. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13610. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13611. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13612. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13613. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13614. certCnt++;
  13615. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13616. }
  13617. else
  13618. {
  13619. DEBUG_INFO(">>> No V2GRootCertificate was found.\n");
  13620. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13621. }
  13622. }
  13623. // Check V2GCertificateChain
  13624. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GCertificateChain") != NULL)
  13625. {
  13626. if(access(CERTIFICATE_V2G,F_OK) != -1)
  13627. {
  13628. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GCertificateChain");
  13629. char parseData[512] = {0};
  13630. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13631. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13632. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13633. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13634. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13635. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13636. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13637. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13638. certCnt++;
  13639. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13640. }
  13641. else
  13642. {
  13643. DEBUG_INFO(">>> No V2GCertificateChain was found.\n");
  13644. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13645. }
  13646. }
  13647. else
  13648. {
  13649. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13650. }
  13651. }
  13652. }
  13653. else
  13654. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13655. }
  13656. json_object_put(GetInstalledCertificateIds);
  13657. sendGetInstalledCertificateIdsConfirmation(uuid, foundCertCnt);
  13658. return result;
  13659. }
  13660. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  13661. {
  13662. mtrace();
  13663. int result = FAIL;
  13664. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  13665. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  13666. {
  13667. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  13668. localversion = 0;
  13669. }
  13670. else
  13671. {
  13672. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  13673. localversion = 0;
  13674. DB_getListVerion();
  13675. }
  13676. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  13677. sendGetLocalListVersionConfirmation(uuid);
  13678. return result;
  13679. }
  13680. static char fnamePlusPath[100]={0};
  13681. static char fnamePWithNoPath[60]={0};
  13682. void checkUploadLog(void)
  13683. {
  13684. FILE *fp;
  13685. /* Open the command for reading. */
  13686. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  13687. if (fp == NULL) {
  13688. printf("Failed to run command\n" );
  13689. exit(1);
  13690. }
  13691. int ftppathlen = 0;
  13692. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  13693. int i = 0;
  13694. /* Read the output a line at a time - output it. */
  13695. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  13696. if(i==0)
  13697. {
  13698. ftppathlen = strlen(fnamePlusPath);
  13699. printf("%s\n", fnamePlusPath);
  13700. fnamePlusPath[ftppathlen]='\0';
  13701. break;
  13702. }
  13703. i= i+1;
  13704. }
  13705. /* close */
  13706. pclose(fp);
  13707. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  13708. {
  13709. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  13710. {
  13711. fnamePlusPath[k]='\0';
  13712. }
  13713. }
  13714. i=1;
  13715. //char fname[60]={0};
  13716. while(i < ftppathlen)
  13717. {
  13718. int len=ftppathlen-i;
  13719. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  13720. {
  13721. printf("compare '/' all right\n");
  13722. break;
  13723. }
  13724. i=i+1;
  13725. }
  13726. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  13727. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  13728. fnamePWithNoPath[i+1] = '\0';
  13729. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  13730. {
  13731. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  13732. {
  13733. fnamePWithNoPath[j]='\0';
  13734. }
  13735. }
  13736. FILE* fp1 = fopen(fnamePlusPath, "r");
  13737. if (fp1)
  13738. {
  13739. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  13740. // file exists
  13741. fclose(fp1);
  13742. }
  13743. else
  13744. {
  13745. // file doesn't exist
  13746. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  13747. }
  13748. }
  13749. void* GetLogProcess(void* data)
  13750. {
  13751. th_GetLog = pthread_self();
  13752. pthread_detach(pthread_self());
  13753. mtrace();
  13754. int requestId, retriesInt=0, retryIntervalInt=0;
  13755. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  13756. 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};
  13757. int port=0;
  13758. int isSuccess = FALSE;
  13759. char ftpbuf[1024]={0};
  13760. char cmdBuf[2048];
  13761. struct tm *tmNow;
  13762. time_t CurrentTime;
  13763. struct tm tmStart;
  13764. struct tm tmStop;
  13765. CurrentTime = time(NULL);
  13766. tmNow=localtime(&CurrentTime);
  13767. uint16_t targetYear, targetMonth;
  13768. json_object *GetLog;
  13769. DEBUG_INFO("GetGetProcess...\n");
  13770. GetLog = json_tokener_parse(data);
  13771. if(!is_error(GetLog))
  13772. {
  13773. // Required data
  13774. if(json_object_object_get(GetLog, "requestId") != NULL)
  13775. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13776. if(json_object_object_get(GetLog, "logType") != NULL)
  13777. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13778. if(json_object_object_get(GetLog, "log") != NULL)
  13779. {
  13780. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  13781. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13782. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13783. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13784. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13785. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13786. }
  13787. // Optional data
  13788. if(json_object_object_get(GetLog, "retries") != NULL)
  13789. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13790. else
  13791. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  13792. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13793. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13794. else
  13795. retryIntervalInt = 30;
  13796. }
  13797. json_object_put(GetLog);
  13798. ShmOCPP20Data->GetLog.requestId = requestId;
  13799. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  13800. {
  13801. /*
  13802. * TODO:
  13803. * 1. Pack security log
  13804. */
  13805. }
  13806. else
  13807. {
  13808. // Pack log to compress file
  13809. 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) &&
  13810. (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))
  13811. {
  13812. // Pack system log
  13813. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13814. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13815. targetYear = tmStart.tm_year;
  13816. targetMonth = tmStart.tm_mon;
  13817. do
  13818. {
  13819. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13820. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13821. if(targetMonth+1>=13)
  13822. {
  13823. targetYear += 1;
  13824. targetMonth = 1;
  13825. }
  13826. else
  13827. {
  13828. targetMonth += 1;
  13829. }
  13830. }while((targetYear < (tmNow->tm_year+1900)) ||
  13831. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13832. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13833. system(cmdBuf);
  13834. // Pack charging & event log
  13835. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13836. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13837. targetYear = tmStart.tm_year;
  13838. targetMonth = tmStart.tm_mon;
  13839. do
  13840. {
  13841. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13842. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  13843. if(targetMonth+1>=13)
  13844. {
  13845. targetYear += 1;
  13846. targetMonth = 1;
  13847. }
  13848. else
  13849. {
  13850. targetMonth += 1;
  13851. }
  13852. }while((targetYear < (tmNow->tm_year+1900)) ||
  13853. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13854. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13855. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13856. system(cmdBuf);
  13857. // Combine log file
  13858. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13859. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13860. }
  13861. else
  13862. {
  13863. system("exec /root/logPackTools 'log' 6");
  13864. }
  13865. }
  13866. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13867. system(cmdBuf);
  13868. checkUploadLog();
  13869. //****************location*******************/
  13870. if(strcmp(remoteLocation,"")==0)
  13871. {
  13872. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13873. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13874. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13875. goto end;
  13876. }
  13877. memset(protocol, 0, ARRAY_SIZE(protocol));
  13878. memset(user, 0, ARRAY_SIZE(user) );
  13879. memset(password, 0, ARRAY_SIZE(password));
  13880. memset(host, 0, ARRAY_SIZE(host));
  13881. memset(path, 0, ARRAY_SIZE(path));
  13882. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13883. memset(host1, 0, ARRAY_SIZE(host1));
  13884. memset(path1, 0, ARRAY_SIZE(path1));
  13885. /*location: ftp://user:password@host:port/path*/
  13886. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13887. if((access(fnamePlusPath,F_OK))!=-1)
  13888. {
  13889. DEBUG_INFO("fnamePlusPath exist.\n");
  13890. }
  13891. else
  13892. {
  13893. DEBUG_INFO("fnamePlusPath not exist!\n");
  13894. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13895. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13896. goto end;
  13897. }
  13898. if(strchr(remoteLocation,'@')==NULL)
  13899. {
  13900. sscanf(remoteLocation,
  13901. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13902. protocol, host, &port, path);
  13903. strcpy(user,"anonymous");
  13904. strcpy(password,"");
  13905. }
  13906. else
  13907. {
  13908. //DEBUG_INFO("pch=%s\n", pch);
  13909. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13910. protocol, user, password, host, &port, path);
  13911. }
  13912. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13913. {
  13914. DEBUG_INFO("protocol is not ftp/http ! \n");
  13915. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13916. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13917. goto end;
  13918. }
  13919. if(strncmp(remoteLocation,"http", 4) == 0)
  13920. {
  13921. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13922. sprintf(ftppath,"/%s", path);
  13923. do
  13924. {
  13925. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13926. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13927. sleep(3);
  13928. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  13929. if(!isSuccess)
  13930. {
  13931. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13932. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13933. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13934. sleep(retryIntervalInt);
  13935. }
  13936. else
  13937. {
  13938. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13939. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13940. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13941. }
  13942. retriesInt--;
  13943. }while((isSuccess == 0)&&(retriesInt >= 0));
  13944. }
  13945. else
  13946. {
  13947. sscanf(host,"%[^/]%s",host1, path1);
  13948. if(strlen(path) > 0)
  13949. sprintf(ftppath,"/%s", path);
  13950. else
  13951. sprintf(ftppath,"/%s", path1);
  13952. int ftppathlen=strlen(ftppath);
  13953. int i=1;
  13954. char filenametemp[50];
  13955. while(i < ftppathlen)
  13956. {
  13957. int len=ftppathlen-i;
  13958. if(ftppath[len]== 47) // '/' ascll code: 47
  13959. {
  13960. DEBUG_INFO("find '/' all right\n");
  13961. break;
  13962. }
  13963. i=i+1;
  13964. }
  13965. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13966. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13967. filenametemp[i+1] = 0;
  13968. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13969. if(port == 0)
  13970. port = 21;
  13971. do
  13972. {
  13973. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13974. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13975. sleep(3);
  13976. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  13977. if(!isSuccess)
  13978. {
  13979. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13980. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13981. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13982. sleep(retryIntervalInt);
  13983. }
  13984. else
  13985. {
  13986. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13987. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13988. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13989. }
  13990. retriesInt--;
  13991. }while((!isSuccess)&&(retriesInt >= 0));
  13992. }
  13993. end:
  13994. system("rm -f /mnt/*");
  13995. sleep(5);
  13996. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  13997. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13998. interLock.isGetLogGoing = OFF;
  13999. pthread_exit(NULL);
  14000. }
  14001. int handleGetLogRequest(char *uuid, char *payload)
  14002. {
  14003. mtrace();
  14004. int result = FAIL;
  14005. char fName[258];
  14006. time_t CurrentTime;
  14007. struct tm *tm;
  14008. pthread_t th_Status;
  14009. DEBUG_INFO("handleGetLogRequest...\n");
  14010. CurrentTime = time(NULL);
  14011. tm = localtime(&CurrentTime);
  14012. 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);
  14013. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  14014. if(interLock.isGetLogGoing)
  14015. {
  14016. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  14017. isCancelUploadLog = TRUE;
  14018. pthread_cancel(th_GetLog);
  14019. interLock.isGetLogGoing = OFF;
  14020. sleep(1);
  14021. isCancelUploadLog = OFF;
  14022. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_AcceptedCanceled]);
  14023. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14024. sleep(1);
  14025. }
  14026. else
  14027. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  14028. sendGetLogConfirmation(uuid);
  14029. if(!interLock.isGetLogGoing)
  14030. {
  14031. interLock.isGetLogGoing = ON;
  14032. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14033. sleep(1);
  14034. }
  14035. else
  14036. {
  14037. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14038. }
  14039. return result;
  14040. }
  14041. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  14042. {
  14043. mtrace();
  14044. int result = FAIL;
  14045. uint8_t cntCriteria = 0;
  14046. int cntComponentVariable = 0;
  14047. uint8_t cntFoundMonitoringVariable = 0;
  14048. json_object *GetMonitoringReport;
  14049. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  14050. GetMonitoringReport = json_tokener_parse(payload);
  14051. if(!is_error(GetMonitoringReport))
  14052. {
  14053. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  14054. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  14055. // Required data
  14056. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  14057. {
  14058. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  14059. }
  14060. // Optional data
  14061. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  14062. {
  14063. cntCriteria = json_object_array_length(json_object_object_get(GetMonitoringReport, "monitoringCriteria"));
  14064. for(int idx=0; idx<cntCriteria; idx++)
  14065. {
  14066. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx], "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  14067. }
  14068. }
  14069. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  14070. {
  14071. cntComponentVariable = json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));
  14072. if(cntComponentVariable <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  14073. {
  14074. for(int idx=0;idx<cntComponentVariable;idx++)
  14075. {
  14076. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  14077. {
  14078. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  14079. {
  14080. 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")));
  14081. }
  14082. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  14083. {
  14084. 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")));
  14085. }
  14086. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14087. {
  14088. 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)
  14089. {
  14090. 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"));
  14091. }
  14092. 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)
  14093. {
  14094. 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"));
  14095. }
  14096. }
  14097. }
  14098. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  14099. {
  14100. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14101. {
  14102. 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")));
  14103. }
  14104. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14105. {
  14106. 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")));
  14107. }
  14108. }
  14109. }
  14110. }
  14111. }
  14112. }
  14113. json_object_put(GetMonitoringReport);
  14114. //strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  14115. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_EmptyResultSet]);
  14116. if(cntComponentVariable>0)
  14117. {
  14118. uint8_t cntTypeSupport = 0;
  14119. for(int idx_cv=0; idx_cv < cntComponentVariable; idx_cv++)
  14120. {
  14121. cntTypeSupport = 0;
  14122. for(int idx=0; idx < 10; idx++)
  14123. {
  14124. if((strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx_cv].component.name)==0) &&
  14125. (strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx_cv].variable.name)==0))
  14126. {
  14127. if(strlen((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[0]) > 0)
  14128. {
  14129. for(int idx_cri=0; idx_cri<cntCriteria; idx_cri++)
  14130. {
  14131. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  14132. {
  14133. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring])==0)
  14134. {
  14135. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14136. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14137. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14138. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14139. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14140. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14141. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14142. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14143. cntTypeSupport++;
  14144. break;
  14145. }
  14146. }
  14147. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  14148. {
  14149. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring])==0)
  14150. {
  14151. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14152. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14153. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14154. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14155. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14156. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14157. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14158. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14159. cntTypeSupport++;
  14160. break;
  14161. }
  14162. }
  14163. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  14164. {
  14165. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring])==0)
  14166. {
  14167. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14168. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14169. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14170. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14171. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14172. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14173. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14174. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14175. cntTypeSupport++;
  14176. break;
  14177. }
  14178. }
  14179. }
  14180. }
  14181. else
  14182. {
  14183. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14184. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14185. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14186. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14187. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14188. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14189. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14190. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14191. cntTypeSupport++;
  14192. }
  14193. cntFoundMonitoringVariable++;
  14194. }
  14195. }
  14196. }
  14197. }
  14198. else
  14199. {
  14200. for(int idx=0; idx < 10; idx++)
  14201. {
  14202. if(strlen((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[0]) > 0)
  14203. {
  14204. if((strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name)>0) && (strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name)>0))
  14205. {
  14206. int isSameVariableFound = FALSE;
  14207. for(int idx_cri=0; idx_cri<cntCriteria; idx_cri++)
  14208. {
  14209. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  14210. {
  14211. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring])==0)
  14212. {
  14213. for(int idx_cv=0; idx_cv < 10; idx_cv++)
  14214. {
  14215. if((strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name)>0) && (strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name)>0))
  14216. {
  14217. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name) != NULL) &&
  14218. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name) != NULL))
  14219. {
  14220. isSameVariableFound = TRUE;
  14221. for(int idx_vm=1; idx_vm < 10; idx_vm++)
  14222. {
  14223. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type) == 0)
  14224. {
  14225. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14226. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14227. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14228. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14229. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14230. }
  14231. }
  14232. break;
  14233. }
  14234. }
  14235. else
  14236. {
  14237. if(isSameVariableFound==FALSE)
  14238. {
  14239. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14240. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14241. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14242. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14243. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14244. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14245. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14246. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14247. }
  14248. break;
  14249. }
  14250. }
  14251. break;
  14252. }
  14253. }
  14254. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  14255. {
  14256. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring])==0)
  14257. {
  14258. for(int idx_cv=0; idx_cv < 10; idx_cv++)
  14259. {
  14260. if((strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name)>0) && (strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name)>0))
  14261. {
  14262. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name) != NULL) &&
  14263. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name) != NULL))
  14264. {
  14265. isSameVariableFound = TRUE;
  14266. for(int idx_vm=1; idx_vm < 10; idx_vm++)
  14267. {
  14268. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type) == 0)
  14269. {
  14270. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14271. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14272. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14273. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14274. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14275. }
  14276. }
  14277. break;
  14278. }
  14279. }
  14280. else
  14281. {
  14282. if(isSameVariableFound==FALSE)
  14283. {
  14284. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14285. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14286. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14287. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14288. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14289. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14290. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14291. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14292. }
  14293. break;
  14294. }
  14295. }
  14296. break;
  14297. }
  14298. }
  14299. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  14300. {
  14301. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring])==0)
  14302. {
  14303. for(int idx_cv=0; idx_cv < 10; idx_cv++)
  14304. {
  14305. if((strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name)>0) && (strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name)>0))
  14306. {
  14307. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name) != NULL) &&
  14308. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name) != NULL))
  14309. {
  14310. isSameVariableFound = TRUE;
  14311. for(int idx_vm=1; idx_vm < 10; idx_vm++)
  14312. {
  14313. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type) == 0)
  14314. {
  14315. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14316. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14317. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14318. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14319. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14320. }
  14321. }
  14322. break;
  14323. }
  14324. }
  14325. else
  14326. {
  14327. if(isSameVariableFound==FALSE)
  14328. {
  14329. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14330. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14331. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14332. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14333. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14334. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14335. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14336. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14337. }
  14338. break;
  14339. }
  14340. }
  14341. break;
  14342. }
  14343. }
  14344. }
  14345. }
  14346. }
  14347. else
  14348. {
  14349. if((strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name)>0) && (strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name)>0))
  14350. {
  14351. int isSameVariableFound = FALSE;
  14352. for(int idx_cv=0; idx_cv < 10; idx_cv++)
  14353. {
  14354. if((strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name)>0) && (strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name)>0))
  14355. {
  14356. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name) != NULL) &&
  14357. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name) != NULL))
  14358. {
  14359. isSameVariableFound = TRUE;
  14360. for(int idx_vm=1; idx_vm < 10; idx_vm++)
  14361. {
  14362. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type) == 0)
  14363. {
  14364. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14365. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14366. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14367. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14368. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14369. }
  14370. }
  14371. }
  14372. }
  14373. else
  14374. {
  14375. if(isSameVariableFound==FALSE)
  14376. {
  14377. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14378. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14379. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14380. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14381. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14382. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14383. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14384. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14385. }
  14386. }
  14387. }
  14388. }
  14389. }
  14390. cntFoundMonitoringVariable++;
  14391. }
  14392. }
  14393. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]) != 0)
  14394. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  14395. sendGetMonitoringReportConfirmation(uuid);
  14396. return result;
  14397. }
  14398. int handleGetReportRequest(char *uuid, char *payload)
  14399. {
  14400. mtrace();
  14401. int result = FAIL;
  14402. json_object *GetReport;
  14403. DEBUG_INFO("handleGetReportRequest...\n");
  14404. GetReport = json_tokener_parse(payload);
  14405. if(!is_error(GetReport))
  14406. {
  14407. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  14408. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  14409. // Required data
  14410. if(json_object_object_get(GetReport, "requestId") != NULL)
  14411. {
  14412. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  14413. }
  14414. // Optional data
  14415. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  14416. {
  14417. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  14418. }
  14419. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  14420. {
  14421. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  14422. {
  14423. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  14424. {
  14425. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  14426. {
  14427. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  14428. {
  14429. 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")));
  14430. }
  14431. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  14432. {
  14433. 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")));
  14434. }
  14435. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14436. {
  14437. 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)
  14438. {
  14439. 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"));
  14440. }
  14441. 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)
  14442. {
  14443. 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"));
  14444. }
  14445. }
  14446. }
  14447. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  14448. {
  14449. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14450. {
  14451. 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")));
  14452. }
  14453. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14454. {
  14455. 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")));
  14456. }
  14457. }
  14458. }
  14459. }
  14460. }
  14461. }
  14462. json_object_put(GetReport);
  14463. /*
  14464. * TODO:
  14465. * 1. Response result
  14466. */
  14467. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14468. sendGetReportConfirmation(uuid);
  14469. return result;
  14470. }
  14471. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  14472. {
  14473. mtrace();
  14474. int result = FAIL;
  14475. uint8_t tempIndex;
  14476. json_object *GetTransactionStatus;
  14477. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  14478. GetTransactionStatus = json_tokener_parse(payload);
  14479. if(!is_error(GetTransactionStatus))
  14480. {
  14481. memset(&ShmOCPP20Data->GetTransactionStatus, 0, sizeof(struct GetTransactionStatus_20));
  14482. memcpy(&ShmOCPP20Data->GetTransactionStatus.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus.guid));
  14483. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = FALSE;
  14484. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = FALSE;
  14485. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  14486. {
  14487. sprintf((char*)ShmOCPP20Data->GetTransactionStatus.transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  14488. }
  14489. if(strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId)>0)
  14490. {
  14491. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14492. {
  14493. if(strcmp((char*)ShmOCPP20Data->GetTransactionStatus.transactionId, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId)==0)
  14494. {
  14495. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14496. {
  14497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14498. tempIndex = ((gun_index==2) ? 1: 0);
  14499. else
  14500. tempIndex = gun_index;
  14501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14502. {
  14503. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) &&
  14504. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14505. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14506. }
  14507. }
  14508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14509. {
  14510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14511. tempIndex = ((gun_index==2) ? 1: 0);
  14512. else
  14513. tempIndex = gun_index;
  14514. for (int index = 0; index < CCS_QUANTITY; index++)
  14515. {
  14516. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) &&
  14517. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14518. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14519. }
  14520. }
  14521. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14522. {
  14523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14524. tempIndex = ((gun_index==2) ? 1: 0);
  14525. else
  14526. tempIndex = gun_index;
  14527. for (int index = 0; index < GB_QUANTITY; index++)
  14528. {
  14529. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) &&
  14530. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14531. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14532. }
  14533. }
  14534. else if(gunType[gun_index] == GUN_TYPE_DO)
  14535. {
  14536. tempIndex = gun_index;
  14537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14538. {
  14539. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) &&
  14540. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)))
  14541. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14542. }
  14543. }
  14544. else
  14545. {
  14546. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14547. tempIndex = 2;
  14548. else
  14549. tempIndex = gun_index;
  14550. for (int index = 0; index < AC_QUANTITY; index++)
  14551. {
  14552. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) &&
  14553. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14554. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14555. }
  14556. }
  14557. }
  14558. }
  14559. }
  14560. char rmFileCmd[100]={0};
  14561. int TransactionQueueNum = 0;
  14562. struct stat stats;
  14563. stat("/Storage/OCPP", &stats);
  14564. // Check for directory existence
  14565. if (S_ISDIR(stats.st_mode) == 1)
  14566. {
  14567. //DEBUG_INFO("\n OCPP directory exist \n");
  14568. }
  14569. else
  14570. {
  14571. //DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  14572. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  14573. system(rmFileCmd);
  14574. }
  14575. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  14576. if((access("/Storage/OCPP/TransactionRelatedQueue20",F_OK))!=-1)
  14577. {
  14578. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14579. }
  14580. else
  14581. {
  14582. FILE *fp = fopen("/Storage/OCPP/TransactionRelatedQueue20", "r");
  14583. char line[QUEUE_MESSAGE_LENGTH]={0};
  14584. if (fp == NULL) {
  14585. DEBUG_INFO("cannot open file TransactionRelatedQueue!");
  14586. }
  14587. TransactionQueueNum = 0; // the number of packets in queue
  14588. while(fgets(line, sizeof line, fp) != NULL) {
  14589. if(strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId)>0)
  14590. {
  14591. if(strstr(line, (char*)ShmOCPP20Data->GetTransactionStatus.transactionId) != NULL)
  14592. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = TRUE;
  14593. }
  14594. TransactionQueueNum += 1; //the number of packets in queue
  14595. }
  14596. fclose(fp);
  14597. }
  14598. if((strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId) == 0) && (TransactionQueueNum>0))
  14599. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = TRUE;
  14600. }
  14601. json_object_put(GetTransactionStatus);
  14602. sendGetTransactionStatusConfirmation(uuid);
  14603. return result;
  14604. }
  14605. int handleGetVariablesRequest(char *uuid, char *payload)
  14606. {
  14607. mtrace();
  14608. int result = FAIL;
  14609. int isUnknownComponent = TRUE;
  14610. json_object *GetVariables;
  14611. DEBUG_INFO("handleGetVariablesRequest...\n");
  14612. GetVariables = json_tokener_parse(payload);
  14613. if(!is_error(GetVariables))
  14614. {
  14615. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  14616. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  14617. // Required data
  14618. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  14619. {
  14620. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  14621. {
  14622. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  14623. {
  14624. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  14625. {
  14626. 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")));
  14627. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  14628. }
  14629. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  14630. {
  14631. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  14632. }*/
  14633. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  14634. {
  14635. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  14636. {
  14637. 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")));
  14638. }
  14639. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  14640. {
  14641. 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")));
  14642. }
  14643. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  14644. {
  14645. 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)
  14646. {
  14647. 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"));
  14648. }
  14649. 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)
  14650. {
  14651. 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"));
  14652. }
  14653. }
  14654. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  14655. }
  14656. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  14657. {
  14658. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  14659. {
  14660. 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")));
  14661. }
  14662. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  14663. {
  14664. 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")));
  14665. }
  14666. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  14667. }
  14668. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  14669. {
  14670. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  14671. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  14672. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  14673. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  14674. {
  14675. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  14676. isUnknownComponent = FALSE;
  14677. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  14678. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  14679. {
  14680. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  14681. break;
  14682. }
  14683. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14684. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  14685. {
  14686. struct sysinfo s_info;
  14687. int error = sysinfo(&s_info);
  14688. if(error != 0)
  14689. {
  14690. DEBUG_WARN("System uptime get error: %d\n", error);
  14691. }
  14692. else
  14693. {
  14694. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  14695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  14696. }
  14697. }
  14698. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14699. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  14700. {
  14701. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  14702. }
  14703. else
  14704. {
  14705. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  14706. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  14707. }
  14708. break;
  14709. }
  14710. else
  14711. {
  14712. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  14713. {
  14714. isUnknownComponent = FALSE;
  14715. }
  14716. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  14717. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  14718. }
  14719. }
  14720. if(isUnknownComponent == TRUE)
  14721. {
  14722. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  14723. }
  14724. }
  14725. }
  14726. }
  14727. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  14728. }
  14729. json_object_put(GetVariables);
  14730. return result;
  14731. }
  14732. int handleInstallCertificateRequest(char *uuid, char *payload)
  14733. {
  14734. mtrace();
  14735. int result = PASS;
  14736. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14737. json_object *InstallCertificate;
  14738. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14739. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14740. InstallCertificate = json_tokener_parse(payload);
  14741. if(!is_error(InstallCertificate))
  14742. {
  14743. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  14744. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  14745. // Required data
  14746. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  14747. {
  14748. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14749. }
  14750. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  14751. {
  14752. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14753. }
  14754. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificateType);
  14755. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificate);
  14756. char temp[1024];
  14757. FILE *fp = fopen(tempCert, "w");
  14758. fprintf(fp, "%s", ShmOCPP20Data->InstallCertificate.certificate);
  14759. fclose(fp);
  14760. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14761. char strExpDate[30];
  14762. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14763. fp = popen(temp, "r");
  14764. if(fp)
  14765. {
  14766. while(fgets(temp, sizeof(temp), fp) != NULL)
  14767. {
  14768. if(strstr(temp, "notAfter=") != NULL)
  14769. {
  14770. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14771. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14772. break;
  14773. }
  14774. }
  14775. }
  14776. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14777. struct tm tmExpDate;
  14778. struct timeb tbExpDate;
  14779. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14780. tbExpDate.time = mktime(&tmExpDate);
  14781. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14782. {
  14783. DEBUG_INFO("The enddate is already expired...\n");
  14784. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14785. goto End;
  14786. }
  14787. // Verify certificate with rootCA
  14788. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14789. fp = popen(temp, "r");
  14790. if(fp)
  14791. {
  14792. while(fgets(temp, sizeof(temp), fp) != NULL)
  14793. {
  14794. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14795. {
  14796. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14797. break;
  14798. }
  14799. else
  14800. {
  14801. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14802. }
  14803. }
  14804. }
  14805. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14806. {
  14807. //=====================================================
  14808. // Verify if the certificate is valid or not. (OCSP?)
  14809. //=====================================================
  14810. /*
  14811. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14812. // Get ocsp url
  14813. char ocspUrl[512];
  14814. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14815. fp = popen(temp, "r");
  14816. if(fp)
  14817. {
  14818. while(fgets(temp, sizeof(temp), fp) != NULL)
  14819. {
  14820. if(strstr(temp, "://") != NULL)
  14821. {
  14822. strcpy(ocspUrl, temp);
  14823. break;
  14824. }
  14825. }
  14826. }
  14827. // Get certificate chain for issuer
  14828. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14829. *
  14830. // Execute OCSP
  14831. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14832. fp = popen(temp, "r");
  14833. if(fp)
  14834. {
  14835. while(fgets(temp, sizeof(temp), fp) != NULL)
  14836. {
  14837. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14838. {
  14839. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14840. break;
  14841. }
  14842. }
  14843. }
  14844. system("rm -f /Storage/OCPP/tempChain.pem");
  14845. pclose(fp);
  14846. */
  14847. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14848. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14849. {
  14850. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14851. goto End;
  14852. }
  14853. else
  14854. DEBUG_INFO("OCSP verifying...PASS.\n");
  14855. }
  14856. else
  14857. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14858. }
  14859. json_object_put(InstallCertificate);
  14860. End:
  14861. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") == 0)
  14862. {
  14863. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]) == 0)
  14864. {
  14865. if(access(ROOTCA_CS,F_OK) != -1)
  14866. {
  14867. DEBUG_INFO("Existed CSMSRootCertificate is found. Replacing...\n");
  14868. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14869. rename(tempCert, ROOTCA_CS);
  14870. }
  14871. else
  14872. {
  14873. DEBUG_INFO("No existed CSMSRootCertificate Creating...\n");
  14874. rename(tempCert, ROOTCA_CS);
  14875. }
  14876. }
  14877. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]) == 0)
  14878. {
  14879. if(access(ROOTCA_MF,F_OK) != -1)
  14880. {
  14881. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14882. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14883. rename(tempCert, ROOTCA_MF);
  14884. }
  14885. else
  14886. {
  14887. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14888. rename(tempCert, ROOTCA_MF);
  14889. }
  14890. }
  14891. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]) == 0)
  14892. {
  14893. if(access(ROOTCA_V2G,F_OK) != -1)
  14894. {
  14895. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14896. rename(ROOTCA_V2G, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14897. rename(tempCert, ROOTCA_V2G);
  14898. }
  14899. else
  14900. {
  14901. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14902. rename(tempCert, ROOTCA_V2G);
  14903. }
  14904. }
  14905. ShmOCPP20Data->MsMsg.bits.InstallCertificateReq = 1;
  14906. }
  14907. sendInstallCertificateConfirmation(uuid);
  14908. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14909. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14910. {
  14911. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14912. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  14913. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14914. }
  14915. return result;
  14916. }
  14917. int handlePublishFirmwareRequest(char *uuid, char *payload)
  14918. {
  14919. mtrace();
  14920. int result = FAIL;
  14921. json_object *PublishFirmware;
  14922. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  14923. PublishFirmware = json_tokener_parse(payload);
  14924. if(!is_error(PublishFirmware))
  14925. {
  14926. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  14927. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  14928. // Required data
  14929. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  14930. {
  14931. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  14932. }
  14933. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  14934. {
  14935. sprintf((char*)ShmOCPP20Data->PublishFirmware.checksum, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  14936. }
  14937. // Optional data
  14938. if(json_object_object_get(PublishFirmware, "location") != NULL)
  14939. {
  14940. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  14941. }
  14942. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  14943. {
  14944. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  14945. }
  14946. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  14947. {
  14948. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  14949. }
  14950. }
  14951. json_object_put(PublishFirmware);
  14952. /*
  14953. * TODO:
  14954. * 1. Publish firmware preocess and response
  14955. */
  14956. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  14957. sendPublishFirmwareConfirmation(uuid);
  14958. return result;
  14959. }
  14960. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  14961. {
  14962. mtrace();
  14963. int result = FAIL;
  14964. int8_t evseId = -1;
  14965. uint8_t tempIndex;
  14966. uint8_t isOverConnectorMax = FALSE;
  14967. uint8_t isPeriodOverMax = FALSE;
  14968. uint8_t isTxProfile = TRUE;
  14969. uint8_t isAllowStart = TRUE;
  14970. uint8_t filename[128]={0};
  14971. char cmdBuf[128];
  14972. FILE *filePtr;
  14973. json_object *RemoteStartTransaction;
  14974. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  14975. RemoteStartTransaction = json_tokener_parse(payload);
  14976. if(!is_error(RemoteStartTransaction))
  14977. {
  14978. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  14979. {
  14980. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  14981. {
  14982. evseId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  14983. }
  14984. else
  14985. {
  14986. isOverConnectorMax = TRUE;
  14987. DEBUG_WARN("Evse id shall not equal 0 and should be less than gunTotalNumber.\n");
  14988. }
  14989. }
  14990. else
  14991. {
  14992. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  14993. {
  14994. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  14995. {
  14996. evseId = (idx+1);
  14997. DEBUG_INFO("Remote start without evseId but detect connector of evse-%02d connected ready to start.\n", evseId);
  14998. break;
  14999. }
  15000. }
  15001. }
  15002. if(isOverConnectorMax == FALSE)
  15003. {
  15004. if(evseId > 0)
  15005. {
  15006. DEBUG_INFO("Requested evseId id: %d\n", evseId);
  15007. memset(&ShmOCPP20Data->RequestStartTransaction[evseId-1], 0, sizeof(struct RequestStartTransaction_20));
  15008. memcpy(&ShmOCPP20Data->RequestStartTransaction[evseId-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[evseId-1].guid));
  15009. // Required data
  15010. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  15011. {
  15012. ShmOCPP20Data->RequestStartTransaction[evseId-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  15013. }
  15014. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  15015. {
  15016. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  15017. {
  15018. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  15019. }
  15020. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  15021. {
  15022. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  15023. }
  15024. }
  15025. // Optional data
  15026. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  15027. {
  15028. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  15029. {
  15030. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  15031. }
  15032. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  15033. {
  15034. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  15035. }
  15036. }
  15037. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  15038. {
  15039. // Check periods is over max configuration
  15040. 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))
  15041. {
  15042. isPeriodOverMax = TRUE;
  15043. }
  15044. // Check profile purpose is TxProfile
  15045. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15046. {
  15047. ShmOCPP20Data->RequestStartTransaction[evseId-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  15048. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  15049. }
  15050. else
  15051. {
  15052. isTxProfile = FALSE;
  15053. }
  15054. }
  15055. //check Transaction active
  15056. if(gunType[evseId-1] == GUN_TYPE_CHAdeMO)
  15057. {
  15058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15059. {
  15060. tempIndex = ((evseId-1) == 2) ? 1: 0;
  15061. }
  15062. else
  15063. {
  15064. tempIndex = (evseId-1);
  15065. }
  15066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15067. {
  15068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  15069. {
  15070. 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))
  15071. {
  15072. //Reserved
  15073. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  15074. }
  15075. 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))
  15076. {
  15077. //Reserved
  15078. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  15079. isAllowStart = FALSE;
  15080. }
  15081. else
  15082. {
  15083. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15084. {
  15085. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  15086. isAllowStart = FALSE;
  15087. }
  15088. }//END FOR ELSE
  15089. }
  15090. }// END FOR CHAdeMO_QUANTITY
  15091. }
  15092. else if(gunType[evseId-1] == GUN_TYPE_CCS)
  15093. {
  15094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15095. {
  15096. tempIndex = ((evseId-1) == 2) ? 1: 0;
  15097. }
  15098. else
  15099. {
  15100. tempIndex = (evseId-1);
  15101. }
  15102. for (int index = 0; index < CCS_QUANTITY; index++)
  15103. {
  15104. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15105. {
  15106. 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))
  15107. {
  15108. //Reserved
  15109. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  15110. }
  15111. 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))
  15112. {
  15113. //Reserved
  15114. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  15115. isAllowStart = FALSE;
  15116. }
  15117. else
  15118. {
  15119. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15120. {
  15121. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  15122. isAllowStart = FALSE;
  15123. }
  15124. }// END FOR ELSE
  15125. }
  15126. }// END FOR CCS_QUANTITY
  15127. }
  15128. else if(gunType[evseId-1] == GUN_TYPE_GBT)
  15129. {
  15130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15131. {
  15132. tempIndex = ((evseId-1) == 2) ? 1: 0;
  15133. }
  15134. else
  15135. {
  15136. tempIndex = (evseId-1);
  15137. }
  15138. for (int index = 0; index < GB_QUANTITY; index++)
  15139. {
  15140. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  15141. {
  15142. 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))
  15143. {
  15144. //Reserved
  15145. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  15146. }
  15147. 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))
  15148. {
  15149. //Reserved
  15150. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  15151. isAllowStart = FALSE;
  15152. }
  15153. else
  15154. {
  15155. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15156. {
  15157. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  15158. isAllowStart = FALSE;
  15159. }
  15160. }// END FOR ELSE
  15161. }
  15162. } // END FOR GB_QUANTITY
  15163. }
  15164. else if(gunType[evseId-1] == GUN_TYPE_DO)
  15165. {
  15166. tempIndex = (evseId-1);
  15167. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15168. {
  15169. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  15170. {
  15171. 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))
  15172. {
  15173. //Reserved
  15174. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  15175. }
  15176. 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))
  15177. {
  15178. //Reserved
  15179. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  15180. isAllowStart = FALSE;
  15181. }
  15182. else
  15183. {
  15184. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15185. {
  15186. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  15187. isAllowStart = FALSE;
  15188. }
  15189. }// END FOR ELSE
  15190. }
  15191. } // END FOR GB_QUANTITY
  15192. }
  15193. else
  15194. {
  15195. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15196. {
  15197. tempIndex = 2;
  15198. }
  15199. else
  15200. {
  15201. tempIndex = (evseId-1);
  15202. }
  15203. for (int index = 0; index < AC_QUANTITY; index++)
  15204. {
  15205. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  15206. {
  15207. 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))
  15208. {
  15209. //Reserved
  15210. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  15211. }
  15212. 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))
  15213. {
  15214. //Reserved
  15215. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  15216. isAllowStart = FALSE;
  15217. }
  15218. else
  15219. {
  15220. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15221. {
  15222. DEBUG_WARN("AC connector not allow start cause busy.\n");
  15223. isAllowStart = FALSE;
  15224. }
  15225. }//END FOR ELSE
  15226. }
  15227. }// END FOR AC_QUANTITY
  15228. }
  15229. }
  15230. else
  15231. {
  15232. DEBUG_INFO("Connector id does not specific.\n");
  15233. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15234. {
  15235. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  15236. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  15237. // Required data
  15238. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  15239. {
  15240. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  15241. }
  15242. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  15243. {
  15244. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  15245. {
  15246. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  15247. }
  15248. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  15249. {
  15250. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  15251. }
  15252. }
  15253. // Optional data
  15254. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  15255. {
  15256. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  15257. {
  15258. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  15259. }
  15260. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  15261. {
  15262. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  15263. }
  15264. }
  15265. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  15266. {
  15267. // Check periods is over max configuration
  15268. 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))
  15269. {
  15270. isPeriodOverMax = TRUE;
  15271. }
  15272. // Check profile purpose is TxProfile
  15273. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15274. {
  15275. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  15276. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  15277. }
  15278. else
  15279. {
  15280. isTxProfile = FALSE;
  15281. }
  15282. }
  15283. }
  15284. }
  15285. }
  15286. // Profile replace or add info
  15287. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  15288. {
  15289. if(evseId != -1)
  15290. {
  15291. if(strlen((char*)filename) > 0)
  15292. {
  15293. // Save profile to file
  15294. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  15295. system(cmdBuf);
  15296. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", evseId);
  15297. filePtr = fopen((char*)filename, "w");
  15298. 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));
  15299. fclose(filePtr);
  15300. }
  15301. ShmOCPP20Data->CsMsg.bits[evseId-1].RequestStartTransactionReq = ON;
  15302. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15303. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_transactionId);
  15304. result = PASS;
  15305. }
  15306. else
  15307. {
  15308. uint8_t isHasIdleConnector = FALSE;
  15309. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15310. {
  15311. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  15312. {
  15313. isHasIdleConnector = TRUE;
  15314. break;
  15315. }
  15316. }
  15317. if((isHasIdleConnector == TRUE) && !ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15318. {
  15319. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  15320. if(strlen((char*)filename) > 0)
  15321. {
  15322. // Save profile to file
  15323. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  15324. system(cmdBuf);
  15325. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  15326. filePtr = fopen((char*)filename, "w");
  15327. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  15328. fclose(filePtr);
  15329. }
  15330. refreshStartTimer(&clientTime.RemoteStartWait);
  15331. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  15332. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15333. {
  15334. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15335. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  15336. }
  15337. result = PASS;
  15338. }
  15339. else
  15340. {
  15341. DEBUG_INFO("There is not any connector is idle.\n");
  15342. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15343. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15344. }
  15345. }
  15346. }
  15347. else
  15348. {
  15349. if(isOverConnectorMax != FALSE)
  15350. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  15351. if(isPeriodOverMax)
  15352. DEBUG_WARN("Profile periods quantity is over spec.\n");
  15353. if(!isTxProfile)
  15354. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  15355. if(!isAllowStart)
  15356. DEBUG_WARN("Target connector does not allow start.\n");
  15357. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((evseId-1)<0?0:(evseId-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  15358. }
  15359. }
  15360. json_object_put(RemoteStartTransaction);
  15361. sendRemoteStartTransactionConfirmation(uuid, ((evseId-1)<0?0:(evseId-1)));
  15362. return result;
  15363. }
  15364. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  15365. {
  15366. mtrace();
  15367. int result = FAIL;
  15368. int match = FALSE;
  15369. int GunNO = 0;
  15370. int tempIndex = 0;
  15371. char transactionIdStr[37];
  15372. int transactionIdIsNULL= TRUE;
  15373. json_object *RemoteStopTransaction;
  15374. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  15375. if(server_pending == TRUE)
  15376. {
  15377. return 0;
  15378. }
  15379. RemoteStopTransaction = json_tokener_parse(payload);
  15380. if(!is_error(RemoteStopTransaction))
  15381. {
  15382. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  15383. {
  15384. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  15385. transactionIdIsNULL = FALSE;
  15386. }
  15387. }
  15388. json_object_put(RemoteStopTransaction);
  15389. if(transactionIdIsNULL == FALSE)
  15390. {
  15391. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  15392. {
  15393. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  15394. {
  15395. //check Transaction active
  15396. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15397. {
  15398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15399. {
  15400. tempIndex = ((gun_index==2) ? 1: 0);
  15401. }
  15402. else
  15403. {
  15404. tempIndex = gun_index;
  15405. }
  15406. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15407. {
  15408. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15409. {
  15410. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15411. {
  15412. match = TRUE;
  15413. GunNO = gun_index;
  15414. }
  15415. }
  15416. }// END FOR CHAdeMO_QUANTITY
  15417. }
  15418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15419. {
  15420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15421. {
  15422. tempIndex = ((gun_index==2) ? 1: 0);
  15423. }
  15424. else
  15425. {
  15426. tempIndex = gun_index;
  15427. }
  15428. for (int index = 0; index < CCS_QUANTITY; index++)
  15429. {
  15430. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15431. {
  15432. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15433. {
  15434. match = TRUE;
  15435. GunNO = gun_index;
  15436. }
  15437. }
  15438. }// END FOR CCS_QUANTITY
  15439. }
  15440. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15441. {
  15442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15443. {
  15444. tempIndex = ((gun_index==2) ? 1: 0);
  15445. }
  15446. else
  15447. {
  15448. tempIndex = gun_index;
  15449. }
  15450. for (int index = 0; index < GB_QUANTITY; index++)
  15451. {
  15452. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15453. {
  15454. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15455. {
  15456. match = TRUE;
  15457. GunNO = gun_index;
  15458. }
  15459. }
  15460. }// END FOR GB_QUANTITY
  15461. }
  15462. else if(gunType[gun_index] == GUN_TYPE_DO)
  15463. {
  15464. tempIndex = gun_index;
  15465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15466. {
  15467. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15468. {
  15469. 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
  15470. {
  15471. match = TRUE;
  15472. GunNO = gun_index;
  15473. }
  15474. }
  15475. }// END FOR GB_QUANTITY
  15476. }
  15477. else
  15478. {
  15479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15480. {
  15481. tempIndex = 2;
  15482. }
  15483. else
  15484. {
  15485. tempIndex = gun_index;
  15486. }
  15487. for (int index = 0; index < AC_QUANTITY; index++)
  15488. {
  15489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15490. {
  15491. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15492. {
  15493. match = TRUE;
  15494. GunNO = gun_index;
  15495. }
  15496. }
  15497. }// END FOR CHAdeMO_QUANTITY
  15498. } // END FOR AC ELSE
  15499. }// CHECK IF ResponseTransactionId == transactionIdInt
  15500. }//END FOR
  15501. if( match == TRUE)
  15502. {
  15503. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  15504. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15505. }
  15506. else
  15507. {
  15508. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15509. }
  15510. }
  15511. else
  15512. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15513. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  15514. return result;
  15515. }
  15516. int handleReserveNowRequest(char *uuid, char *payload)
  15517. {
  15518. mtrace();
  15519. int result = FAIL;
  15520. int evseIdInt=0, reservationIdInt=0;
  15521. int tempIndex = 0;
  15522. json_object *ReserveNow;
  15523. DEBUG_INFO("handleReserveNowRequest ...\n");
  15524. ReserveNow = json_tokener_parse(payload);
  15525. if(!is_error(ReserveNow))
  15526. {
  15527. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  15528. {
  15529. evseIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15530. evseIdInt = (evseIdInt==0)?1:evseIdInt;
  15531. memset(&ShmOCPP20Data->ReserveNow[evseIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  15532. ShmOCPP20Data->ReserveNow[evseIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15533. }
  15534. // Required data
  15535. if(json_object_object_get(ReserveNow, "id") != NULL)
  15536. ShmOCPP20Data->ReserveNow[evseIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "id"));
  15537. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  15538. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  15539. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  15540. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  15541. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  15542. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  15543. // Optional data
  15544. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  15545. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  15546. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  15547. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  15548. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  15549. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  15550. result = PASS;
  15551. }
  15552. json_object_put(ReserveNow);
  15553. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15554. if((evseIdInt > 0) && ((evseIdInt -1) <= gunTotalNumber))
  15555. {
  15556. //check Transaction active
  15557. if(gunType[evseIdInt -1] == GUN_TYPE_CHAdeMO)
  15558. {
  15559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15560. {
  15561. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15562. }
  15563. else
  15564. {
  15565. tempIndex = evseIdInt -1;
  15566. }
  15567. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15568. {
  15569. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15570. {
  15571. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15572. {
  15573. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15574. {
  15575. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15576. {
  15577. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  15578. {
  15579. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15580. }
  15581. else
  15582. {
  15583. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15584. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15585. }
  15586. }
  15587. 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'))
  15588. {
  15589. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15590. }
  15591. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15592. {
  15593. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15594. }
  15595. else
  15596. {
  15597. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15598. }
  15599. }
  15600. 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
  15601. {
  15602. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15603. }
  15604. }
  15605. else
  15606. {
  15607. //replace reservation
  15608. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15609. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15610. }
  15611. }
  15612. } // END FOR CHAdeMO_QUANTITY
  15613. }
  15614. else if(gunType[evseIdInt -1] == GUN_TYPE_CCS)
  15615. {
  15616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15617. {
  15618. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15619. }
  15620. else
  15621. {
  15622. tempIndex = evseIdInt -1;
  15623. }
  15624. for (int index = 0; index < CCS_QUANTITY; index++)
  15625. {
  15626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15627. {
  15628. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15629. {
  15630. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15631. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15632. {
  15633. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15634. {
  15635. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  15636. {
  15637. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15638. }
  15639. else
  15640. {
  15641. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15642. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15643. }
  15644. }
  15645. 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'))
  15646. {
  15647. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15648. }
  15649. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  15650. {
  15651. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15652. }
  15653. else
  15654. {
  15655. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15656. }
  15657. }
  15658. 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
  15659. {
  15660. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15661. }
  15662. }
  15663. else
  15664. {
  15665. //replace reservation
  15666. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15667. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15668. }
  15669. }
  15670. } // END FOR CCS_QUANTITY
  15671. }
  15672. else if(gunType[evseIdInt -1] == GUN_TYPE_GBT)
  15673. {
  15674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15675. {
  15676. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15677. }
  15678. else
  15679. {
  15680. tempIndex = evseIdInt -1;
  15681. }
  15682. for (int index = 0; index < GB_QUANTITY; index++)
  15683. {
  15684. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15685. {
  15686. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15687. {
  15688. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15689. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15690. {
  15691. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15692. {
  15693. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  15694. {
  15695. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15696. }
  15697. else
  15698. {
  15699. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15700. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15701. }
  15702. }
  15703. 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'))
  15704. {
  15705. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15706. }
  15707. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15708. {
  15709. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15710. }
  15711. else
  15712. {
  15713. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15714. }
  15715. }
  15716. 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
  15717. {
  15718. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15719. }
  15720. }
  15721. else
  15722. {
  15723. //replace reservation
  15724. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15725. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15726. }
  15727. }
  15728. }// END FOR GB_QUANTITY
  15729. }
  15730. else if(gunType[evseIdInt -1] == GUN_TYPE_DO)
  15731. {
  15732. tempIndex = evseIdInt -1;
  15733. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15734. {
  15735. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15736. {
  15737. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  15738. {
  15739. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15740. 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
  15741. {
  15742. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15743. {
  15744. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  15745. {
  15746. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15747. }
  15748. else
  15749. {
  15750. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15751. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15752. }
  15753. }
  15754. 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'))
  15755. {
  15756. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15757. }
  15758. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15759. {
  15760. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15761. }
  15762. else
  15763. {
  15764. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15765. }
  15766. }
  15767. 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
  15768. {
  15769. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15770. }
  15771. }
  15772. else
  15773. {
  15774. //replace reservation
  15775. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15776. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15777. }
  15778. }
  15779. }// END FOR DO_QUANTITY
  15780. }
  15781. else
  15782. {
  15783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15784. {
  15785. tempIndex = 2;
  15786. }
  15787. else
  15788. {
  15789. tempIndex = (evseIdInt -1);
  15790. }
  15791. for (int index = 0; index < AC_QUANTITY; index++)
  15792. {
  15793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15794. {
  15795. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15796. {
  15797. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15798. {
  15799. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15800. {
  15801. 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))
  15802. {
  15803. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15804. }
  15805. else
  15806. {
  15807. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15808. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15809. }
  15810. }
  15811. 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'))
  15812. {
  15813. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15814. }
  15815. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15816. {
  15817. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15818. }
  15819. else
  15820. {
  15821. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15822. }
  15823. }
  15824. 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
  15825. {
  15826. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15827. }
  15828. }
  15829. else
  15830. {
  15831. //replace reservation
  15832. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15833. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15834. }
  15835. }
  15836. } // END FOR AC_QUANTITY
  15837. }
  15838. }
  15839. else if(evseIdInt == 0)
  15840. {
  15841. //check Transaction active
  15842. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15843. {
  15844. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15845. {
  15846. 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'))
  15847. {
  15848. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15849. goto end;
  15850. }
  15851. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15852. {
  15853. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15854. goto end;
  15855. }
  15856. 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
  15857. {
  15858. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15859. goto end;
  15860. }
  15861. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15862. {
  15863. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15864. goto end;
  15865. }
  15866. }
  15867. }// END FOR CHAdeMO_QUANTITY
  15868. for (int index = 0; index < CCS_QUANTITY; index++)
  15869. {
  15870. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15871. {
  15872. 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'))
  15873. {
  15874. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15875. goto end;
  15876. }
  15877. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  15878. {
  15879. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15880. goto end;
  15881. }
  15882. 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
  15883. {
  15884. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15885. goto end;
  15886. }
  15887. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15888. {
  15889. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15890. goto end;
  15891. }
  15892. }
  15893. } // END FOR CCS_QUANTITY
  15894. for (int index = 0; index < GB_QUANTITY; index++)
  15895. {
  15896. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15897. {
  15898. 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'))
  15899. {
  15900. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15901. goto end;
  15902. }
  15903. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15904. {
  15905. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15906. goto end;
  15907. }
  15908. 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
  15909. {
  15910. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15911. goto end;
  15912. }
  15913. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15914. {
  15915. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15916. goto end;
  15917. }
  15918. }
  15919. } // END FOR GB_QUANTITY
  15920. for (int index = 0; index < AC_QUANTITY; index++)
  15921. {
  15922. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15923. {
  15924. 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'))
  15925. {
  15926. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15927. goto end;
  15928. }
  15929. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15930. {
  15931. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15932. goto end;
  15933. }
  15934. 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
  15935. {
  15936. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15937. goto end;
  15938. }
  15939. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15940. {
  15941. 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))
  15942. {
  15943. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15944. goto end;
  15945. }
  15946. }
  15947. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15948. {
  15949. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15950. goto end;
  15951. }
  15952. }
  15953. }// END FOR AC_QUANTITY
  15954. //The connectorId is 0
  15955. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  15956. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15957. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  15958. result = TRUE;
  15959. return result;
  15960. }
  15961. else
  15962. {
  15963. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15964. }
  15965. if(strcmp((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  15966. {
  15967. strcpy((char *)ShmOCPP20Data->ReserveNow[evseIdInt-1].guid, uuid);
  15968. result = TRUE;
  15969. return result;
  15970. }
  15971. end:
  15972. sendReserveNowConfirmation(uuid, (evseIdInt==0?evseIdInt:evseIdInt-1));
  15973. return result;
  15974. }
  15975. int handleResetRequest(char *uuid, char *payload)
  15976. {
  15977. mtrace();
  15978. int result = FAIL;
  15979. json_object *Reset = json_object_new_object();
  15980. DEBUG_INFO("handleResetRequest...\n");
  15981. Reset = json_tokener_parse(payload);
  15982. ShmOCPP20Data->Reset.evseId = 0;
  15983. if(!is_error(Reset))
  15984. {
  15985. // Required data
  15986. if(json_object_object_get(Reset, "type") != NULL)
  15987. {
  15988. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  15989. }
  15990. if(json_object_object_get(Reset, "evseId") != NULL)
  15991. {
  15992. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  15993. }
  15994. }
  15995. json_object_put(Reset);
  15996. if((ShmOCPP20Data->Reset.evseId == 0) && ((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0)))
  15997. {
  15998. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  15999. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  16000. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  16001. result = PASS;
  16002. }
  16003. else
  16004. {
  16005. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  16006. }
  16007. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  16008. sendResetConfirmation(uuid);
  16009. return result;
  16010. }
  16011. int handleSendLocalListRequest(char *uuid, char *payload)
  16012. {
  16013. mtrace();
  16014. int result = FAIL;
  16015. int checkState_Faulted = FALSE;
  16016. json_object *SendLocalList;
  16017. DEBUG_INFO("handleSendLocalListRequest...\n");
  16018. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  16019. {
  16020. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  16021. goto end;
  16022. }
  16023. SendLocalList = json_tokener_parse(payload);
  16024. if(!is_error(SendLocalList))
  16025. {
  16026. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  16027. // Required data
  16028. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  16029. {
  16030. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  16031. }
  16032. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  16033. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  16034. // Optional data
  16035. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  16036. {
  16037. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  16038. {
  16039. // Required data
  16040. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  16041. {
  16042. 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")));
  16043. 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"))));
  16044. }
  16045. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  16046. {
  16047. 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"))));
  16048. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  16049. 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")));
  16050. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  16051. 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"));
  16052. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  16053. {
  16054. 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")));
  16055. 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")));
  16056. }
  16057. }
  16058. }
  16059. }
  16060. }
  16061. json_object_put(SendLocalList);
  16062. //check Charge Point state
  16063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16064. {
  16065. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  16066. {
  16067. checkState_Faulted = TRUE; //OCPP Status: Faulted
  16068. }
  16069. }
  16070. for (int index = 0; index < CCS_QUANTITY; index++)
  16071. {
  16072. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  16073. {
  16074. checkState_Faulted = TRUE; //OCPP Status
  16075. }
  16076. }
  16077. for (int index = 0; index < GB_QUANTITY; index++)
  16078. {
  16079. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  16080. {
  16081. checkState_Faulted = TRUE; //OCPP Status: Faulted
  16082. }
  16083. }
  16084. for (int index = 0; index < AC_QUANTITY; index++)
  16085. {
  16086. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  16087. {
  16088. checkState_Faulted = TRUE; //OCPP Status: Faulted
  16089. }
  16090. }
  16091. if(checkState_Faulted == TRUE)
  16092. {
  16093. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  16094. goto end;
  16095. }
  16096. // Check update type
  16097. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  16098. {
  16099. //Local list full update
  16100. DEBUG_INFO("Local list full update.\n");
  16101. DB_getListVerion();
  16102. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  16103. {
  16104. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  16105. goto end;
  16106. }*/
  16107. DB_cleanLocalList();
  16108. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  16109. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  16110. }
  16111. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  16112. {
  16113. //Local list different update
  16114. DEBUG_INFO("Local list different update.\n");
  16115. DB_getListVerion();
  16116. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  16117. {
  16118. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  16119. goto end;
  16120. }
  16121. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  16122. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  16123. }
  16124. else
  16125. {
  16126. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  16127. goto end;
  16128. }
  16129. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  16130. end:
  16131. sendSendLocalListConfirmation(uuid);
  16132. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16133. return result;
  16134. }
  16135. int handleSetChargingProfileRequest(char *uuid, char *payload)
  16136. {
  16137. mtrace();
  16138. int result = FAIL;
  16139. struct SetChargingProfile_20 SetProfileReq = {0};
  16140. uint8_t isLostEvseId = FALSE;
  16141. uint8_t isPeriodOverMax = FALSE;
  16142. uint8_t isStackOverMax = FALSE;
  16143. uint8_t isProfileOverMax = FALSE;
  16144. uint8_t isEvseMismatch = FALSE;
  16145. uint8_t isTransactiodIdMismatch = FALSE;
  16146. uint8_t isInvalidLimit = FALSE;
  16147. uint8_t isWrongFormat = FALSE;
  16148. uint8_t replaceableProfileCnt = 0;
  16149. uint8_t existProfileQuantity = 0;
  16150. uint8_t filename[128]={0};
  16151. uint8_t dataLine[4096]={0};
  16152. FILE *filePtr;
  16153. json_object *SetChargingProfile;
  16154. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  16155. SetChargingProfile = json_tokener_parse(payload);
  16156. if(!is_error(SetChargingProfile))
  16157. {
  16158. // Required data
  16159. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  16160. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  16161. else
  16162. isLostEvseId = TRUE;
  16163. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  16164. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  16165. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  16166. {
  16167. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  16168. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  16169. {
  16170. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  16171. }
  16172. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  16173. {
  16174. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  16175. }
  16176. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  16177. {
  16178. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  16179. }
  16180. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  16181. {
  16182. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  16183. }
  16184. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  16185. {
  16186. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  16187. }
  16188. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  16189. {
  16190. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  16191. }
  16192. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  16193. {
  16194. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  16195. }
  16196. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  16197. {
  16198. int chargingScheduleCount = 0;
  16199. int chargingSchedulePeriodCount = 0;
  16200. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  16201. {
  16202. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  16203. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  16204. {
  16205. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  16206. {
  16207. 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")));
  16208. }
  16209. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  16210. {
  16211. 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"));
  16212. }
  16213. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  16214. {
  16215. 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"));
  16216. }
  16217. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  16218. {
  16219. 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")));
  16220. }
  16221. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  16222. {
  16223. 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"));
  16224. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  16225. {
  16226. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  16227. {
  16228. 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)
  16229. {
  16230. 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"));
  16231. }
  16232. 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)
  16233. {
  16234. 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"));
  16235. }
  16236. 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)
  16237. {
  16238. 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"));
  16239. }
  16240. 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)
  16241. {
  16242. 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"));
  16243. }
  16244. // Check invalid limit
  16245. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  16246. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  16247. {
  16248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  16249. {
  16250. 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)))) ||
  16251. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  16252. {
  16253. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  16254. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  16255. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  16256. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  16257. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  16258. isInvalidLimit = TRUE;
  16259. }
  16260. }
  16261. else
  16262. {
  16263. 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) ||
  16264. (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)))
  16265. {
  16266. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  16267. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  16268. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  16269. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  16270. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  16271. isInvalidLimit = TRUE;
  16272. }
  16273. }
  16274. }
  16275. }
  16276. }
  16277. else
  16278. {
  16279. isPeriodOverMax = TRUE;
  16280. }
  16281. }
  16282. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff") != NULL)
  16283. {
  16284. 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)
  16285. {
  16286. 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"));
  16287. }
  16288. 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)
  16289. {
  16290. 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")));
  16291. }
  16292. 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)
  16293. {
  16294. 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"));
  16295. }
  16296. 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)
  16297. {
  16298. 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"));
  16299. if(cntEntry<=1024)
  16300. {
  16301. for(int idxEntry=0; idxEntry<cntEntry; idxEntry++)
  16302. {
  16303. 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)
  16304. {
  16305. 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"));
  16306. }
  16307. 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)
  16308. {
  16309. 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)
  16310. 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"));
  16311. 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)
  16312. 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"));
  16313. }
  16314. 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)
  16315. {
  16316. 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"));
  16317. if(cntConCost<=3)
  16318. {
  16319. for(uint8_t idxConCost=0; idxConCost<cntConCost; idxConCost++)
  16320. {
  16321. 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)
  16322. 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"));
  16323. 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)
  16324. {
  16325. 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"));
  16326. if(cntConCost<=3)
  16327. {
  16328. for(uint8_t idxCost=0; idxCost<cntCost; idxCost++)
  16329. {
  16330. 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)
  16331. 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")));
  16332. 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)
  16333. 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"));
  16334. 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)
  16335. 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"));
  16336. }
  16337. }
  16338. }
  16339. }
  16340. }
  16341. 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"));
  16342. }
  16343. }
  16344. }
  16345. }
  16346. }
  16347. }
  16348. }
  16349. else
  16350. {
  16351. isWrongFormat = TRUE;
  16352. }
  16353. }
  16354. // Check periods is over max configuration
  16355. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  16356. {
  16357. if(SetProfileReq.evseId == 0)
  16358. {
  16359. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  16360. filePtr = fopen((char*)filename, "r");
  16361. if (!filePtr)
  16362. {
  16363. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  16364. filePtr = fopen((char*)filename, "w+");
  16365. }
  16366. else
  16367. {
  16368. //Check Charging Profile Count
  16369. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16370. char *line = NULL;
  16371. size_t len = 0;
  16372. while(getline(&line, &len, filePtr) != -1)
  16373. {
  16374. json_object *obj = NULL;
  16375. obj = json_tokener_parse(line);
  16376. if(is_error(obj))
  16377. {
  16378. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  16379. }
  16380. else
  16381. {
  16382. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16383. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16384. {
  16385. existProfileQuantity += 1;
  16386. }
  16387. else
  16388. replaceableProfileCnt += 1;
  16389. }
  16390. //DEBUG_INFO("word=%s\n",word);
  16391. /*if(strstr((char*)dataLine, "id")!= NULL)
  16392. {
  16393. existProfileQuantity += 1;
  16394. }*/
  16395. }
  16396. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16397. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16398. {
  16399. isStackOverMax = TRUE;
  16400. }
  16401. }
  16402. fclose(filePtr);
  16403. }
  16404. else
  16405. isEvseMismatch = TRUE;
  16406. }
  16407. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  16408. {
  16409. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  16410. isEvseMismatch = TRUE;
  16411. if(!isEvseMismatch)
  16412. {
  16413. if(SetProfileReq.evseId == 0)
  16414. {
  16415. int tmpExistProfileQuantity;
  16416. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  16417. {
  16418. tmpExistProfileQuantity = 0;
  16419. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16420. filePtr = fopen((char*)filename, "r");
  16421. if (!filePtr)
  16422. {
  16423. DEBUG_INFO("%s not exist, create it.\n", filename);
  16424. filePtr = fopen((char*)filename, "w+");
  16425. }
  16426. else
  16427. {
  16428. //Check Charging Profile Count
  16429. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16430. char *line = NULL;
  16431. size_t len = 0;
  16432. while(getline(&line, &len, filePtr) != -1)
  16433. {
  16434. json_object *obj = NULL;
  16435. obj = json_tokener_parse(line);
  16436. if(is_error(obj))
  16437. {
  16438. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  16439. }
  16440. else
  16441. {
  16442. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16443. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16444. {
  16445. tmpExistProfileQuantity += 1;
  16446. }
  16447. else
  16448. replaceableProfileCnt += 1;
  16449. }
  16450. //DEBUG_INFO("word=%s\n",word);
  16451. /*if(strstr((char*)dataLine, "id")!= NULL)
  16452. {
  16453. tmpExistProfileQuantity += 1;
  16454. }*/
  16455. }
  16456. }
  16457. fclose(filePtr);
  16458. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16459. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16460. {
  16461. isStackOverMax = TRUE;
  16462. }
  16463. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  16464. }
  16465. }
  16466. else
  16467. {
  16468. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16469. filePtr = fopen((char*)filename, "r");
  16470. if (!filePtr)
  16471. {
  16472. DEBUG_INFO("%s not exist, create it.\n", filename);
  16473. filePtr = fopen((char*)filename, "w+");
  16474. }
  16475. else
  16476. {
  16477. //Check Charging Profile Count
  16478. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16479. char *line = NULL;
  16480. size_t len = 0;
  16481. while(getline(&line, &len, filePtr) != -1)
  16482. {
  16483. json_object *obj = NULL;
  16484. obj = json_tokener_parse(line);
  16485. if(is_error(obj))
  16486. {
  16487. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  16488. }
  16489. else
  16490. {
  16491. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16492. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16493. {
  16494. existProfileQuantity += 1;
  16495. }
  16496. else
  16497. replaceableProfileCnt += 1;
  16498. }
  16499. //DEBUG_INFO("word=%s\n",word);
  16500. /*if(strstr((char*)dataLine, "id")!= NULL)
  16501. {
  16502. existProfileQuantity += 1;
  16503. }*/
  16504. }
  16505. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16506. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16507. {
  16508. isStackOverMax = TRUE;
  16509. }
  16510. }
  16511. fclose(filePtr);
  16512. }
  16513. }
  16514. }
  16515. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  16516. {
  16517. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  16518. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16519. else
  16520. isEvseMismatch = TRUE;
  16521. if(!isEvseMismatch)
  16522. {
  16523. filePtr = fopen((char*)filename, "r");
  16524. if (!filePtr)
  16525. {
  16526. DEBUG_INFO("%s not exist, create it.\n", filename);
  16527. filePtr = fopen((char*)filename, "w+");
  16528. }
  16529. else
  16530. {
  16531. //Check Charging Profile Count
  16532. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16533. char *line = NULL;
  16534. size_t len = 0;
  16535. while(getline(&line, &len, filePtr) != -1)
  16536. {
  16537. json_object *obj = NULL;
  16538. obj = json_tokener_parse(line);
  16539. if(is_error(obj))
  16540. {
  16541. DEBUG_ERROR("Parse TxProfile from file error.\n");
  16542. }
  16543. else
  16544. {
  16545. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16546. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16547. {
  16548. existProfileQuantity += 1;
  16549. }
  16550. else
  16551. replaceableProfileCnt += 1;
  16552. }
  16553. //DEBUG_INFO("word=%s\n",word);
  16554. /*if(strstr((char*)dataLine, "id")!= NULL)
  16555. {
  16556. existProfileQuantity += 1;
  16557. }*/
  16558. }
  16559. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16560. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16561. {
  16562. isStackOverMax = TRUE;
  16563. }
  16564. }
  16565. fclose(filePtr);
  16566. if(strcmp((char*)SetProfileReq.chargingProfile.transactionId, (char*)ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId) != 0)
  16567. isTransactiodIdMismatch = TRUE;
  16568. }
  16569. }
  16570. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  16571. {
  16572. /*
  16573. * TODO:
  16574. *
  16575. */
  16576. }
  16577. else
  16578. {}
  16579. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  16580. {
  16581. FILE *fp;
  16582. char dataLine[4096]={0};
  16583. char fnametemp[128]={0};
  16584. int tmpProfileQuantity;
  16585. //Check ChargePointMaxProfile.json exit
  16586. existProfileQuantity = 0;
  16587. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  16588. {
  16589. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  16590. //Check Charging Profile Count
  16591. tmpProfileQuantity = 0;
  16592. while(fscanf(fp, "%s", dataLine) != EOF)
  16593. {
  16594. if(strstr(dataLine, "id")!= NULL)
  16595. {
  16596. existProfileQuantity += 1;
  16597. tmpProfileQuantity += 1;
  16598. }
  16599. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16600. }
  16601. fclose(fp);
  16602. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  16603. }
  16604. //Check TxDefaultProfile_%d.json
  16605. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16606. {
  16607. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16608. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16609. if((access(fnametemp,F_OK))!=-1)
  16610. {
  16611. fp = fopen(fnametemp, "r");
  16612. //Check Charging Profile Count
  16613. tmpProfileQuantity = 0;
  16614. while(fscanf(fp, "%s", dataLine) != EOF)
  16615. {
  16616. //DEBUG_INFO("word=%s\n",word);
  16617. if(strstr(dataLine, "id")!= NULL)
  16618. {
  16619. existProfileQuantity += 1;
  16620. tmpProfileQuantity += 1;
  16621. }
  16622. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16623. }
  16624. fclose(fp);
  16625. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16626. }
  16627. }
  16628. //Check TxProfile_%d.json
  16629. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16630. {
  16631. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16632. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  16633. if((access(fnametemp,F_OK))!=-1)
  16634. {
  16635. fp = fopen(fnametemp, "r");
  16636. //Check Charging Profile Count
  16637. tmpProfileQuantity = 0;
  16638. while(fscanf(fp, "%s", dataLine) != EOF)
  16639. {
  16640. if(strstr(dataLine, "id")!= NULL)
  16641. {
  16642. existProfileQuantity += 1;
  16643. tmpProfileQuantity += 1;
  16644. }
  16645. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16646. }
  16647. fclose(fp);
  16648. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16649. }
  16650. }
  16651. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  16652. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  16653. // To check total Profile quantity
  16654. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  16655. {
  16656. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16657. isProfileOverMax = TRUE;
  16658. }
  16659. else
  16660. {
  16661. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16662. isProfileOverMax = TRUE;
  16663. }
  16664. }
  16665. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  16666. }
  16667. // Profile replace or add info
  16668. if(!isLostEvseId && !isPeriodOverMax && !isProfileOverMax && !isEvseMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  16669. {
  16670. FILE *infile;
  16671. FILE *outfile;
  16672. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  16673. char rmFileCmd[128];
  16674. int tempchargingProfileIdInt;
  16675. int tempchargingProfileStackLevelInt;
  16676. int chkChar;
  16677. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  16678. {
  16679. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  16680. {
  16681. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  16682. }
  16683. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  16684. {
  16685. if(SetProfileReq.evseId==0)
  16686. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16687. else
  16688. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16689. }
  16690. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  16691. {
  16692. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16693. }
  16694. else
  16695. {
  16696. /*
  16697. * TODO:
  16698. *
  16699. */
  16700. }
  16701. infile = fopen ((char*)filename, "r");
  16702. outfile = fopen ((char*)tmpProfileName, "w");
  16703. chkChar = fgetc(infile);
  16704. rewind(infile);
  16705. if(chkChar == EOF)
  16706. {
  16707. // Profile is empty
  16708. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16709. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16710. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16711. fclose(infile);
  16712. fclose(outfile);
  16713. sprintf(rmFileCmd,"rm -f %s",filename);
  16714. system(rmFileCmd);
  16715. rename((char*)tmpProfileName, (char*)filename);
  16716. }
  16717. else
  16718. {
  16719. // Profile is not empty
  16720. int ChargingProfileAdded = FALSE;
  16721. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  16722. {
  16723. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  16724. json_object *tmpChargingProfile;
  16725. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  16726. if(!is_error(tmpChargingProfile))
  16727. {
  16728. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  16729. {
  16730. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  16731. {
  16732. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  16733. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  16734. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  16735. }
  16736. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  16737. {
  16738. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  16739. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  16740. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  16741. }
  16742. }
  16743. }
  16744. json_object_put(tmpChargingProfile);
  16745. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  16746. {
  16747. if(ChargingProfileAdded == FALSE)
  16748. {
  16749. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16750. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16751. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16752. ChargingProfileAdded = TRUE;
  16753. }
  16754. }
  16755. else
  16756. {
  16757. fprintf(outfile,"%s\n",dataLine);
  16758. if(ChargingProfileAdded == FALSE)
  16759. {
  16760. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16761. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16762. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16763. ChargingProfileAdded = TRUE;
  16764. }
  16765. }
  16766. } // end of while loop
  16767. fclose(infile);
  16768. fclose(outfile);
  16769. sprintf(rmFileCmd,"rm -f %s",filename);
  16770. system(rmFileCmd);
  16771. rename((char*)tmpProfileName, (char*)filename);
  16772. }
  16773. }
  16774. sleep(1);
  16775. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  16776. result = PASS;
  16777. }
  16778. else
  16779. {
  16780. if(isLostEvseId)
  16781. DEBUG_WARN("Connector id is wrong.\n");
  16782. if(isEvseMismatch)
  16783. DEBUG_WARN("Connector id is mismatch.\n");
  16784. if(isPeriodOverMax)
  16785. DEBUG_WARN("Profile periods quantity is over spec.\n");
  16786. if(isProfileOverMax)
  16787. DEBUG_WARN("Profile quantity is over spec.\n");
  16788. if(isTransactiodIdMismatch)
  16789. DEBUG_WARN("Transaction id is mismatch.\n");
  16790. if(isInvalidLimit)
  16791. DEBUG_WARN("Limit value is invalid.\n");
  16792. if(isStackOverMax)
  16793. DEBUG_WARN("Profile stack is over spec.\n");
  16794. if(isWrongFormat)
  16795. DEBUG_WARN("Profile format is wrong.\n");
  16796. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  16797. }
  16798. }
  16799. json_object_put(SetChargingProfile);
  16800. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  16801. {
  16802. if(SetProfileReq.evseId == 0)
  16803. {
  16804. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  16805. {
  16806. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  16807. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16808. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  16809. }
  16810. }
  16811. else
  16812. {
  16813. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  16814. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16815. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  16816. }
  16817. }
  16818. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  16819. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16820. return result;
  16821. }
  16822. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  16823. {
  16824. mtrace();
  16825. int result = FAIL;
  16826. json_object *SetDisplayMessage;
  16827. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  16828. SetDisplayMessage = json_tokener_parse(payload);
  16829. if(!is_error(SetDisplayMessage))
  16830. {
  16831. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  16832. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  16833. // Required data
  16834. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  16835. {
  16836. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  16837. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  16838. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  16839. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  16840. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  16841. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  16842. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  16843. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  16844. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  16845. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  16846. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  16847. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  16848. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  16849. {
  16850. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  16851. 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")));
  16852. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  16853. 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")));
  16854. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  16855. 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")));
  16856. }
  16857. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  16858. {
  16859. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  16860. 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")));
  16861. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  16862. 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")));
  16863. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  16864. {
  16865. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  16866. 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"));
  16867. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  16868. 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"));
  16869. }
  16870. }
  16871. }
  16872. }
  16873. json_object_put(SetDisplayMessage);
  16874. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  16875. sendSetDisplayMessagesConfirmation(uuid);
  16876. // Announce CSU there is display request come from server
  16877. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  16878. return result;
  16879. }
  16880. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  16881. {
  16882. mtrace();
  16883. int result = FAIL;
  16884. json_object *SetMonitoringBase;
  16885. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  16886. SetMonitoringBase = json_tokener_parse(payload);
  16887. if(!is_error(SetMonitoringBase))
  16888. {
  16889. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  16890. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  16891. // Required data
  16892. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  16893. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  16894. }
  16895. json_object_put(SetMonitoringBase);
  16896. /*
  16897. * TODO:
  16898. * 1. Configure monitor base and response
  16899. */
  16900. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  16901. sendSetMonitoringBaseConfirmation(uuid);
  16902. return result;
  16903. }
  16904. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  16905. {
  16906. mtrace();
  16907. int result = FAIL;
  16908. json_object *SetMonitoringLevel;
  16909. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  16910. SetMonitoringLevel = json_tokener_parse(payload);
  16911. if(!is_error(SetMonitoringLevel))
  16912. {
  16913. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  16914. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  16915. // Required data
  16916. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  16917. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  16918. }
  16919. json_object_put(SetMonitoringLevel);
  16920. /*
  16921. * TODO:
  16922. * Configure monitor status and response
  16923. */
  16924. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  16925. sendSetMonitoringLevelConfirmation(uuid);
  16926. return result;
  16927. }
  16928. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  16929. {
  16930. mtrace();
  16931. int result = FAIL;
  16932. json_object *SetNetworkProfile;
  16933. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  16934. SetNetworkProfile = json_tokener_parse(payload);
  16935. if(!is_error(SetNetworkProfile))
  16936. {
  16937. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  16938. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  16939. // Required data
  16940. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  16941. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  16942. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  16943. {
  16944. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  16945. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  16946. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  16947. {
  16948. if(strcmp(json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")), "JSON") == 0)
  16949. {
  16950. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  16951. }
  16952. else
  16953. {
  16954. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16955. goto end;
  16956. }
  16957. }
  16958. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  16959. {
  16960. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  16961. if((strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"wss", 3) == 0) || (strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"ws", 2) == 0))
  16962. {
  16963. char protocol[10], host[128], path[512], port[10];
  16964. int check = sscanf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"%[^:]:%*2[/]%[^:]:%[^/]/%199[^\n]", protocol, host, port, path);
  16965. if(check >= 3)
  16966. {
  16967. DEBUG_INFO("URL: %s\n", ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl);
  16968. DEBUG_INFO("protocol: %s\n",protocol);
  16969. DEBUG_INFO("host: %s\n",host);
  16970. DEBUG_INFO("port: %s\n",port);
  16971. DEBUG_INFO("path: %s\n",path);
  16972. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  16973. }
  16974. else
  16975. {
  16976. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16977. goto end;
  16978. }
  16979. }
  16980. else
  16981. {
  16982. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16983. goto end;
  16984. }
  16985. }
  16986. else
  16987. {
  16988. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16989. goto end;
  16990. }
  16991. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  16992. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  16993. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  16994. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  16995. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  16996. {
  16997. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  16998. 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")));
  16999. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  17000. 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")));
  17001. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  17002. 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")));
  17003. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  17004. 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")));
  17005. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  17006. 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")));
  17007. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  17008. 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")));
  17009. }
  17010. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  17011. {
  17012. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  17013. {
  17014. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  17015. 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")));
  17016. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  17017. }
  17018. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  17019. {
  17020. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  17021. 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")));
  17022. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  17023. }
  17024. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  17025. {
  17026. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  17027. 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")));
  17028. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  17029. }
  17030. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  17031. 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"));
  17032. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  17033. 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")));
  17034. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  17035. 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"));
  17036. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  17037. 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")));
  17038. }
  17039. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  17040. }
  17041. }
  17042. json_object_put(SetNetworkProfile);
  17043. /*
  17044. * TODO:
  17045. * 1. Process network configuration and response
  17046. */
  17047. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  17048. {
  17049. }
  17050. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  17051. {
  17052. }
  17053. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  17054. {
  17055. }
  17056. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  17057. {
  17058. }
  17059. else
  17060. {
  17061. }
  17062. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  17063. {
  17064. }
  17065. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  17066. {
  17067. }
  17068. else
  17069. {
  17070. }
  17071. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  17072. {
  17073. }
  17074. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  17075. {
  17076. }
  17077. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  17078. {
  17079. }
  17080. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  17081. {
  17082. }
  17083. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  17084. {
  17085. }
  17086. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  17087. {
  17088. }
  17089. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  17090. {
  17091. }
  17092. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  17093. {
  17094. }
  17095. else
  17096. {
  17097. }
  17098. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  17099. {
  17100. }
  17101. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  17102. {
  17103. }
  17104. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  17105. {
  17106. }
  17107. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  17108. {
  17109. }
  17110. else
  17111. {
  17112. }
  17113. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  17114. {
  17115. }
  17116. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  17117. {
  17118. }
  17119. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  17120. {
  17121. }
  17122. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  17123. {
  17124. }
  17125. else
  17126. {
  17127. }
  17128. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  17129. end:
  17130. sendSetNetworkProfileConfirmation(uuid);
  17131. return result;
  17132. }
  17133. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  17134. {
  17135. mtrace();
  17136. int result = FAIL;
  17137. json_object *SetVariableMonitoring;
  17138. uint8_t variableQuantity = 0;
  17139. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  17140. SetVariableMonitoring = json_tokener_parse(payload);
  17141. if(!is_error(SetVariableMonitoring))
  17142. {
  17143. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  17144. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  17145. // Required data
  17146. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  17147. {
  17148. variableQuantity++;
  17149. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  17150. {
  17151. 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"));
  17152. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  17153. }
  17154. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  17155. {
  17156. 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"));
  17157. }
  17158. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  17159. {
  17160. 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")));
  17161. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  17162. }
  17163. else
  17164. {
  17165. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  17166. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  17167. }
  17168. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  17169. {
  17170. 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"));
  17171. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  17172. }
  17173. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  17174. {
  17175. 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"));
  17176. }
  17177. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  17178. {
  17179. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  17180. {
  17181. 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")));
  17182. }
  17183. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  17184. {
  17185. 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")));
  17186. }
  17187. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  17188. {
  17189. 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)
  17190. {
  17191. 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"));
  17192. }
  17193. 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)
  17194. {
  17195. 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"));
  17196. }
  17197. }
  17198. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  17199. }
  17200. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  17201. {
  17202. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  17203. {
  17204. 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")));
  17205. }
  17206. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  17207. {
  17208. 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")));
  17209. }
  17210. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  17211. }
  17212. /*
  17213. * TODO
  17214. * Set Variables and save to DB
  17215. */
  17216. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  17217. }
  17218. }
  17219. json_object_put(SetVariableMonitoring);
  17220. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  17221. return result;
  17222. }
  17223. int handleSetVariablesRequest(char *uuid, char *payload)
  17224. {
  17225. mtrace();
  17226. uint8_t result = FAIL;
  17227. uint8_t isUnknownComponent = TRUE;
  17228. uint8_t isNeedReconnect = FALSE;
  17229. json_object *SetVariables;
  17230. DEBUG_INFO("handleSetVariablesRequest...\n");
  17231. SetVariables = json_tokener_parse(payload);
  17232. if(!is_error(SetVariables))
  17233. {
  17234. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  17235. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  17236. // Required data
  17237. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  17238. {
  17239. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  17240. {
  17241. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  17242. {
  17243. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  17244. {
  17245. 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")));
  17246. }
  17247. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  17248. {
  17249. 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")));
  17250. }
  17251. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  17252. {
  17253. 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)
  17254. {
  17255. 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"));
  17256. }
  17257. 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)
  17258. {
  17259. 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"));
  17260. }
  17261. }
  17262. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  17263. }
  17264. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  17265. {
  17266. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  17267. {
  17268. 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")));
  17269. }
  17270. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  17271. {
  17272. 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")));
  17273. }
  17274. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  17275. }
  17276. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  17277. {
  17278. 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")));
  17279. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  17280. }
  17281. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  17282. {
  17283. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  17284. }
  17285. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  17286. {
  17287. 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")));
  17288. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  17289. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  17290. {
  17291. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  17292. (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) &&
  17293. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  17294. (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))
  17295. {
  17296. isUnknownComponent = FALSE;
  17297. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17298. //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);
  17299. if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_decimal]) == 0)
  17300. {
  17301. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,TRUE)!=YES)
  17302. {
  17303. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17304. break;
  17305. }
  17306. }
  17307. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_integer]) == 0)
  17308. {
  17309. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, FALSE)!=YES)
  17310. {
  17311. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17312. break;
  17313. }
  17314. }
  17315. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_dateTime]) == 0)
  17316. {
  17317. if(isMatchTimeFormat(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)!=YES)
  17318. {
  17319. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17320. break;
  17321. }
  17322. }
  17323. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_boolean]) == 0)
  17324. {
  17325. // To make sure all boolean value is in uppercase
  17326. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true") != NULL) ||
  17327. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"True") != NULL) ||
  17328. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"TRUE") != NULL))
  17329. {
  17330. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true");
  17331. }
  17332. else if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false") != NULL) ||
  17333. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"False") != NULL) ||
  17334. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"FALSE") != NULL))
  17335. {
  17336. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false");
  17337. }
  17338. else
  17339. {
  17340. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17341. break;
  17342. }
  17343. }
  17344. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  17345. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  17346. {
  17347. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  17348. break;
  17349. }
  17350. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  17351. {
  17352. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17353. break;
  17354. }
  17355. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AuthCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Enabled") != NULL))
  17356. {
  17357. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17358. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17359. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17360. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17361. {
  17362. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17363. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17364. if(strstr((char*)tmp, "true") != NULL)
  17365. {
  17366. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
  17367. }
  17368. else
  17369. {
  17370. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
  17371. }
  17372. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17373. }
  17374. else
  17375. {
  17376. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17377. break;
  17378. }
  17379. }
  17380. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  17381. {
  17382. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  17383. }
  17384. else
  17385. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17386. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  17387. {
  17388. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  17389. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17390. else
  17391. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17392. }
  17393. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  17394. {
  17395. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17396. {
  17397. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17398. }
  17399. else
  17400. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17401. }
  17402. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  17403. {
  17404. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17405. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17406. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17407. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17408. {
  17409. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17410. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17411. }
  17412. else
  17413. {
  17414. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17415. break;
  17416. }
  17417. }
  17418. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  17419. {
  17420. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17421. {
  17422. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17423. }
  17424. else
  17425. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17426. }
  17427. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "CharingProfileRefreshInterval") != NULL))
  17428. {
  17429. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17430. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17431. else
  17432. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17433. }
  17434. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "MessageAttempts") != NULL))
  17435. {
  17436. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17437. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17438. else
  17439. {
  17440. TransactionMessageAttemptsValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17441. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17442. }
  17443. }
  17444. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "MessageAttemptInterval") != NULL))
  17445. {
  17446. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17447. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17448. else
  17449. {
  17450. TransactionMessageRetryIntervalValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17451. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17452. }
  17453. }
  17454. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "RfidEndianType") != NULL))
  17455. {
  17456. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17457. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17458. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17459. if((strstr((char*)tmp, "big") != NULL) || (strstr((char*)tmp, "little") != NULL))
  17460. {
  17461. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "big") != NULL)? "big" : "little");
  17462. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strstr((char*)tmp, "big") != NULL)?1:0;
  17463. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17464. }
  17465. else
  17466. {
  17467. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17468. break;
  17469. }
  17470. }
  17471. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "AuthorizeTimeout") != NULL))
  17472. {
  17473. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) <=0) ||
  17474. (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) ||
  17475. (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.maxLimit))
  17476. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17477. else
  17478. {
  17479. TransactionMessageRetryIntervalValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17480. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17481. }
  17482. }
  17483. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "EnableAcCcs") != NULL))
  17484. {
  17485. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17486. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17487. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17488. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17489. {
  17490. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17491. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17492. }
  17493. else
  17494. {
  17495. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17496. break;
  17497. }
  17498. }
  17499. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  17500. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  17501. {
  17502. isNeedReconnect = TRUE;
  17503. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17504. //SetOcppConnStatus(FALSE);
  17505. }
  17506. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  17507. {
  17508. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17509. {
  17510. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17511. }
  17512. else
  17513. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17514. }
  17515. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SendDuringIdle") != NULL))
  17516. {
  17517. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17518. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17519. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17520. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17521. {
  17522. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17523. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17524. }
  17525. else
  17526. {
  17527. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17528. break;
  17529. }
  17530. }
  17531. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SignReadings") != NULL))
  17532. {
  17533. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17534. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17535. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17536. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17537. {
  17538. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17539. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17540. }
  17541. else
  17542. {
  17543. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17544. break;
  17545. }
  17546. }
  17547. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  17548. {
  17549. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17550. {
  17551. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17552. }
  17553. else
  17554. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17555. }
  17556. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  17557. {
  17558. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17559. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17560. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17561. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17562. {
  17563. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17564. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  17565. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17566. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17567. }
  17568. }
  17569. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  17570. {
  17571. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  17572. {
  17573. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17574. }
  17575. else
  17576. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17577. }
  17578. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "OffLineMaxChargingPower") != NULL))
  17579. {
  17580. if(atoi((const char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > modelnameInfo.ratedPower)
  17581. {
  17582. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17583. }
  17584. else
  17585. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17586. }
  17587. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  17588. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  17589. {
  17590. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17591. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  17592. }
  17593. break;
  17594. }
  17595. else
  17596. {
  17597. // When there is no matched variable, check the component name again
  17598. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  17599. {
  17600. isUnknownComponent = FALSE;
  17601. }
  17602. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  17603. }
  17604. }
  17605. if(isUnknownComponent == TRUE)
  17606. {
  17607. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  17608. }
  17609. }
  17610. }
  17611. }
  17612. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17613. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  17614. if(isNeedReconnect)
  17615. {
  17616. SetOcppConnStatus(FALSE);
  17617. }
  17618. }
  17619. json_object_put(SetVariables);
  17620. return result;
  17621. }
  17622. int handleTriggerMessageRequest(char *uuid, char *payload)
  17623. {
  17624. mtrace();
  17625. int result = FAIL;
  17626. int evseIdIsNULL = FALSE;
  17627. //int connectorIdIsNULL = FALSE;
  17628. int evseIdInt =0;
  17629. //int connectorIdInt =0;
  17630. json_object *TriggerMessage;
  17631. DEBUG_INFO("handleTriggerMessageRequest\n");
  17632. TriggerMessage = json_tokener_parse(payload);
  17633. if(!is_error(TriggerMessage))
  17634. {
  17635. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  17636. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  17637. // Required data
  17638. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  17639. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  17640. // Optional data
  17641. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  17642. {
  17643. // Required data
  17644. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  17645. {
  17646. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  17647. evseIdInt = ShmOCPP20Data->TriggerMessage.evse.id;
  17648. }
  17649. else
  17650. evseIdIsNULL = TRUE;
  17651. // Optional data
  17652. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  17653. {
  17654. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  17655. //connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  17656. }
  17657. //else
  17658. //connectorIdIsNULL = TRUE;
  17659. }
  17660. else
  17661. evseIdIsNULL = TRUE;
  17662. }
  17663. json_object_put(TriggerMessage);
  17664. if((evseIdIsNULL == TRUE) || ((evseIdIsNULL == FALSE) && ((evseIdInt > 0) && (evseIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  17665. {
  17666. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  17667. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  17668. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  17669. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  17670. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  17671. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  17672. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  17673. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  17674. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  17675. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  17676. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  17677. {
  17678. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  17679. sendTriggerMessageConfirmation(uuid);
  17680. return TRUE;
  17681. }
  17682. else
  17683. {
  17684. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  17685. sendTriggerMessageConfirmation(uuid);
  17686. }
  17687. }
  17688. else if(evseIdIsNULL == FALSE && ((evseIdInt <= 0) || (evseIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  17689. {
  17690. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17691. sendTriggerMessageConfirmation(uuid);
  17692. return TRUE;
  17693. }
  17694. //==========================
  17695. // Trigger message
  17696. //==========================
  17697. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  17698. {
  17699. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  17700. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  17701. {
  17702. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  17703. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17704. }
  17705. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17706. }
  17707. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  17708. {
  17709. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  17710. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  17711. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  17712. }
  17713. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  17714. {
  17715. if(server_sign)
  17716. {
  17717. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17718. sendTriggerMessageConfirmation(uuid);
  17719. return TRUE;
  17720. }
  17721. else
  17722. {
  17723. if(DB_updateBootType(BootReasonEnumType_Triggered))
  17724. server_sign = FALSE;
  17725. }
  17726. }
  17727. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  17728. {
  17729. refreshStartTimer(&clientTime.Heartbeat);
  17730. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  17731. }
  17732. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  17733. {
  17734. if(evseIdIsNULL == FALSE)
  17735. {
  17736. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17737. {
  17738. cpinitateMsg.bits[evseIdInt-1].TriggerMeterValueReq = ON;
  17739. }
  17740. }
  17741. else
  17742. {
  17743. for(int idx=0;idx< gunTotalNumber;idx++)
  17744. {
  17745. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  17746. }
  17747. }
  17748. }
  17749. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  17750. {
  17751. if(evseIdIsNULL == FALSE)
  17752. {
  17753. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17754. {
  17755. cpinitateMsg.bits[evseIdInt-1].TriggerStatusNotificationReq = ON;
  17756. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  17757. }
  17758. }
  17759. else
  17760. {
  17761. for(int idx=0;idx< gunTotalNumber;idx++)
  17762. {
  17763. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  17764. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  17765. }
  17766. }
  17767. }
  17768. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  17769. {
  17770. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17771. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17772. {
  17773. 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\" &");
  17774. }
  17775. }
  17776. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  17777. {
  17778. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17779. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17780. {
  17781. 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\" &");
  17782. }
  17783. }
  17784. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  17785. {
  17786. if(evseIdIsNULL == FALSE)
  17787. {
  17788. if((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber))
  17789. {
  17790. //ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  17791. cpinitateMsg.bits[evseIdInt -1].TriggerTransactionEventReq = ON;
  17792. }
  17793. }
  17794. else
  17795. {
  17796. for(int idx=0;idx< gunTotalNumber;idx++)
  17797. {
  17798. //ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  17799. cpinitateMsg.bits[idx].TriggerTransactionEventReq = ON;
  17800. }
  17801. }
  17802. }
  17803. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  17804. {
  17805. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17806. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17807. {
  17808. 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\" &");
  17809. }
  17810. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17811. {
  17812. 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\" &");
  17813. }
  17814. }
  17815. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  17816. {
  17817. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  17818. }
  17819. return result;
  17820. }
  17821. int handleUnlockConnectorRequest(char *uuid, char *payload)
  17822. {
  17823. mtrace();
  17824. int result = FAIL;
  17825. int evseIdInt =0;
  17826. int tempIndex = 0;
  17827. json_object *UnlockConnector;
  17828. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  17829. UnlockConnector = json_tokener_parse(payload);
  17830. if(!is_error(UnlockConnector))
  17831. {
  17832. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  17833. {
  17834. evseIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  17835. ShmOCPP20Data->UnlockConnector[(evseIdInt>0?evseIdInt-1:0)].evseId = evseIdInt;
  17836. //it should not be array!!
  17837. }
  17838. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  17839. {
  17840. if(json_object_get_int(json_object_object_get(UnlockConnector, "connectorId")) != 1)
  17841. {
  17842. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17843. goto end;
  17844. }
  17845. }
  17846. }
  17847. json_object_put(UnlockConnector);
  17848. DEBUG_INFO("Unlock evseIdInt = %d\n",evseIdInt);
  17849. if(gunTotalNumber == 0)
  17850. {
  17851. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17852. goto end;
  17853. }
  17854. else if((evseIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (evseIdInt <= 0))
  17855. {
  17856. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17857. goto end;
  17858. }
  17859. else
  17860. {
  17861. memset(&ShmOCPP20Data->UnlockConnector[evseIdInt-1], 0, sizeof(struct UnlockConnector_20));
  17862. memcpy(&ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid));
  17863. //check Transaction active
  17864. if(gunType[evseIdInt-1] == GUN_TYPE_CHAdeMO)
  17865. {
  17866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17867. {
  17868. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17869. }
  17870. else
  17871. {
  17872. tempIndex = evseIdInt -1;
  17873. }
  17874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17875. {
  17876. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  17877. {
  17878. //stop Transaction
  17879. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17880. }
  17881. }
  17882. }
  17883. else if(gunType[evseIdInt-1] == GUN_TYPE_CCS)
  17884. {
  17885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17886. {
  17887. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17888. }
  17889. else
  17890. {
  17891. tempIndex = evseIdInt -1;
  17892. }
  17893. for (int index = 0; index < CCS_QUANTITY; index++)
  17894. {
  17895. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  17896. {
  17897. //stop Transaction
  17898. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17899. }
  17900. }
  17901. }
  17902. else if(gunType[evseIdInt-1] == GUN_TYPE_GBT)
  17903. {
  17904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17905. {
  17906. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17907. }
  17908. else
  17909. {
  17910. tempIndex = evseIdInt -1;
  17911. }
  17912. for (int index = 0; index < GB_QUANTITY; index++)
  17913. {
  17914. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  17915. {
  17916. //stop Transaction
  17917. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17918. }
  17919. }
  17920. }
  17921. else if(gunType[evseIdInt-1] == GUN_TYPE_DO)
  17922. {
  17923. tempIndex = evseIdInt -1;
  17924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17925. {
  17926. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  17927. {
  17928. //stop Transaction
  17929. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17930. }
  17931. }
  17932. }
  17933. else
  17934. {
  17935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17936. {
  17937. tempIndex = 2;
  17938. }
  17939. else
  17940. {
  17941. tempIndex = evseIdInt-1;
  17942. }
  17943. for (int index = 0; index < AC_QUANTITY; index++)
  17944. {
  17945. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  17946. {
  17947. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17948. }
  17949. }
  17950. }
  17951. ShmOCPP20Data->UnlockConnector[evseIdInt-1].connectorId = evseIdInt;
  17952. strcpy((char *)ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid);
  17953. result = TRUE;
  17954. return result;
  17955. }
  17956. end:
  17957. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorConf = ON;
  17958. return result;
  17959. }
  17960. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  17961. {
  17962. mtrace();
  17963. int result = FAIL;
  17964. json_object *UnpublishFirmware;
  17965. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  17966. UnpublishFirmware = json_tokener_parse(payload);
  17967. if(!is_error(UnpublishFirmware))
  17968. {
  17969. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  17970. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  17971. // Required data
  17972. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  17973. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  17974. }
  17975. json_object_put(UnpublishFirmware);
  17976. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  17977. /*
  17978. * TODO:
  17979. * 1. Check unpublished status
  17980. */
  17981. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  17982. sendUnpublishFirmwareConfirmation(uuid);
  17983. return result;
  17984. }
  17985. static char UpdateFirmwarepayloadData[512]={0};
  17986. void *UpdateFirmwareProcess(void *data)
  17987. {
  17988. pthread_detach(pthread_self());
  17989. mtrace();
  17990. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  17991. int port=0;
  17992. int isSuccess = 0;
  17993. char ftpbuf[1024];
  17994. char temp[1024];
  17995. char * pch;
  17996. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  17997. json_object *UpdateFirmware;
  17998. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  17999. if(!is_error(UpdateFirmware))
  18000. {
  18001. // Required data
  18002. if(json_object_object_get(UpdateFirmware, "requestId"))
  18003. {
  18004. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  18005. }
  18006. if(json_object_object_get(UpdateFirmware, "firmware"))
  18007. {
  18008. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  18009. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  18010. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  18011. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  18012. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  18013. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  18014. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  18015. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  18016. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  18017. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  18018. }
  18019. // Optional data
  18020. if(json_object_object_get(UpdateFirmware, "retries"))
  18021. {
  18022. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  18023. }
  18024. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  18025. {
  18026. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  18027. }
  18028. }
  18029. json_object_put(UpdateFirmware);
  18030. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  18031. memset(path, 0, ARRAY_SIZE(path));
  18032. // Wait retrieveData
  18033. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  18034. {
  18035. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18036. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  18037. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18038. do
  18039. {
  18040. sleep(1);
  18041. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  18042. }
  18043. system("rm -f /mnt/*");
  18044. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  18045. {
  18046. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  18047. sprintf(ftppath,"/%s", path);
  18048. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  18049. DEBUG_INFO("protocol: %s\n",protocol);
  18050. DEBUG_INFO("host: %s\n",host);
  18051. DEBUG_INFO("path: %s\n",path);
  18052. DEBUG_INFO("ftppath: %s\n",ftppath);
  18053. int ftppathlen=strlen(ftppath);
  18054. int i=1;
  18055. char filenametemp[50];
  18056. while(i < ftppathlen)
  18057. {
  18058. int len=ftppathlen-i;
  18059. if(ftppath[len]== 47) // '/' ascll code: 47
  18060. {
  18061. DEBUG_INFO("compare '/' all right\n");
  18062. break;
  18063. }
  18064. i=i+1;
  18065. }
  18066. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  18067. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  18068. filenametemp[i+1] = 0;
  18069. do
  18070. {
  18071. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18072. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  18073. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18074. sleep(3);
  18075. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  18076. if(!isSuccess)
  18077. {
  18078. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18079. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  18080. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18081. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  18082. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18083. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  18084. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18085. }
  18086. else
  18087. {
  18088. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18089. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  18090. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18091. }
  18092. ShmOCPP20Data->UpdateFirmware.retries--;
  18093. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  18094. }
  18095. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  18096. {
  18097. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18098. memset(temp, 0, ARRAY_SIZE(temp));
  18099. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  18100. int ftppathlen=strlen(ftpbuf);
  18101. int i=1;
  18102. char filenametemp[50];
  18103. while(i < ftppathlen)
  18104. {
  18105. int len=ftppathlen-i;
  18106. if(ftpbuf[len]== 47) // '/' ascll code: 47
  18107. {
  18108. DEBUG_INFO(" compare '/' all right\n");
  18109. break;
  18110. }
  18111. i=i+1;
  18112. }
  18113. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  18114. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  18115. filenametemp[i+1] = 0;
  18116. strncpy(temp, ftpbuf, ftppathlen-i+1);
  18117. pch=strchr(temp,'@');
  18118. if(pch==NULL)
  18119. {
  18120. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18121. protocol, host, &port, path);
  18122. strcpy(user,"anonymous");
  18123. strcpy(password,"");
  18124. }
  18125. else
  18126. {
  18127. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  18128. protocol, user, password, host, &port, path);
  18129. }
  18130. sscanf(host,"%[^/]%s",host1, path1);
  18131. sprintf(ftppath,"%s", path1);
  18132. if(port == 0)
  18133. {
  18134. port = 21;
  18135. }
  18136. do
  18137. {
  18138. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18139. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  18140. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18141. sleep(3);
  18142. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  18143. if(!isSuccess)
  18144. {
  18145. //BulldogUtil.sleepMs(interval*1000);
  18146. DEBUG_INFO("Update firmware request and download file fail.\n");
  18147. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18148. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  18149. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18150. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  18151. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18152. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  18153. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18154. }
  18155. else
  18156. {
  18157. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18158. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  18159. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18160. }
  18161. ShmOCPP20Data->UpdateFirmware.retries--;
  18162. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  18163. }
  18164. else
  18165. {
  18166. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18167. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  18168. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18169. sleep(1);
  18170. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18171. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  18172. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18173. }
  18174. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  18175. interLock.isUpdateFirmwareGoing = OFF;
  18176. pthread_exit(NULL);
  18177. }
  18178. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  18179. {
  18180. mtrace();
  18181. int result = FAIL;
  18182. pthread_t t;
  18183. sendUpdateFirmwareConfirmation(uuid);
  18184. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  18185. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  18186. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  18187. if(!interLock.isUpdateFirmwareGoing)
  18188. {
  18189. interLock.isUpdateFirmwareGoing = ON;
  18190. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  18191. sleep(1);
  18192. }
  18193. else
  18194. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  18195. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  18196. return result;
  18197. }
  18198. int handleUnknownRequest(char *uuid, char *payload)
  18199. {
  18200. mtrace();
  18201. int result = FAIL;
  18202. DEBUG_INFO("handleUnknownRequest...\n");
  18203. sendUnknownConfirmation(uuid);
  18204. result = PASS;
  18205. return result;
  18206. }
  18207. //==========================================
  18208. // Handle server response routine
  18209. //==========================================
  18210. void handleAuthorizeResponse(char *payload, int gun_index)
  18211. {
  18212. mtrace();
  18213. DEBUG_INFO("handleAuthorizeResponse...\n");
  18214. json_object *Authorize;
  18215. Authorize = json_tokener_parse(payload);
  18216. if(!is_error(Authorize))
  18217. {
  18218. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  18219. {
  18220. // Required data
  18221. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  18222. // Optional data
  18223. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  18224. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  18225. else
  18226. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  18227. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority") != NULL)
  18228. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  18229. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1") != NULL)
  18230. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  18231. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "evseId") != NULL)
  18232. {
  18233. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTokenInfo"), "evseId"));idx++)
  18234. {
  18235. 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));
  18236. }
  18237. }
  18238. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2") != NULL)
  18239. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  18240. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken") != NULL)
  18241. {
  18242. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  18243. 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")));
  18244. else
  18245. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  18246. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  18247. 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")));
  18248. }
  18249. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage") != NULL)
  18250. {
  18251. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  18252. 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")));
  18253. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  18254. 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")));
  18255. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  18256. 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")));
  18257. }
  18258. }
  18259. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  18260. {
  18261. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  18262. }
  18263. }
  18264. json_object_put(Authorize);
  18265. //Update idTag information to authorization cache if supported
  18266. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  18267. /*(strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  18268. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&*/
  18269. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  18270. {
  18271. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  18272. }
  18273. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  18274. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  18275. authorizeRetryTimes = 0;
  18276. }
  18277. void handleBootNotificationResponse(char *payload, int gun_index)
  18278. {
  18279. mtrace();
  18280. char statusStr[12]={0};
  18281. char currentTimeStr[30]={0};
  18282. int intervalInt = 0;
  18283. DEBUG_INFO("handleBootNotificationResponse...\n");
  18284. json_object *BootNotification;
  18285. BootNotification = json_tokener_parse(payload);
  18286. if(!is_error(BootNotification))
  18287. {
  18288. // Required data
  18289. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  18290. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  18291. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  18292. }
  18293. json_object_put(BootNotification);
  18294. DEBUG_INFO("statusStr: %s\n", statusStr);
  18295. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  18296. BootNotificationInterval = intervalInt;
  18297. //write back to ShmOCPP20Data->BootNotification
  18298. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  18299. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  18300. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  18301. {
  18302. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  18303. {
  18304. //Do nothing because the value is out of range.
  18305. }
  18306. else
  18307. {
  18308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  18309. HeartBeatWaitTime = intervalInt;
  18310. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  18311. }
  18312. server_sign = TRUE;
  18313. server_pending =FALSE;
  18314. DB_updateBootType(BootReasonEnumType_PowerUp);
  18315. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  18316. }
  18317. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  18318. {
  18319. server_pending = TRUE;
  18320. }
  18321. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  18322. srand(time(NULL));
  18323. refreshStartTimer(&clientTime.Heartbeat);
  18324. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  18325. SetOcppConnStatus(TRUE);
  18326. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  18327. }
  18328. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  18329. {
  18330. mtrace();
  18331. json_object *ClearedChargingLimit;
  18332. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  18333. ClearedChargingLimit = json_tokener_parse(payload);
  18334. if(!is_error(ClearedChargingLimit))
  18335. {
  18336. // Required data
  18337. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  18338. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  18339. }
  18340. json_object_put(ClearedChargingLimit);
  18341. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  18342. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  18343. }
  18344. void handleDataTransferResponse(char *payload, int gun_index)
  18345. {
  18346. mtrace();
  18347. json_object *DataTrans;
  18348. DEBUG_INFO("handleDataTransferResponse...\n");
  18349. DataTrans = json_tokener_parse(payload);
  18350. if(!is_error(DataTrans))
  18351. {
  18352. // Required data
  18353. if(json_object_object_get(DataTrans,"status") != NULL)
  18354. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  18355. // Optional data
  18356. if(json_object_object_get(DataTrans,"data") != NULL)
  18357. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  18358. }
  18359. json_object_put(DataTrans);
  18360. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  18361. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  18362. }
  18363. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  18364. {
  18365. mtrace();
  18366. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  18367. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  18368. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  18369. }
  18370. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  18371. {
  18372. mtrace();
  18373. json_object *Get15118EVCertificate;
  18374. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  18375. Get15118EVCertificate = json_tokener_parse(payload);
  18376. if(!is_error(Get15118EVCertificate))
  18377. {
  18378. // Required data
  18379. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  18380. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  18381. // Optional data
  18382. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  18383. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  18384. }
  18385. json_object_put(Get15118EVCertificate);
  18386. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  18387. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  18388. }
  18389. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  18390. {
  18391. mtrace();
  18392. json_object *GetCertificateStatus;
  18393. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  18394. GetCertificateStatus = json_tokener_parse(payload);
  18395. if(!is_error(GetCertificateStatus))
  18396. {
  18397. // Required data
  18398. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  18399. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  18400. // Optional data
  18401. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  18402. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  18403. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  18404. {
  18405. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  18406. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  18407. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  18408. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  18409. }
  18410. }
  18411. json_object_put(GetCertificateStatus);
  18412. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  18413. {
  18414. /*
  18415. * TODO:
  18416. * 1. If get certificate response accepted process something here
  18417. */
  18418. }
  18419. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  18420. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  18421. }
  18422. void handleHeartbeatResponse(char *payload, int gun_index)
  18423. {
  18424. mtrace();
  18425. DEBUG_INFO("handleHeartbeatResponse...\n");
  18426. json_object *Heartbeat;
  18427. Heartbeat = json_tokener_parse(payload);
  18428. if(!is_error(Heartbeat))
  18429. {
  18430. // Required data
  18431. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  18432. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  18433. }
  18434. json_object_put(Heartbeat);
  18435. if(FirstHeartBeat == OFF)
  18436. {
  18437. FirstHeartBeat = ON;
  18438. DEBUG_INFO("FirstHeartBeat \n");
  18439. }
  18440. HeartBeatWithNOResponse = 0;
  18441. refreshStartTimer(&clientTime.Heartbeat);
  18442. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  18443. }
  18444. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  18445. {
  18446. mtrace();
  18447. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  18448. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  18449. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  18450. }
  18451. void handleMeterValuesResponse(char *payload, int gun_index)
  18452. {
  18453. mtrace();
  18454. DEBUG_INFO("handleMeterValuesResponse...\n");
  18455. isQueueSendable = ON;
  18456. }
  18457. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  18458. {
  18459. mtrace();
  18460. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  18461. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  18462. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  18463. }
  18464. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  18465. {
  18466. mtrace();
  18467. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  18468. }
  18469. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  18470. {
  18471. mtrace();
  18472. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  18473. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  18474. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  18475. }
  18476. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  18477. {
  18478. mtrace();
  18479. json_object *NotifyEVChargingNeeds;
  18480. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  18481. NotifyEVChargingNeeds = json_tokener_parse(payload);
  18482. if(!is_error(NotifyEVChargingNeeds))
  18483. {
  18484. // Required data
  18485. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  18486. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  18487. }
  18488. json_object_put(NotifyEVChargingNeeds);
  18489. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  18490. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  18491. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  18492. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsConf = ON;
  18493. }
  18494. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  18495. {
  18496. mtrace();
  18497. json_object *NotifyEVChargingSchedule;
  18498. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  18499. NotifyEVChargingSchedule = json_tokener_parse(payload);
  18500. if(!is_error(NotifyEVChargingSchedule))
  18501. {
  18502. // Required data
  18503. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  18504. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  18505. }
  18506. json_object_put(NotifyEVChargingSchedule);
  18507. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  18508. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleConf = ON;
  18509. }
  18510. void handleNotifyEventResponse(char *payload, int gun_index)
  18511. {
  18512. mtrace();
  18513. DEBUG_INFO("handleNotifyEventResponse...\n");
  18514. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  18515. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  18516. }
  18517. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  18518. {
  18519. mtrace();
  18520. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  18521. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  18522. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  18523. }
  18524. void handleNotifyReportResponse(char *payload, int gun_index)
  18525. {
  18526. mtrace();
  18527. DEBUG_INFO("handleNotifyReportResponse...\n");
  18528. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  18529. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  18530. }
  18531. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  18532. {
  18533. mtrace();
  18534. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  18535. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  18536. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  18537. }
  18538. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  18539. {
  18540. mtrace();
  18541. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  18542. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  18543. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  18544. }
  18545. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  18546. {
  18547. mtrace();
  18548. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  18549. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  18550. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  18551. }
  18552. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  18553. {
  18554. mtrace();
  18555. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  18556. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  18557. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  18558. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  18559. }
  18560. void handleSignCertificateResponse(char *payload, int gun_index)
  18561. {
  18562. mtrace();
  18563. json_object *SignCertificate;
  18564. DEBUG_INFO("handleSignCertificateResponse...\n");
  18565. SignCertificate = json_tokener_parse(payload);
  18566. if(!is_error(SignCertificate))
  18567. {
  18568. // Required data
  18569. if(json_object_object_get(SignCertificate,"status") != NULL)
  18570. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  18571. // Optional data
  18572. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  18573. {
  18574. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  18575. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  18576. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  18577. }
  18578. }
  18579. json_object_put(SignCertificate);
  18580. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  18581. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  18582. }
  18583. void handleStatusNotificationResponse(char *payload, int gun_index)
  18584. {
  18585. mtrace();
  18586. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  18587. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  18588. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  18589. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  18590. }
  18591. void handleTransactionEventResponse(char *payload, int gun_index)
  18592. {
  18593. mtrace();
  18594. json_object *TransactionEven;
  18595. DEBUG_INFO("handleTransactionEventResponse...\n");
  18596. TransactionEven = json_tokener_parse(payload);
  18597. if(!is_error(TransactionEven))
  18598. {
  18599. // Required data
  18600. // Optional data
  18601. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  18602. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  18603. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  18604. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  18605. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  18606. {
  18607. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  18608. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  18609. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  18610. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  18611. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  18612. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  18613. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  18614. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  18615. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  18616. {
  18617. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  18618. 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")));
  18619. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  18620. 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")));
  18621. }
  18622. }
  18623. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  18624. {
  18625. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  18626. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  18627. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  18628. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  18629. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  18630. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  18631. }
  18632. }
  18633. json_object_put(TransactionEven);
  18634. isQueueSendable = ON;
  18635. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  18636. }
  18637. //==========================================
  18638. // Handle Error routine
  18639. //==========================================
  18640. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  18641. {
  18642. mtrace();
  18643. #ifdef SystemLogMessage
  18644. DEBUG_INFO("errorCode: %s\n", errorCode);
  18645. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  18646. DEBUG_INFO("errorDetails: %s\n", payload);
  18647. #endif
  18648. }
  18649. //===============================================
  18650. // Common routine
  18651. //===============================================
  18652. int initialConfigurationTable(void)
  18653. {
  18654. DEBUG_INFO("initialConfigurationTable...\n");
  18655. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  18656. DB_variableIsCreate();
  18657. DB_variableLoadFromDb();
  18658. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  18659. {
  18660. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  18661. DB_variableClear();
  18662. DB_variableIsCreate();
  18663. DB_variableLoadFromDb();
  18664. }
  18665. DB_getNetworkProfileFromDb();
  18666. DB_variableMonitoringLoadFromDb();
  18667. return 0;
  18668. }
  18669. int TransactionMessageAttemptsGet(void)
  18670. {
  18671. return TransactionMessageAttemptsValue;
  18672. }
  18673. int FirstHeartBeatResponse(void)
  18674. {
  18675. return FirstHeartBeat;
  18676. }
  18677. int TransactionMessageRetryIntervalGet(void)
  18678. {
  18679. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18680. }
  18681. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18682. {
  18683. int result = TRUE;
  18684. char rmFileCmd[100]={0};
  18685. char FilePath[100]={0};
  18686. char ftpbuf[200];
  18687. int systemresult;
  18688. sprintf(FilePath,"/mnt/%s",filename);
  18689. system("ping 8.8.8.8 &");
  18690. if((access(FilePath,F_OK))!=-1)
  18691. {
  18692. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18693. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18694. system(rmFileCmd);
  18695. }
  18696. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18697. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18698. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18699. systemresult = system(ftpbuf);
  18700. if(systemresult != 0)
  18701. {
  18702. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  18703. result = FALSE;
  18704. }
  18705. system("pkill ping");
  18706. return result;
  18707. }
  18708. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18709. {
  18710. int result = TRUE;
  18711. char rmFileCmd[100]={0};
  18712. char FilePath[100]={0};
  18713. char ftpbuf[200];
  18714. int systemresult;
  18715. sprintf(FilePath,"/mnt/%s",filename);
  18716. system("ping 8.8.8.8 &");
  18717. if((access(FilePath,F_OK))!=-1)
  18718. {
  18719. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18720. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18721. system(rmFileCmd);
  18722. }
  18723. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18724. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18725. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18726. systemresult = system(ftpbuf);
  18727. if(systemresult != 0)
  18728. {
  18729. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18730. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18731. systemresult = system(ftpbuf);
  18732. if(systemresult != 0)
  18733. {
  18734. DEBUG_WARN("FTP download fail!\n");
  18735. result = FALSE;
  18736. }
  18737. }
  18738. system("pkill ping");
  18739. return result;
  18740. }
  18741. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18742. {
  18743. char rmFileCmd[100]={0};
  18744. char FilePath[100]={0};
  18745. char buf[512];
  18746. int systemresult = 0;
  18747. //DEBUG_INFO("filename=%s\n",filename);
  18748. //DEBUG_INFO("url=%s\n",url);
  18749. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18750. if((access(FilePath,F_OK))!=-1)
  18751. {
  18752. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18753. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18754. system(rmFileCmd);
  18755. }
  18756. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18757. if(fp == NULL)
  18758. {
  18759. DEBUG_INFO("log is NULL\n");
  18760. return FALSE;
  18761. }
  18762. else
  18763. {
  18764. fprintf(fp, "%s\n", url);
  18765. fprintf(fp, "%s\n", filename);
  18766. fclose(fp);
  18767. }
  18768. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18769. if(phpFP == NULL)
  18770. {
  18771. DEBUG_INFO("PHP upload fail.\n");
  18772. return FALSE;
  18773. }
  18774. else
  18775. {
  18776. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18777. {
  18778. if(strstr(buf, "result") != NULL)
  18779. {
  18780. sscanf(buf, "result: %d", &systemresult);
  18781. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18782. }
  18783. }
  18784. pclose(phpFP);
  18785. }
  18786. if(systemresult != 1)
  18787. {
  18788. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18789. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18790. if(phpFP == NULL)
  18791. {
  18792. DEBUG_WARN("PHP PUT upload fail.\n");
  18793. return FALSE;
  18794. }
  18795. else
  18796. {
  18797. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18798. {
  18799. if(strstr(buf, "result") != NULL)
  18800. {
  18801. sscanf(buf, "result: %d", &systemresult);
  18802. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18803. }
  18804. }
  18805. pclose(phpFP);
  18806. }
  18807. }
  18808. if(systemresult != 1)
  18809. {
  18810. DEBUG_WARN("PHP PUT upload fail.\n");
  18811. return FALSE;
  18812. }
  18813. return TRUE;
  18814. }
  18815. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18816. {
  18817. int result = FALSE;
  18818. char ftpbuf[200];
  18819. int systemresult;
  18820. /*
  18821. // Domaind name transfer to IP address
  18822. struct hostent* server;
  18823. char *IPbuffer;
  18824. server = gethostbyname(location);
  18825. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18826. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18827. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18828. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18829. systemresult = system(ftpbuf);
  18830. if(systemresult != 0)
  18831. {
  18832. DEBUG_INFO("ftpput error!\n");
  18833. }
  18834. else
  18835. {
  18836. result = TRUE;
  18837. DEBUG_INFO("ftpput OK!\n");
  18838. }
  18839. return result;
  18840. }
  18841. //=========================================
  18842. // Routine
  18843. //=========================================
  18844. int GetOcppServerURL()
  18845. {
  18846. int result = FALSE;
  18847. struct yuarel url;
  18848. char urlStr[512];
  18849. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18850. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18851. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18852. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  18853. {
  18854. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  18855. if(yuarel_parse(&url, urlStr) != -1)
  18856. {
  18857. sprintf(OcppProtocol, "%s", url.scheme);
  18858. sprintf(OcppHost, "%s", url.host);
  18859. if(url.path == NULL)
  18860. OcppTempPath[0] = '\0';
  18861. else
  18862. sprintf(OcppTempPath, "%s", url.path);
  18863. if(url.port == 0)
  18864. {
  18865. if(strcmp(OcppProtocol, "wss") == 0)
  18866. OcppPort = 443;
  18867. else
  18868. OcppPort = 80;
  18869. }
  18870. else
  18871. OcppPort = url.port;
  18872. result = TRUE;
  18873. }
  18874. }
  18875. else
  18876. {
  18877. strcpy(OcppHost,"");
  18878. }
  18879. return result;
  18880. }
  18881. int GetOcppPath()
  18882. {
  18883. int result = FALSE;
  18884. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18885. {
  18886. if(OcppTempPath == NULL)
  18887. {
  18888. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18889. }
  18890. else
  18891. {
  18892. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18893. }
  18894. result = TRUE;
  18895. }
  18896. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  18897. {
  18898. if(OcppTempPath == NULL)
  18899. {
  18900. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  18901. }
  18902. else
  18903. {
  18904. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  18905. }
  18906. result = TRUE;
  18907. }
  18908. else
  18909. {
  18910. strcpy(OcppPath,"");
  18911. }
  18912. return result;
  18913. }
  18914. int GetOcppPort()
  18915. {
  18916. return OcppPort;
  18917. }
  18918. int GetOcppConnStatus(void)
  18919. {
  18920. return ShmOCPP20Data->OcppConnStatus;
  18921. }
  18922. void SetOcppConnStatus(uint8_t status)
  18923. {
  18924. ShmOCPP20Data->OcppConnStatus = status;
  18925. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18926. }
  18927. int GetHeartBeatWithNOResponse(void)
  18928. {
  18929. return HeartBeatWithNOResponse;
  18930. }
  18931. void SetHeartBeatWithNOResponse(void)
  18932. {
  18933. HeartBeatWithNOResponse = 0;
  18934. }
  18935. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18936. void storeTempStopTransaction(int gun_index)
  18937. {
  18938. char TempStopTransaction[256];
  18939. //char message[1024*20]={0};
  18940. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  18941. char guid[37]={0};
  18942. json_object *TransactionEvent = json_object_new_object();
  18943. json_object *transactionInfo = json_object_new_object();
  18944. json_object *idToken = json_object_new_object();
  18945. json_object *evse = json_object_new_object();
  18946. json_object *meterValues = json_object_new_array();
  18947. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  18948. DEBUG_INFO("storeTempStopTransaction...\n");
  18949. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  18950. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  18951. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  18952. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  18953. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  18954. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  18955. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  18956. // Message
  18957. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  18958. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  18959. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  18960. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  18961. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  18962. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  18963. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  18964. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  18965. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  18966. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  18967. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  18968. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  18969. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  18970. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  18971. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  18972. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  18973. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  18974. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  18975. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  18976. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  18977. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  18978. {
  18979. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  18980. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  18981. json_object_object_add(TransactionEvent, "idToken", idToken);
  18982. }
  18983. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  18984. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  18985. json_object_object_add(TransactionEvent, "evse", evse);
  18986. meterValueBufferQuery(gun_index, meterValues);
  18987. if(json_object_array_length(meterValues) > 0)
  18988. {
  18989. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  18990. }
  18991. random_uuid(guid);
  18992. sprintf(queuedata,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  18993. , guid
  18994. , "TransactionEvent"
  18995. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  18996. json_object_put(TransactionEvent);
  18997. // open file for writing
  18998. FILE *outfile;
  18999. outfile = fopen (TempStopTransaction, "w+");
  19000. //DEBUG_INFO("data = %s\n", queuedata);
  19001. fputs(queuedata, outfile);
  19002. fputs("\n", outfile);
  19003. fclose (outfile);
  19004. }
  19005. void checkTempStopTransaction(int gun_index)
  19006. {
  19007. FILE *fptr1;
  19008. char ch;
  19009. char str[QUEUE_MESSAGE_LENGTH]={0};
  19010. char guid[37]={0};
  19011. char tempdata[65]={0};
  19012. char TempStopTransaction[256];
  19013. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  19014. fptr1 = fopen(TempStopTransaction, "r");
  19015. if (!fptr1)
  19016. {
  19017. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  19018. return ;
  19019. }
  19020. ch=fgetc(fptr1);
  19021. rewind(fptr1);
  19022. if(ch!=EOF)
  19023. {
  19024. // copy all contents to the temporary file except the specific line
  19025. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19026. {
  19027. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19028. if(str[0]=='\0')
  19029. {
  19030. break;
  19031. }
  19032. strncpy(guid, str+4, 36); //copy guid
  19033. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  19034. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19035. {
  19036. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19037. }
  19038. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19039. memset(str,0,ARRAY_SIZE(str));
  19040. }
  19041. }
  19042. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19043. fclose(fptr1);
  19044. remove(TempStopTransaction); // remove the original file
  19045. }
  19046. int GetWebSocketPingInterval(void)
  19047. {
  19048. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  19049. }
  19050. int GetServerSign(void)
  19051. {
  19052. return server_sign;
  19053. }
  19054. uint8_t GetOcppSecurityProfile()
  19055. {
  19056. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  19057. }
  19058. void MergeCertificates()
  19059. {
  19060. char cmdBuf[2048]={0};
  19061. if(access(ROOTCA_CS,F_OK) != -1)
  19062. {
  19063. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  19064. }
  19065. else
  19066. {
  19067. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  19068. }
  19069. system(cmdBuf);
  19070. }
  19071. void GetOcppChargerBoxId(uint8_t *data)
  19072. {
  19073. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19074. }
  19075. void GetOcppSecurityPassword(uint8_t *data)
  19076. {
  19077. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  19078. }
  19079. void SetServerSign(int value)
  19080. {
  19081. server_sign = value;
  19082. }
  19083. int GetBootNotificationInterval(void)
  19084. {
  19085. return BootNotificationInterval;
  19086. }
  19087. int GetInternetConn(void)
  19088. {
  19089. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19090. }
  19091. int GetBackendConnectionTimeout(void)
  19092. {
  19093. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19094. }
  19095. int isConnectorInitMode(int gun_index)
  19096. {
  19097. int tempIndex = 0;
  19098. int result = TRUE;
  19099. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19100. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19101. {
  19102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19103. {
  19104. tempIndex = ((gun_index==2) ? 1: 0);
  19105. }
  19106. else
  19107. {
  19108. tempIndex = gun_index;
  19109. }
  19110. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19111. {
  19112. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19113. {
  19114. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19115. } //end of the same index
  19116. }//end of for CHAdeMO_QUANTITY
  19117. }
  19118. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19119. {
  19120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19121. {
  19122. tempIndex = ((gun_index==2) ? 1: 0);
  19123. }
  19124. else
  19125. {
  19126. tempIndex = gun_index;
  19127. }
  19128. for (int index = 0; index < CCS_QUANTITY; index++)
  19129. {
  19130. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19131. {
  19132. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19133. } //end of the same index
  19134. } // end of for CCS_QUANTITY
  19135. }
  19136. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19137. {
  19138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19139. {
  19140. tempIndex = ((gun_index==2) ? 1: 0);
  19141. }
  19142. else
  19143. {
  19144. tempIndex = gun_index;
  19145. }
  19146. for (int index = 0; index < GB_QUANTITY; index++)
  19147. {
  19148. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19149. {
  19150. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19151. } //end of the same index
  19152. } // end of for GB_QUANTITY
  19153. }
  19154. else if(gunType[gun_index] == GUN_TYPE_DO)
  19155. {
  19156. tempIndex = gun_index;
  19157. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19158. {
  19159. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19160. {
  19161. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19162. } //end of the same index
  19163. }
  19164. }
  19165. else
  19166. {
  19167. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19168. {
  19169. tempIndex = 2;
  19170. }
  19171. else
  19172. {
  19173. tempIndex = gun_index;
  19174. }
  19175. for (int index = 0; index < AC_QUANTITY; index++)
  19176. {
  19177. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19178. {
  19179. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19180. }//end of the same index
  19181. }//end of for AC_QUANTITY
  19182. }
  19183. return result;
  19184. }
  19185. void refreshProcDogTimer()
  19186. {
  19187. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  19188. }
  19189. void InitialSystemValue(void)
  19190. {
  19191. localversion=0;
  19192. BootNotificationInterval = 10;
  19193. authorizeRetryTimes = 0;
  19194. GunStatusInterval = 10;
  19195. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  19196. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  19197. //Heart Beat
  19198. HeartBeatWithNOResponse = 0;
  19199. HeartBeatCountPerHour = 0;
  19200. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  19201. if(HeartBeatWaitTime == 0)
  19202. FirstHeartBeat = TRUE;
  19203. else
  19204. FirstHeartBeat = FALSE;
  19205. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  19206. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  19207. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19208. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19209. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19210. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19211. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19212. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19213. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19214. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19215. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19216. //Status && ConnectorPlugIn Setting
  19217. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19218. {
  19219. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19220. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19221. }
  19222. for (int index = 0; index < CCS_QUANTITY; index++)
  19223. {
  19224. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19225. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19226. }
  19227. for (int index = 0; index < GB_QUANTITY; index++)
  19228. {
  19229. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19230. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19231. }
  19232. for (int index = 0; index < AC_QUANTITY; index++)
  19233. {
  19234. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19235. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19236. }
  19237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19238. {
  19239. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19240. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19241. }
  19242. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19243. {
  19244. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  19245. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  19246. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  19247. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19248. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  19249. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  19250. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  19251. }
  19252. refreshStartTimer(&clientTime.Heartbeat);
  19253. sleep(1);
  19254. }
  19255. void LWS_Send(char *str)
  19256. {
  19257. //=====================================================
  19258. // Check InternetConn 0: disconnected, 1: connected
  19259. //====================================================
  19260. if(GetOcppConnStatus() == 0)
  19261. {
  19262. DEBUG_INFO("offline now !!!\n");
  19263. return;
  19264. }
  19265. // Only disable isWebsocketSendable operation initiated by charger
  19266. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19267. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19268. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  19269. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19270. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19271. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  19272. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  19273. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19274. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19275. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19276. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  19277. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  19278. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  19279. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  19280. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  19281. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  19282. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  19283. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  19284. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  19285. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  19286. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  19287. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19288. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19289. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19290. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  19291. {
  19292. isWebsocketSendable = OFF;
  19293. }
  19294. pthread_mutex_lock(&lock_send);
  19295. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19296. sprintf((char *)SendBuffer, "%s", str);
  19297. SendBufLen = strlen(str);
  19298. pthread_mutex_unlock(&lock_send);
  19299. lws_callback_on_writable(wsi_client);
  19300. //lws_service(context, 0);
  19301. //sleep(1);
  19302. }
  19303. void LWS_SendNow(char *str)
  19304. {
  19305. //=====================================================
  19306. // Check InternetConn 0: disconnected, 1: connected
  19307. //====================================================
  19308. if(GetOcppConnStatus() == 0)
  19309. {
  19310. DEBUG_INFO("offline now !!!\n");
  19311. return;
  19312. }
  19313. // Only disable isWebsocketSendable operation initiated by charger
  19314. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19315. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19316. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  19317. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19318. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19319. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  19320. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  19321. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19322. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19323. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19324. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  19325. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  19326. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  19327. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  19328. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  19329. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  19330. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  19331. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  19332. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  19333. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  19334. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  19335. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19336. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19337. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19338. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  19339. {
  19340. isWebsocketSendable = OFF;
  19341. }
  19342. pthread_mutex_lock(&lock_send);
  19343. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19344. sprintf((char *)SendBuffer, "%s", str);
  19345. SendBufLen = strlen(str);
  19346. pthread_mutex_unlock(&lock_send);
  19347. lws_callback_on_writable(wsi_client);
  19348. lws_service(context, 0);
  19349. //sleep(1);
  19350. }