MessageHandler.c 1.1 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291
  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 variableMonitoringQuantity()
  3185. {
  3186. uint32_t result = 0;
  3187. char sqlCmd[8192];
  3188. char zErrMsg[200];
  3189. int rows, cols;
  3190. char **resultData;
  3191. sprintf(sqlCmd, "select count(idx) as dataQuantity from ocpp20_variable_monitoring");
  3192. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  3193. {
  3194. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  3195. }
  3196. else
  3197. {
  3198. if(rows >= 1)
  3199. {
  3200. result = atoi(resultData[1]);
  3201. }
  3202. }
  3203. return result;
  3204. }
  3205. int DB_variableMonitoringClear()
  3206. {
  3207. int result = PASS;
  3208. char * sqlclearVariableMonitoring = "delete from ocpp20_variable_monitoring";
  3209. char *errMsg = 0;
  3210. if (sqlite3_exec(db, sqlclearVariableMonitoring, 0, 0, &errMsg) != SQLITE_OK)
  3211. {
  3212. DEBUG_INFO("%s\n", errMsg);
  3213. result = FAIL;
  3214. }
  3215. return result;
  3216. }
  3217. int VariableMonitoringReplace(uint8_t idx, struct SetMonitoringDataType *variableMonitoring)
  3218. {
  3219. int result = PASS;
  3220. char sql[1024];
  3221. char *errMsg = 0;
  3222. sprintf(sql,"replace into ocpp20_variable_monitoring "
  3223. "(idx, id, txn, value, type, severity, component_name, component_instance, component_evse_id, component_evse_connectorId, variable_name, variable_instance) "
  3224. "VALUES('%d', '%d', '%d', '%.2f', '%s', '%d', '%s', '%s', '%d', '%d', '%s', '%s'); SELECT * from ocpp20_variable_monitoring;",
  3225. idx,
  3226. variableMonitoring->id,
  3227. variableMonitoring->transaction,
  3228. variableMonitoring->value,
  3229. variableMonitoring->type,
  3230. variableMonitoring->severity,
  3231. variableMonitoring->component.name,
  3232. variableMonitoring->component.instance,
  3233. variableMonitoring->component.evse.id,
  3234. variableMonitoring->component.evse.connectorId,
  3235. variableMonitoring->variable.name,
  3236. variableMonitoring->variable.instance
  3237. );
  3238. if (sqlite3_exec(db, sql, 0, 0, &errMsg) != SQLITE_OK)
  3239. {
  3240. result = FAIL;
  3241. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  3242. }
  3243. return result;
  3244. }
  3245. int DB_cbVariableMonitoringSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  3246. {
  3247. for(int i = 0; i<columnCount; i++)
  3248. {
  3249. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  3250. }
  3251. return 0;
  3252. }
  3253. int DB_variableMonitoringSaveToDb(struct SetMonitoringDataType *variableMonitoring)
  3254. {
  3255. int result = FAIL;
  3256. char sql[1024];
  3257. char* errMsg = NULL;
  3258. sprintf(sql,"insert or replace into ocpp20_variable_monitoring "
  3259. "(id, txn, value, type, severity, component_name, component_instance, component_evse_id, component_evse_connectorId, variable_name, variable_instance) "
  3260. "VALUES('%d', '%d', '%.2f', '%s', '%d', '%s', '%s', '%d', '%d', '%s', '%s'); SELECT * from ocpp20_variable_monitoring;",
  3261. variableMonitoring->id,
  3262. variableMonitoring->transaction,
  3263. variableMonitoring->value,
  3264. variableMonitoring->type,
  3265. variableMonitoring->severity,
  3266. variableMonitoring->component.name,
  3267. variableMonitoring->component.instance,
  3268. variableMonitoring->component.evse.id,
  3269. variableMonitoring->component.evse.connectorId,
  3270. variableMonitoring->variable.name,
  3271. variableMonitoring->variable.instance
  3272. );
  3273. //* Execute SQL statement */
  3274. if(sqlite3_exec(db, sql, DB_cbVariableMonitoringSaveToDb, 0, &errMsg) != SQLITE_OK)
  3275. {
  3276. DEBUG_INFO("SQL error: %s\n", errMsg);
  3277. result = FAIL;
  3278. }
  3279. return result;
  3280. }
  3281. int DB_cbVariableMonitoringLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3282. {
  3283. for(int idx=0;idx<10;idx++)
  3284. {
  3285. if((strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name) == 0) &&
  3286. (strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name) == 0))
  3287. {
  3288. ShmOCPP20Data->MonitoringComponentVariable[idx].id = strlen(columnValue[1])>=0?atoi(columnValue[1]):-1;
  3289. ShmOCPP20Data->MonitoringComponentVariable[idx].transaction = strlen(columnValue[2])>=0?atoi(columnValue[2]):0;
  3290. ShmOCPP20Data->MonitoringComponentVariable[idx].value = strlen(columnValue[3])>=0?atof(columnValue[3]):0;
  3291. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "%s", columnValue[4]);
  3292. ShmOCPP20Data->MonitoringComponentVariable[idx].severity = strlen(columnValue[5])>0?atoi(columnValue[5]):9;
  3293. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, "%s", columnValue[6]);
  3294. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.instance, "%s", columnValue[7]);
  3295. ShmOCPP20Data->MonitoringComponentVariable[idx].component.evse.id = strlen(columnValue[8])>0?atoi(columnValue[8]):-1;
  3296. ShmOCPP20Data->MonitoringComponentVariable[idx].component.evse.connectorId = strlen(columnValue[9])>0?atoi(columnValue[9]):-1;
  3297. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, "%s", columnValue[10]);
  3298. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.instance, "%s", columnValue[11]);
  3299. break;
  3300. }
  3301. }
  3302. return 0;
  3303. }
  3304. void DB_variableMonitoringLoadFromDb()
  3305. {
  3306. char sql[512];
  3307. char* errMsg = NULL;
  3308. sprintf(sql,"select * from ocpp20_variable_monitoring order by idx;");
  3309. /* Execute SQL statement */
  3310. if(sqlite3_exec(db, sql, DB_cbVariableMonitoringLoadFromDb, 0, &errMsg) != SQLITE_OK )
  3311. {
  3312. DEBUG_INFO("SQL error: %s\n", errMsg);
  3313. }
  3314. }
  3315. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3316. {
  3317. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  3318. if(columnCount > 0)
  3319. {
  3320. for(int idx=0;idx<columnCount;idx++)
  3321. {
  3322. json_object *SetNetworkProfile;
  3323. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  3324. if(!is_error(SetNetworkProfile))
  3325. {
  3326. // Required data
  3327. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  3328. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  3329. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  3330. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  3331. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  3332. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  3333. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  3334. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  3335. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  3336. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  3337. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  3338. {
  3339. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  3340. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  3341. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  3342. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  3343. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  3344. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  3345. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  3346. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  3347. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  3348. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  3349. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  3350. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  3351. }
  3352. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  3353. {
  3354. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  3355. {
  3356. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  3357. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  3358. }
  3359. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  3360. {
  3361. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  3362. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  3363. }
  3364. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  3365. {
  3366. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  3367. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  3368. }
  3369. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  3370. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  3371. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  3372. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  3373. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  3374. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  3375. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  3376. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  3377. }
  3378. }
  3379. json_object_put(SetNetworkProfile);
  3380. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  3381. }
  3382. }
  3383. return 0;
  3384. }
  3385. void DB_getNetworkProfileFromDb()
  3386. {
  3387. char sql[512];
  3388. char* errMsg = NULL;
  3389. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  3390. /* Execute SQL statement */
  3391. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3392. {
  3393. DEBUG_INFO("SQL error: %s\n", errMsg);
  3394. }
  3395. }
  3396. int DB_addNetworkProfile(int slot, char *data)
  3397. {
  3398. int result = PASS;
  3399. char sql[512];
  3400. char* errMsg = NULL;
  3401. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  3402. slot,
  3403. data);
  3404. //* Execute SQL statement */
  3405. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  3406. {
  3407. DEBUG_INFO("SQL error: %s\n", errMsg);
  3408. result = FAIL;
  3409. }
  3410. return result;
  3411. }
  3412. int DB_deleteNetworkProfile(int slot)
  3413. {
  3414. int result = PASS;
  3415. char sql[512];
  3416. char* errMsg = NULL;
  3417. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  3418. //* Execute SQL statement */
  3419. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3420. {
  3421. DEBUG_INFO("SQL error: %s", errMsg);
  3422. result = FAIL;
  3423. }
  3424. return result;
  3425. }
  3426. int isNumber(uint8_t *string, uint8_t isFloat)
  3427. {
  3428. int result = NO;
  3429. int cntDecimal = 0;
  3430. float i;
  3431. for(int idx=0; idx<strlen((char*)string); idx++)
  3432. {
  3433. if((isdigit(string[idx])==0) && (string[idx] != '.'))
  3434. {
  3435. return result;
  3436. }
  3437. else if(string[idx] == '.')
  3438. cntDecimal++;
  3439. if(cntDecimal>1)
  3440. return result;
  3441. }
  3442. if((isFloat==FALSE) && (strstr((char*)string, ".") != NULL))
  3443. {
  3444. //DEBUG_INFO("%s is not pure integer!!\n", string);
  3445. }
  3446. else if((isFloat==TRUE) && (strstr((char*)string, ".") == NULL))
  3447. {
  3448. //DEBUG_INFO("%s is not float format!!\n", string);
  3449. }
  3450. else if(sscanf((char*)string, "%f", &i) != 0)
  3451. {
  3452. result = YES;
  3453. }
  3454. return result;
  3455. }
  3456. int isMatchTimeFormat(uint8_t *time)
  3457. {
  3458. int result = NO;
  3459. struct ParsingResult
  3460. {
  3461. int result;
  3462. int scanedElement;
  3463. int year;
  3464. int month;
  3465. int mday;
  3466. int hour;
  3467. int min;
  3468. int sec;
  3469. int tz_hour;
  3470. int tz_min;
  3471. float minSec;
  3472. }parsingResult;
  3473. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3474. if(strstr((char*)time, ".") != NULL)
  3475. {
  3476. // Original data with mini second
  3477. if(strstr((char*)time, "Z") != NULL)
  3478. {
  3479. // Original data with Z
  3480. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%fZ",
  3481. &parsingResult.year,
  3482. &parsingResult.month,
  3483. &parsingResult.mday,
  3484. &parsingResult.hour,
  3485. &parsingResult.min,
  3486. &parsingResult.sec,
  3487. &parsingResult.minSec);
  3488. }
  3489. else
  3490. {
  3491. // Original data without Z
  3492. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3493. &parsingResult.year,
  3494. &parsingResult.month,
  3495. &parsingResult.mday,
  3496. &parsingResult.hour,
  3497. &parsingResult.min,
  3498. &parsingResult.sec,
  3499. &parsingResult.minSec,
  3500. &parsingResult.tz_hour,
  3501. &parsingResult.tz_min);
  3502. }
  3503. }
  3504. else
  3505. {
  3506. // Original data without mini second
  3507. if(strstr((char*)time, "Z") != NULL)
  3508. {
  3509. // Original data with Z
  3510. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%dZ",
  3511. &parsingResult.year,
  3512. &parsingResult.month,
  3513. &parsingResult.mday,
  3514. &parsingResult.hour,
  3515. &parsingResult.min,
  3516. &parsingResult.sec);
  3517. }
  3518. else
  3519. {
  3520. // Original data without Z
  3521. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d%d:%d",
  3522. &parsingResult.year,
  3523. &parsingResult.month,
  3524. &parsingResult.mday,
  3525. &parsingResult.hour,
  3526. &parsingResult.min,
  3527. &parsingResult.sec,
  3528. &parsingResult.tz_hour,
  3529. &parsingResult.tz_min);
  3530. }
  3531. }
  3532. if(parsingResult.scanedElement >= 6)
  3533. {
  3534. result = YES;
  3535. }
  3536. return result;
  3537. }
  3538. int getCurrentYear()
  3539. {
  3540. int result = 0;
  3541. time_t CurrentTime;
  3542. struct tm *tm;
  3543. CurrentTime = time(NULL);
  3544. tm=localtime(&CurrentTime);
  3545. result = (tm->tm_year + 1900);
  3546. return result;
  3547. }
  3548. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  3549. {
  3550. int result = PASS;
  3551. char* errMsg = NULL;
  3552. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  3553. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  3554. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3555. {
  3556. result = FAIL;
  3557. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  3558. }
  3559. 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));
  3560. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3561. {
  3562. result = FAIL;
  3563. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  3564. }
  3565. return result;
  3566. }
  3567. //==========================================
  3568. // Check time passed since today
  3569. //==========================================
  3570. long long DiffTimebWithNow(struct timeb ST)
  3571. {
  3572. //return milli-second
  3573. struct timeb ET;
  3574. long long StartTime,StopTime;
  3575. ftime(&ET);
  3576. StartTime=(long long)ST.time;
  3577. StopTime=(long long)ET.time;
  3578. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  3579. }
  3580. int getTimePassSinceToday(uint8_t gun_index)
  3581. {
  3582. int result = -1;
  3583. static time_t lastTime[4];
  3584. time_t t;
  3585. struct tm *tmStartToday;
  3586. struct timeb tbStartToday;
  3587. t=time(NULL);
  3588. if(difftime(t, lastTime[gun_index])>0)
  3589. {
  3590. tmStartToday=localtime(&t);
  3591. tmStartToday->tm_hour = 0;
  3592. tmStartToday->tm_min = 0;
  3593. tmStartToday->tm_sec = 0;
  3594. tbStartToday.time = mktime(tmStartToday);
  3595. tbStartToday.millitm = 0;
  3596. result = DiffTimebWithNow(tbStartToday)/1000;
  3597. lastTime[gun_index] = t;
  3598. }
  3599. return result;
  3600. }
  3601. int syncDateTimeRTC(uint8_t *data)
  3602. {
  3603. struct ParsingResult
  3604. {
  3605. int result;
  3606. int scanedElement;
  3607. int year;
  3608. int month;
  3609. int mday;
  3610. int hour;
  3611. int min;
  3612. int sec;
  3613. int tz_hour;
  3614. int tz_min;
  3615. float minSec;
  3616. }result;
  3617. struct tm tmOrg;
  3618. struct tm *tmTarget;
  3619. struct timeb tbTarget;
  3620. char buf[128];
  3621. memset(&result, 0x00, sizeof(struct ParsingResult));
  3622. result.result = PASS;
  3623. if(strstr((char*)data, ".") != NULL)
  3624. {
  3625. // Original data with mini second
  3626. if(strstr((char*)data, "Z") != NULL)
  3627. {
  3628. // Original data with Z
  3629. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  3630. &result.year,
  3631. &result.month,
  3632. &result.mday,
  3633. &result.hour,
  3634. &result.min,
  3635. &result.sec,
  3636. &result.minSec);
  3637. }
  3638. else
  3639. {
  3640. // Original data without Z
  3641. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3642. &result.year,
  3643. &result.month,
  3644. &result.mday,
  3645. &result.hour,
  3646. &result.min,
  3647. &result.sec,
  3648. &result.minSec,
  3649. &result.tz_hour,
  3650. &result.tz_min);
  3651. }
  3652. }
  3653. else
  3654. {
  3655. // Original data without mini second
  3656. if(strstr((char*)data, "Z") != NULL)
  3657. {
  3658. // Original data with Z
  3659. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  3660. &result.year,
  3661. &result.month,
  3662. &result.mday,
  3663. &result.hour,
  3664. &result.min,
  3665. &result.sec);
  3666. }
  3667. else
  3668. {
  3669. // Original data without Z
  3670. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  3671. &result.year,
  3672. &result.month,
  3673. &result.mday,
  3674. &result.hour,
  3675. &result.min,
  3676. &result.sec,
  3677. &result.tz_hour,
  3678. &result.tz_min);
  3679. }
  3680. }
  3681. tmOrg.tm_year = result.year - 1900;
  3682. tmOrg.tm_mon = result.month - 1;
  3683. tmOrg.tm_mday = result.mday;
  3684. tmOrg.tm_hour = result.hour;
  3685. tmOrg.tm_min = result.min;
  3686. tmOrg.tm_sec = result.sec;
  3687. tmOrg.tm_gmtoff = 0;
  3688. tbTarget.time = mktime(&tmOrg);
  3689. tbTarget.timezone = 0;
  3690. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  3691. tmTarget = gmtime(&tbTarget.time);
  3692. 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);
  3693. //DEBUG_INFO(" org date time: %s\n", data);
  3694. //DEBUG_INFO("parse date time: %s\n", buf);
  3695. system(buf);
  3696. system("/sbin/hwclock -w --systohc");
  3697. if(result.scanedElement < 6)
  3698. result.result = FAIL;
  3699. return result.result;
  3700. }
  3701. //==========================================
  3702. // GetCompositeSchedule logic related function
  3703. //==========================================
  3704. int DiffTimebSec(struct timeb ST, struct timeb ET)
  3705. {
  3706. //return milli-second
  3707. unsigned int StartTime,StopTime;
  3708. StartTime=(unsigned int)ST.time;
  3709. StopTime=(unsigned int)ET.time;
  3710. return (StopTime-StartTime);
  3711. }
  3712. int DiffTimebWithNowSec(struct timeb ST)
  3713. {
  3714. //return milli-second
  3715. struct timeb ET;
  3716. unsigned int StartTime,StopTime;
  3717. ftime(&ET);
  3718. StartTime=(unsigned int)ST.time;
  3719. StopTime=(unsigned int)ET.time;
  3720. return (StopTime-StartTime);
  3721. }
  3722. int getStartStop(uint8_t *start, uint8_t *stop)
  3723. {
  3724. struct ParsingResult
  3725. {
  3726. int result;
  3727. int scanedElement;
  3728. int year;
  3729. int month;
  3730. int mday;
  3731. int hour;
  3732. int min;
  3733. int sec;
  3734. int tz_hour;
  3735. int tz_min;
  3736. float minSec;
  3737. };
  3738. struct ParsingResult parseStart;
  3739. struct ParsingResult parseStop;
  3740. int result = -1;
  3741. struct tm tmStart;
  3742. struct timeb tbStart;
  3743. struct tm tmStop;
  3744. struct timeb tbStop;
  3745. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3746. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3747. // Scan start & stop date time
  3748. if(strstr((char*)start, ".") != NULL)
  3749. {
  3750. // Original data with mini second
  3751. if(strstr((char*)start, "Z") != NULL)
  3752. {
  3753. // Original data with Z
  3754. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3755. &parseStart.year,
  3756. &parseStart.month,
  3757. &parseStart.mday,
  3758. &parseStart.hour,
  3759. &parseStart.min,
  3760. &parseStart.sec,
  3761. &parseStart.minSec);
  3762. }
  3763. else
  3764. {
  3765. // Original data without Z
  3766. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3767. &parseStart.year,
  3768. &parseStart.month,
  3769. &parseStart.mday,
  3770. &parseStart.hour,
  3771. &parseStart.min,
  3772. &parseStart.sec,
  3773. &parseStart.minSec,
  3774. &parseStart.tz_hour,
  3775. &parseStart.tz_min);
  3776. }
  3777. }
  3778. else
  3779. {
  3780. // Original data without mini second
  3781. if(strstr((char*)start, "Z") != NULL)
  3782. {
  3783. // Original data with Z
  3784. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3785. &parseStart.year,
  3786. &parseStart.month,
  3787. &parseStart.mday,
  3788. &parseStart.hour,
  3789. &parseStart.min,
  3790. &parseStart.sec);
  3791. }
  3792. else
  3793. {
  3794. // Original data without Z
  3795. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3796. &parseStart.year,
  3797. &parseStart.month,
  3798. &parseStart.mday,
  3799. &parseStart.hour,
  3800. &parseStart.min,
  3801. &parseStart.sec,
  3802. &parseStart.tz_hour,
  3803. &parseStart.tz_min);
  3804. }
  3805. }
  3806. if(strstr((char*)stop, ".") != NULL)
  3807. {
  3808. // Original data with mini second
  3809. if(strstr((char*)stop, "Z") != NULL)
  3810. {
  3811. // Original data with Z
  3812. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3813. &parseStop.year,
  3814. &parseStop.month,
  3815. &parseStop.mday,
  3816. &parseStop.hour,
  3817. &parseStop.min,
  3818. &parseStop.sec,
  3819. &parseStop.minSec);
  3820. }
  3821. else
  3822. {
  3823. // Original data without Z
  3824. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3825. &parseStop.year,
  3826. &parseStop.month,
  3827. &parseStop.mday,
  3828. &parseStop.hour,
  3829. &parseStop.min,
  3830. &parseStop.sec,
  3831. &parseStop.minSec,
  3832. &parseStop.tz_hour,
  3833. &parseStop.tz_min);
  3834. }
  3835. }
  3836. else
  3837. {
  3838. // Original data without mini second
  3839. if(strstr((char*)stop, "Z") != NULL)
  3840. {
  3841. // Original data with Z
  3842. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3843. &parseStop.year,
  3844. &parseStop.month,
  3845. &parseStop.mday,
  3846. &parseStop.hour,
  3847. &parseStop.min,
  3848. &parseStop.sec);
  3849. }
  3850. else
  3851. {
  3852. // Original data without Z
  3853. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3854. &parseStop.year,
  3855. &parseStop.month,
  3856. &parseStop.mday,
  3857. &parseStop.hour,
  3858. &parseStop.min,
  3859. &parseStop.sec,
  3860. &parseStop.tz_hour,
  3861. &parseStop.tz_min);
  3862. }
  3863. }
  3864. // Calculate date time difference
  3865. if((parseStart.scanedElement >=6) &&
  3866. (parseStop.scanedElement >=6))
  3867. {
  3868. //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);
  3869. //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);
  3870. tmStart.tm_year = parseStart.year - 1900;
  3871. tmStart.tm_mon = parseStart.month - 1;
  3872. tmStart.tm_mday = parseStart.mday;
  3873. tmStart.tm_hour = parseStart.hour;
  3874. tmStart.tm_min = parseStart.min;
  3875. tmStart.tm_sec = parseStart.sec;
  3876. tmStart.tm_gmtoff = 0;
  3877. tbStart.time = mktime(&tmStart);
  3878. tbStart.timezone = 0;
  3879. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3880. tmStop.tm_year = parseStop.year - 1900;
  3881. tmStop.tm_mon = parseStop.month - 1;
  3882. tmStop.tm_mday = parseStop.mday;
  3883. tmStop.tm_hour = parseStop.hour;
  3884. tmStop.tm_min = parseStop.min;
  3885. tmStop.tm_sec = parseStop.sec;
  3886. tmStop.tm_gmtoff = 0;
  3887. tbStop.time = mktime(&tmStop);
  3888. tbStop.timezone = 0;
  3889. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3890. result = DiffTimebSec(tbStart, tbStop);
  3891. //DEBUG_INFO("getStartStop(): %d\n", result);
  3892. }
  3893. else
  3894. {
  3895. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3896. }
  3897. return result;
  3898. }
  3899. int isOvertNow(uint8_t *start)
  3900. {
  3901. int result = NO;
  3902. struct ParsingResult
  3903. {
  3904. int result;
  3905. int scanedElement;
  3906. int year;
  3907. int month;
  3908. int mday;
  3909. int hour;
  3910. int min;
  3911. int sec;
  3912. int tz_hour;
  3913. int tz_min;
  3914. float minSec;
  3915. }parsingResult;
  3916. struct tm tmStart;
  3917. struct timeb tbStart;
  3918. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3919. if(strstr((char*)start, ".") != NULL)
  3920. {
  3921. // Original data with mini second
  3922. if(strstr((char*)start, "Z") != NULL)
  3923. {
  3924. // Original data with Z
  3925. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3926. &parsingResult.year,
  3927. &parsingResult.month,
  3928. &parsingResult.mday,
  3929. &parsingResult.hour,
  3930. &parsingResult.min,
  3931. &parsingResult.sec,
  3932. &parsingResult.minSec);
  3933. }
  3934. else
  3935. {
  3936. // Original data without Z
  3937. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3938. &parsingResult.year,
  3939. &parsingResult.month,
  3940. &parsingResult.mday,
  3941. &parsingResult.hour,
  3942. &parsingResult.min,
  3943. &parsingResult.sec,
  3944. &parsingResult.minSec,
  3945. &parsingResult.tz_hour,
  3946. &parsingResult.tz_min);
  3947. }
  3948. }
  3949. else
  3950. {
  3951. // Original data without mini second
  3952. if(strstr((char*)start, "Z") != NULL)
  3953. {
  3954. // Original data with Z
  3955. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3956. &parsingResult.year,
  3957. &parsingResult.month,
  3958. &parsingResult.mday,
  3959. &parsingResult.hour,
  3960. &parsingResult.min,
  3961. &parsingResult.sec);
  3962. }
  3963. else
  3964. {
  3965. // Original data without Z
  3966. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3967. &parsingResult.year,
  3968. &parsingResult.month,
  3969. &parsingResult.mday,
  3970. &parsingResult.hour,
  3971. &parsingResult.min,
  3972. &parsingResult.sec,
  3973. &parsingResult.tz_hour,
  3974. &parsingResult.tz_min);
  3975. }
  3976. }
  3977. if(parsingResult.scanedElement >= 6)
  3978. {
  3979. tmStart.tm_year = parsingResult.year - 1900;
  3980. tmStart.tm_mon = parsingResult.month - 1;
  3981. tmStart.tm_mday = parsingResult.mday;
  3982. tmStart.tm_hour = parsingResult.hour;
  3983. tmStart.tm_min = parsingResult.min;
  3984. tmStart.tm_sec = parsingResult.sec;
  3985. tmStart.tm_gmtoff = 0;
  3986. tbStart.time = mktime(&tmStart);
  3987. tbStart.timezone = 0;
  3988. tbStart.millitm = 0;
  3989. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3990. if(DiffTimebWithNowSec(tbStart) <= 0)
  3991. result = NO;
  3992. else
  3993. result = YES;
  3994. }
  3995. else
  3996. {
  3997. DEBUG_WARN("Start date parsing error.\n");
  3998. }
  3999. return result;
  4000. }
  4001. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  4002. {
  4003. struct ParsingResult
  4004. {
  4005. int result;
  4006. int scanedElement;
  4007. int year;
  4008. int month;
  4009. int mday;
  4010. int hour;
  4011. int min;
  4012. int sec;
  4013. int tz_hour;
  4014. int tz_min;
  4015. float minSec;
  4016. };
  4017. struct ParsingResult parseStart;
  4018. struct ParsingResult parseStop;
  4019. int result = -1;
  4020. struct tm tmStart;
  4021. struct timeb tbStart;
  4022. struct tm tmStop;
  4023. struct timeb tbStop;
  4024. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  4025. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  4026. // Scan start & stop date time
  4027. if(strstr((char*)start, ".") != NULL)
  4028. {
  4029. // Original data with mini second
  4030. if(strstr((char*)start, "Z") != NULL)
  4031. {
  4032. // Original data with Z
  4033. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  4034. &parseStart.year,
  4035. &parseStart.month,
  4036. &parseStart.mday,
  4037. &parseStart.hour,
  4038. &parseStart.min,
  4039. &parseStart.sec,
  4040. &parseStart.minSec);
  4041. }
  4042. else
  4043. {
  4044. // Original data without Z
  4045. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  4046. &parseStart.year,
  4047. &parseStart.month,
  4048. &parseStart.mday,
  4049. &parseStart.hour,
  4050. &parseStart.min,
  4051. &parseStart.sec,
  4052. &parseStart.minSec,
  4053. &parseStart.tz_hour,
  4054. &parseStart.tz_min);
  4055. }
  4056. }
  4057. else
  4058. {
  4059. // Original data without mini second
  4060. if(strstr((char*)start, "Z") != NULL)
  4061. {
  4062. // Original data with Z
  4063. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  4064. &parseStart.year,
  4065. &parseStart.month,
  4066. &parseStart.mday,
  4067. &parseStart.hour,
  4068. &parseStart.min,
  4069. &parseStart.sec);
  4070. }
  4071. else
  4072. {
  4073. // Original data without Z
  4074. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  4075. &parseStart.year,
  4076. &parseStart.month,
  4077. &parseStart.mday,
  4078. &parseStart.hour,
  4079. &parseStart.min,
  4080. &parseStart.sec,
  4081. &parseStart.tz_hour,
  4082. &parseStart.tz_min);
  4083. }
  4084. }
  4085. if(strstr((char*)stop, ".") != NULL)
  4086. {
  4087. // Original data with mini second
  4088. if(strstr((char*)stop, "Z") != NULL)
  4089. {
  4090. // Original data with Z
  4091. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  4092. &parseStop.year,
  4093. &parseStop.month,
  4094. &parseStop.mday,
  4095. &parseStop.hour,
  4096. &parseStop.min,
  4097. &parseStop.sec,
  4098. &parseStop.minSec);
  4099. }
  4100. else
  4101. {
  4102. // Original data without Z
  4103. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  4104. &parseStop.year,
  4105. &parseStop.month,
  4106. &parseStop.mday,
  4107. &parseStop.hour,
  4108. &parseStop.min,
  4109. &parseStop.sec,
  4110. &parseStop.minSec,
  4111. &parseStop.tz_hour,
  4112. &parseStop.tz_min);
  4113. }
  4114. }
  4115. else
  4116. {
  4117. // Original data without mini second
  4118. if(strstr((char*)stop, "Z") != NULL)
  4119. {
  4120. // Original data with Z
  4121. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  4122. &parseStop.year,
  4123. &parseStop.month,
  4124. &parseStop.mday,
  4125. &parseStop.hour,
  4126. &parseStop.min,
  4127. &parseStop.sec);
  4128. }
  4129. else
  4130. {
  4131. // Original data without Z
  4132. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  4133. &parseStop.year,
  4134. &parseStop.month,
  4135. &parseStop.mday,
  4136. &parseStop.hour,
  4137. &parseStop.min,
  4138. &parseStop.sec,
  4139. &parseStop.tz_hour,
  4140. &parseStop.tz_min);
  4141. }
  4142. }
  4143. // Calculate date time difference
  4144. if((parseStart.scanedElement >=6) &&
  4145. (parseStop.scanedElement >=6))
  4146. {
  4147. //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);
  4148. //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);
  4149. tmStart.tm_year = parseStart.year - 1900;
  4150. tmStart.tm_mon = parseStart.month - 1;
  4151. tmStart.tm_mday = parseStart.mday;
  4152. tmStart.tm_hour = parseStart.hour;
  4153. tmStart.tm_min = parseStart.min;
  4154. tmStart.tm_sec = parseStart.sec;
  4155. tmStart.tm_gmtoff = 0;
  4156. tbStart.time = mktime(&tmStart);
  4157. tbStart.timezone = 0;
  4158. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  4159. tmStop.tm_year = parseStop.year - 1900;
  4160. tmStop.tm_mon = parseStop.month - 1;
  4161. tmStop.tm_mday = parseStop.mday;
  4162. tmStop.tm_hour = parseStop.hour;
  4163. tmStop.tm_min = parseStop.min;
  4164. tmStop.tm_sec = parseStop.sec;
  4165. tmStop.tm_gmtoff = 0;
  4166. tbStop.time = mktime(&tmStop);
  4167. tbStop.timezone = 0;
  4168. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  4169. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  4170. //DEBUG_INFO("getStartStop(): %d\n", result);
  4171. }
  4172. else
  4173. {
  4174. DEBUG_WARN("Start or stop date parsing error.\r\n");
  4175. }
  4176. return result;
  4177. }
  4178. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4179. {
  4180. FILE *fp;
  4181. char profileFileName[128];
  4182. char *line = NULL;
  4183. size_t len = 0;
  4184. time_t CurrentTime;
  4185. struct tm *tmComposite;
  4186. struct ChargingProfileType maxProfile;
  4187. struct ChargingProfileType compositeProfile;
  4188. uint8_t limitMax=0;
  4189. int compositePeriodIdx = 0;
  4190. CurrentTime = time(NULL);
  4191. tmComposite=localtime(&CurrentTime);
  4192. 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);
  4193. if(isUnitA)
  4194. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4195. else
  4196. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4197. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4198. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4199. {
  4200. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4201. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4202. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4203. }
  4204. compositeProfile.id = 0;
  4205. compositeProfile.stackLevel = 99 ;
  4206. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  4207. maxProfile.id = -1;
  4208. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4209. system("rm -f /tmp/*.json");
  4210. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4211. // Search max profile
  4212. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4213. if((access(profileFileName, F_OK))!=-1)
  4214. {
  4215. fp = fopen(profileFileName, "r");
  4216. while(getline(&line, &len, fp) != -1)
  4217. {
  4218. json_object *obj = NULL;
  4219. obj = json_tokener_parse(line);
  4220. if(is_error(obj))
  4221. {
  4222. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4223. }
  4224. else
  4225. {
  4226. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4227. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4228. )
  4229. {
  4230. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4231. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4232. )
  4233. {
  4234. struct tm tmFrom, tmTo;
  4235. struct timeb tbFrom, tbTo;
  4236. 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) &&
  4237. (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))
  4238. {
  4239. tmFrom.tm_year -= 1900;
  4240. tmFrom.tm_mon -= 1;
  4241. tbFrom.time = mktime(&tmFrom);
  4242. tmTo.tm_year -= 1900;
  4243. tmTo.tm_mon -= 1;
  4244. tbTo.time = mktime(&tmTo);
  4245. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4246. {
  4247. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4248. {
  4249. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4250. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4251. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4252. }
  4253. if(maxProfile.id == -1)
  4254. DEBUG_INFO("MaxProfile found.\n");
  4255. else
  4256. DEBUG_INFO("MaxProfile updated.\n");
  4257. // Required item
  4258. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4259. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4260. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4261. if(isUnitA)
  4262. {
  4263. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4264. 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++)
  4265. {
  4266. 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"));
  4267. 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"));
  4268. /*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)
  4269. {
  4270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4271. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4272. else
  4273. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4274. }
  4275. else
  4276. {
  4277. 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"));
  4278. }*/
  4279. 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")));
  4280. }
  4281. }
  4282. else
  4283. {
  4284. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4285. 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++)
  4286. {
  4287. 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"));
  4288. 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"));
  4289. /*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)
  4290. {
  4291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4292. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4293. else
  4294. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4295. }
  4296. else
  4297. {
  4298. 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"));
  4299. }*/
  4300. 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));
  4301. }
  4302. }
  4303. // Optional item
  4304. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4305. {
  4306. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4307. }
  4308. else
  4309. {
  4310. sprintf((char*)maxProfile.validFrom, " ");
  4311. }
  4312. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4313. {
  4314. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4315. }
  4316. else
  4317. {
  4318. sprintf((char*)maxProfile.validTo, " ");
  4319. }
  4320. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4321. {
  4322. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4323. }
  4324. else
  4325. {
  4326. sprintf((char*)maxProfile.recurrencyKind, " ");
  4327. }
  4328. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4329. {
  4330. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4331. }
  4332. else
  4333. {
  4334. sprintf((char*)maxProfile.transactionId, " ");
  4335. }
  4336. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4337. {
  4338. 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"));
  4339. }
  4340. else
  4341. {
  4342. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4343. }
  4344. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4345. {
  4346. 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")));
  4347. }
  4348. else
  4349. {
  4350. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4351. }
  4352. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4353. {
  4354. 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"));
  4355. }
  4356. else
  4357. {
  4358. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4359. }
  4360. }
  4361. }
  4362. }
  4363. else
  4364. {
  4365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4366. {
  4367. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4368. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4369. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4370. }
  4371. if(maxProfile.id == -1)
  4372. DEBUG_INFO("MaxProfile found.\n");
  4373. else
  4374. DEBUG_INFO("MaxProfile updated.\n");
  4375. // Required item
  4376. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4377. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4378. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4379. if(isUnitA)
  4380. {
  4381. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4382. 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++)
  4383. {
  4384. 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"));
  4385. 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"));
  4386. /*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)
  4387. {
  4388. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4389. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4390. else
  4391. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4392. }
  4393. else
  4394. {
  4395. 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"));
  4396. }*/
  4397. 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")));
  4398. }
  4399. }
  4400. else
  4401. {
  4402. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4403. 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++)
  4404. {
  4405. 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"));
  4406. 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"));
  4407. /*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)
  4408. {
  4409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4410. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4411. else
  4412. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4413. }
  4414. else
  4415. {
  4416. 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"));
  4417. }*/
  4418. 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));
  4419. }
  4420. }
  4421. // Optional item
  4422. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4423. {
  4424. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4425. }
  4426. else
  4427. {
  4428. sprintf((char*)maxProfile.validFrom, " ");
  4429. }
  4430. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4431. {
  4432. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4433. }
  4434. else
  4435. {
  4436. sprintf((char*)maxProfile.validTo, " ");
  4437. }
  4438. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4439. {
  4440. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4441. }
  4442. else
  4443. {
  4444. sprintf((char*)maxProfile.recurrencyKind, " ");
  4445. }
  4446. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4447. {
  4448. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4449. }
  4450. else
  4451. {
  4452. sprintf((char*)maxProfile.transactionId, " ");
  4453. }
  4454. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4455. {
  4456. 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"));
  4457. }
  4458. else
  4459. {
  4460. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4461. }
  4462. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4463. {
  4464. 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")));
  4465. }
  4466. else
  4467. {
  4468. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4469. }
  4470. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4471. {
  4472. 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"));
  4473. }
  4474. else
  4475. {
  4476. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4477. }
  4478. }
  4479. }
  4480. }
  4481. json_object_put(obj);
  4482. }
  4483. fclose(fp);
  4484. /*
  4485. if(maxProfile.id !=-1)
  4486. {
  4487. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4488. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4489. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4490. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4491. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4492. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4493. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4494. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4495. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4496. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4497. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4498. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4499. {
  4500. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4501. {
  4502. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4503. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4504. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4505. }
  4506. }
  4507. }
  4508. else
  4509. DEBUG_INFO("MaxProfile not found.\n");
  4510. DEBUG_INFO("------------------------------------\n");*/
  4511. }
  4512. if(maxProfile.id != -1)
  4513. {
  4514. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4515. {
  4516. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4517. {
  4518. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4519. 0:
  4520. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4521. }
  4522. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4523. {
  4524. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4525. {
  4526. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4527. 0:
  4528. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4529. if(idxPeriod > 0)
  4530. {
  4531. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4532. {
  4533. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4534. }
  4535. }
  4536. }
  4537. }
  4538. }
  4539. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4540. {
  4541. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4542. {
  4543. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  4544. }
  4545. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4546. {
  4547. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4548. {
  4549. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  4550. if(idxPeriod > 0)
  4551. {
  4552. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4553. {
  4554. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4555. }
  4556. }
  4557. }
  4558. }
  4559. }
  4560. else
  4561. {
  4562. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4563. {
  4564. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4565. {
  4566. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4567. 0:
  4568. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4569. }
  4570. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4571. {
  4572. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4573. {
  4574. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4575. 0:
  4576. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4577. if(idxPeriod > 0)
  4578. {
  4579. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4580. {
  4581. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4582. }
  4583. }
  4584. }
  4585. }
  4586. }
  4587. else
  4588. {
  4589. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4590. {
  4591. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4592. 0:
  4593. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4594. }
  4595. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4596. {
  4597. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4598. {
  4599. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4600. 0:
  4601. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4602. if(idxPeriod > 0)
  4603. {
  4604. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4605. {
  4606. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4607. }
  4608. }
  4609. }
  4610. }
  4611. }
  4612. }
  4613. /*
  4614. DEBUG_INFO("MaxProfile after align.\n");
  4615. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4616. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4617. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4618. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4619. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4620. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4621. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4622. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4623. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4624. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4625. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4626. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4627. {
  4628. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4629. {
  4630. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4631. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4632. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4633. }
  4634. }
  4635. DEBUG_INFO("------------------------------------\n");*/
  4636. }
  4637. // Find each profile period quantity
  4638. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4639. {
  4640. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4641. limitMax = idx+1;
  4642. }
  4643. if(maxProfile.id != -1)
  4644. {
  4645. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4646. {
  4647. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4648. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4649. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4650. {
  4651. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4652. {
  4653. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4654. compositePeriodIdx++;
  4655. }
  4656. else
  4657. {
  4658. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4659. }
  4660. }
  4661. }
  4662. }
  4663. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  4664. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4665. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  4666. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  4667. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4668. {
  4669. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4670. {
  4671. compositeProfile.id = 1;
  4672. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4673. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4674. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4675. }
  4676. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4677. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4678. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4679. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4680. }
  4681. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4682. if(line)
  4683. free(line);
  4684. }
  4685. void checkCompositeSchedule(uint8_t evseId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4686. {
  4687. FILE *fp;
  4688. char profileFileName[128];
  4689. char *line = NULL;
  4690. size_t len = 0;
  4691. time_t CurrentTime;
  4692. struct tm *tmComposite;
  4693. struct ChargingProfileType maxProfile;
  4694. struct ChargingProfileType defaultTxProfile;
  4695. struct ChargingProfileType txProfile;
  4696. struct ChargingProfileType compositeProfile;
  4697. struct ChargingSchedulePeriodType tmpPeriod;
  4698. uint8_t limitMax=0;
  4699. uint8_t limitDef=0;
  4700. uint8_t limitTx=0;
  4701. int compositePeriodIdx = 0;
  4702. CurrentTime = time(NULL);
  4703. tmComposite=localtime(&CurrentTime);
  4704. 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);
  4705. if(isUnitA)
  4706. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4707. else
  4708. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4709. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4711. {
  4712. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4713. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4714. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4715. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4716. }
  4717. compositeProfile.id = 0;
  4718. compositeProfile.stackLevel = 99 ;
  4719. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  4720. maxProfile.id = -1;
  4721. defaultTxProfile.id = -1;
  4722. txProfile.id = -1;
  4723. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4724. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  4725. txProfile.chargingSchedule[idxSchedule].duration = -1;
  4726. system("rm -f /tmp/*.json");
  4727. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4728. /*
  4729. * Search valid charging profile
  4730. */
  4731. //DEBUG_INFO("====================================\n");
  4732. // Search tx profile
  4733. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", evseId);
  4734. if((access(profileFileName, F_OK))!=-1)
  4735. {
  4736. fp = fopen(profileFileName, "r");
  4737. while(getline(&line, &len, fp) != -1)
  4738. {
  4739. json_object *obj = NULL;
  4740. obj = json_tokener_parse(line);
  4741. if(is_error(obj))
  4742. {
  4743. DEBUG_ERROR("Parse txProfile from file error.\n");
  4744. }
  4745. else
  4746. {
  4747. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  4748. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  4749. )
  4750. {
  4751. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4752. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4753. )
  4754. {
  4755. struct tm tmFrom, tmTo;
  4756. struct timeb tbFrom, tbTo;
  4757. 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) &&
  4758. (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))
  4759. {
  4760. tmFrom.tm_year -= 1900;
  4761. tmFrom.tm_mon -= 1;
  4762. tbFrom.time = mktime(&tmFrom);
  4763. tmTo.tm_year -= 1900;
  4764. tmTo.tm_mon -= 1;
  4765. tbTo.time = mktime(&tmTo);
  4766. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4767. {
  4768. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4769. {
  4770. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4771. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4772. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4773. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4774. }
  4775. if(txProfile.id == -1)
  4776. DEBUG_INFO("TxProfile found.\n");
  4777. else
  4778. DEBUG_INFO("TxProfile updated.\n");
  4779. // Required item
  4780. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4781. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4782. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4783. if(isUnitA)
  4784. {
  4785. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4786. 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++)
  4787. {
  4788. 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"));
  4789. 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"));
  4790. /*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)
  4791. {
  4792. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4793. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4794. else
  4795. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4796. }
  4797. else
  4798. {
  4799. 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"));
  4800. }*/
  4801. 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")));
  4802. }
  4803. }
  4804. else
  4805. {
  4806. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4807. 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++)
  4808. {
  4809. 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"));
  4810. 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"));
  4811. /*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)
  4812. {
  4813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4814. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4815. else
  4816. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4817. }
  4818. else
  4819. {
  4820. 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"));
  4821. }*/
  4822. 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));
  4823. }
  4824. }
  4825. // Optional item
  4826. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4827. {
  4828. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4829. }
  4830. else
  4831. {
  4832. sprintf((char*)txProfile.validFrom, " ");
  4833. }
  4834. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4835. {
  4836. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4837. }
  4838. else
  4839. {
  4840. sprintf((char*)txProfile.validTo, " ");
  4841. }
  4842. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4843. {
  4844. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4845. }
  4846. else
  4847. {
  4848. sprintf((char*)txProfile.recurrencyKind, " ");
  4849. }
  4850. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4851. {
  4852. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4853. }
  4854. else
  4855. {
  4856. sprintf((char*)txProfile.transactionId, " ");
  4857. }
  4858. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4859. {
  4860. 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"));
  4861. }
  4862. else
  4863. {
  4864. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4865. }
  4866. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4867. {
  4868. 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")));
  4869. }
  4870. else
  4871. {
  4872. 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));
  4873. }
  4874. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4875. {
  4876. 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"));
  4877. }
  4878. else
  4879. {
  4880. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4881. }
  4882. }
  4883. }
  4884. }
  4885. else
  4886. {
  4887. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4888. {
  4889. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4890. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4891. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4892. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4893. }
  4894. if(txProfile.id == -1)
  4895. DEBUG_INFO("TxProfile found.\n");
  4896. else
  4897. DEBUG_INFO("TxProfile updated.\n");
  4898. // Required item
  4899. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4900. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4901. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4902. if(isUnitA)
  4903. {
  4904. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4905. 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++)
  4906. {
  4907. 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"));
  4908. 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"));
  4909. /*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)
  4910. {
  4911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4912. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4913. else
  4914. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4915. }
  4916. else
  4917. {
  4918. 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"));
  4919. }*/
  4920. 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")));
  4921. }
  4922. }
  4923. else
  4924. {
  4925. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4926. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4927. {
  4928. 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"));
  4929. 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"));
  4930. /*if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4931. {
  4932. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4933. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4934. else
  4935. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4936. }
  4937. else
  4938. {
  4939. 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"));
  4940. }*/
  4941. 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));
  4942. }
  4943. }
  4944. // Optional item
  4945. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4946. {
  4947. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4948. }
  4949. else
  4950. {
  4951. sprintf((char*)txProfile.validFrom, " ");
  4952. }
  4953. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4954. {
  4955. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4956. }
  4957. else
  4958. {
  4959. sprintf((char*)txProfile.validTo, " ");
  4960. }
  4961. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4962. {
  4963. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4964. }
  4965. else
  4966. {
  4967. sprintf((char*)txProfile.recurrencyKind, " ");
  4968. }
  4969. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4970. {
  4971. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4972. }
  4973. else
  4974. {
  4975. sprintf((char*)txProfile.transactionId, " ");
  4976. }
  4977. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4978. {
  4979. 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"));
  4980. }
  4981. else
  4982. {
  4983. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4984. }
  4985. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4986. {
  4987. 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")));
  4988. }
  4989. else
  4990. {
  4991. 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));
  4992. }
  4993. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4994. {
  4995. 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"));
  4996. }
  4997. else
  4998. {
  4999. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5000. }
  5001. }
  5002. }
  5003. }
  5004. json_object_put(obj);
  5005. }
  5006. fclose(fp);
  5007. /*
  5008. if(txProfile.id != -1)
  5009. {
  5010. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  5011. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  5012. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  5013. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  5014. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  5015. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  5016. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  5017. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  5018. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  5019. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5020. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5021. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5022. {
  5023. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5024. {
  5025. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5026. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5027. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5028. }
  5029. }
  5030. }
  5031. else
  5032. DEBUG_INFO("TxProfile not found.\n");*/
  5033. }
  5034. // Search default tx profile
  5035. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", evseId);
  5036. if((access(profileFileName, F_OK))==-1)
  5037. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  5038. if((access(profileFileName, F_OK))!=-1)
  5039. {
  5040. fp = fopen(profileFileName, "r");
  5041. while(getline(&line, &len, fp) != -1)
  5042. {
  5043. json_object *obj = NULL;
  5044. obj = json_tokener_parse(line);
  5045. if(is_error(obj))
  5046. {
  5047. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  5048. }
  5049. else
  5050. {
  5051. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  5052. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  5053. )
  5054. {
  5055. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  5056. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5057. )
  5058. {
  5059. struct tm tmFrom, tmTo;
  5060. struct timeb tbFrom, tbTo;
  5061. 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) &&
  5062. (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))
  5063. {
  5064. tmFrom.tm_year -= 1900;
  5065. tmFrom.tm_mon -= 1;
  5066. tbFrom.time = mktime(&tmFrom);
  5067. tmTo.tm_year -= 1900;
  5068. tmTo.tm_mon -= 1;
  5069. tbTo.time = mktime(&tmTo);
  5070. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  5071. {
  5072. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5073. {
  5074. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5075. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5076. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5077. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  5078. }
  5079. if(defaultTxProfile.id == -1)
  5080. DEBUG_INFO("TxDefaultProfile found.\n");
  5081. else
  5082. DEBUG_INFO("TxDefaultProfile updated.\n");
  5083. // Required item
  5084. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5085. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5086. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5087. if(isUnitA)
  5088. {
  5089. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5090. 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++)
  5091. {
  5092. 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"));
  5093. 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"));
  5094. /*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)
  5095. {
  5096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5097. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5098. else
  5099. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5100. }
  5101. else
  5102. {
  5103. 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"));
  5104. }*/
  5105. 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")));
  5106. }
  5107. }
  5108. else
  5109. {
  5110. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5111. 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++)
  5112. {
  5113. 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"));
  5114. 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"));
  5115. /*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)
  5116. {
  5117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5118. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5119. else
  5120. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5121. }
  5122. else
  5123. {
  5124. 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"));
  5125. }*/
  5126. 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));
  5127. }
  5128. }
  5129. // Optional item
  5130. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5131. {
  5132. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5133. }
  5134. else
  5135. {
  5136. sprintf((char*)defaultTxProfile.validFrom, " ");
  5137. }
  5138. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5139. {
  5140. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5141. }
  5142. else
  5143. {
  5144. sprintf((char*)defaultTxProfile.validTo, " ");
  5145. }
  5146. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5147. {
  5148. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5149. }
  5150. else
  5151. {
  5152. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  5153. }
  5154. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5155. {
  5156. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5157. }
  5158. else
  5159. {
  5160. sprintf((char*)defaultTxProfile.transactionId, " ");
  5161. }
  5162. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5163. {
  5164. 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"));
  5165. }
  5166. else
  5167. {
  5168. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5169. }
  5170. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5171. {
  5172. 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")));
  5173. }
  5174. else
  5175. {
  5176. 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));
  5177. }
  5178. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5179. {
  5180. 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"));
  5181. }
  5182. else
  5183. {
  5184. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5185. }
  5186. }
  5187. }
  5188. }
  5189. else
  5190. {
  5191. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5192. {
  5193. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5194. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5195. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5196. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  5197. }
  5198. if(defaultTxProfile.id == -1)
  5199. DEBUG_INFO("TxDefaultProfile found.\n");
  5200. else
  5201. DEBUG_INFO("TxDefaultProfile updated.\n");
  5202. // Required item
  5203. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5204. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5205. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5206. if(isUnitA)
  5207. {
  5208. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5209. 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++)
  5210. {
  5211. 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"));
  5212. 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"));
  5213. /*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)
  5214. {
  5215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5216. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5217. else
  5218. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5219. }
  5220. else
  5221. {
  5222. 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"));
  5223. }*/
  5224. 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")));
  5225. }
  5226. }
  5227. else
  5228. {
  5229. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5230. 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++)
  5231. {
  5232. 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"));
  5233. 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"));
  5234. /*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)
  5235. {
  5236. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5237. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5238. else
  5239. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5240. }
  5241. else
  5242. {
  5243. 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"));
  5244. }*/
  5245. 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));
  5246. }
  5247. }
  5248. // Optional item
  5249. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5250. {
  5251. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5252. }
  5253. else
  5254. {
  5255. sprintf((char*)defaultTxProfile.validFrom, " ");
  5256. }
  5257. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5258. {
  5259. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5260. }
  5261. else
  5262. {
  5263. sprintf((char*)defaultTxProfile.validTo, " ");
  5264. }
  5265. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5266. {
  5267. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5268. }
  5269. else
  5270. {
  5271. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  5272. }
  5273. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5274. {
  5275. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5276. }
  5277. else
  5278. {
  5279. sprintf((char*)defaultTxProfile.transactionId, " ");
  5280. }
  5281. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5282. {
  5283. 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"));
  5284. }
  5285. else
  5286. {
  5287. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5288. }
  5289. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5290. {
  5291. 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")));
  5292. }
  5293. else
  5294. {
  5295. 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));
  5296. }
  5297. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5298. {
  5299. 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"));
  5300. }
  5301. else
  5302. {
  5303. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5304. }
  5305. }
  5306. }
  5307. }
  5308. json_object_put(obj);
  5309. }
  5310. fclose(fp);
  5311. /*
  5312. if(defaultTxProfile.id != -1)
  5313. {
  5314. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5315. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5316. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5317. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5318. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5319. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5320. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5321. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5322. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5323. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5324. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5325. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5326. {
  5327. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5328. {
  5329. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5330. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5331. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5332. }
  5333. }
  5334. }
  5335. else
  5336. DEBUG_INFO("TxDefaultProfile not found.\n");
  5337. DEBUG_INFO("------------------------------------\n");*/
  5338. }
  5339. // Search max profile
  5340. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  5341. if((access(profileFileName, F_OK))!=-1)
  5342. {
  5343. fp = fopen(profileFileName, "r");
  5344. while(getline(&line, &len, fp) != -1)
  5345. {
  5346. json_object *obj = NULL;
  5347. obj = json_tokener_parse(line);
  5348. if(is_error(obj))
  5349. {
  5350. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  5351. }
  5352. else
  5353. {
  5354. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  5355. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  5356. )
  5357. {
  5358. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  5359. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5360. )
  5361. {
  5362. struct tm tmFrom, tmTo;
  5363. struct timeb tbFrom, tbTo;
  5364. 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) &&
  5365. (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))
  5366. {
  5367. tmFrom.tm_year -= 1900;
  5368. tmFrom.tm_mon -= 1;
  5369. tbFrom.time = mktime(&tmFrom);
  5370. tmTo.tm_year -= 1900;
  5371. tmTo.tm_mon -= 1;
  5372. tbTo.time = mktime(&tmTo);
  5373. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  5374. {
  5375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5376. {
  5377. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5378. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5379. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5380. }
  5381. if(maxProfile.id == -1)
  5382. DEBUG_INFO("MaxProfile found.\n");
  5383. else
  5384. DEBUG_INFO("MaxProfile updated.\n");
  5385. // Required item
  5386. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5387. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5388. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5389. if(isUnitA)
  5390. {
  5391. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5392. 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++)
  5393. {
  5394. 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"));
  5395. 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"));
  5396. /*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)
  5397. {
  5398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5399. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5400. else
  5401. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5402. }
  5403. else
  5404. {
  5405. 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"));
  5406. }*/
  5407. 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")));
  5408. }
  5409. }
  5410. else
  5411. {
  5412. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5413. 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++)
  5414. {
  5415. 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"));
  5416. 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"));
  5417. /*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)
  5418. {
  5419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5420. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5421. else
  5422. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5423. }
  5424. else
  5425. {
  5426. 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"));
  5427. }*/
  5428. 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));
  5429. }
  5430. }
  5431. // Optional item
  5432. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5433. {
  5434. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5435. }
  5436. else
  5437. {
  5438. sprintf((char*)maxProfile.validFrom, " ");
  5439. }
  5440. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5441. {
  5442. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5443. }
  5444. else
  5445. {
  5446. sprintf((char*)maxProfile.validTo, " ");
  5447. }
  5448. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5449. {
  5450. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5451. }
  5452. else
  5453. {
  5454. sprintf((char*)maxProfile.recurrencyKind, " ");
  5455. }
  5456. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5457. {
  5458. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5459. }
  5460. else
  5461. {
  5462. sprintf((char*)maxProfile.transactionId, " ");
  5463. }
  5464. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5465. {
  5466. 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"));
  5467. }
  5468. else
  5469. {
  5470. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5471. }
  5472. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5473. {
  5474. 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")));
  5475. }
  5476. else
  5477. {
  5478. 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));
  5479. }
  5480. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5481. {
  5482. 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"));
  5483. }
  5484. else
  5485. {
  5486. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5487. }
  5488. }
  5489. }
  5490. }
  5491. else
  5492. {
  5493. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5494. {
  5495. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5496. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5497. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5498. }
  5499. if(maxProfile.id == -1)
  5500. DEBUG_INFO("MaxProfile found.\n");
  5501. else
  5502. DEBUG_INFO("MaxProfile updated.\n");
  5503. // Required item
  5504. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5505. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5506. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5507. if(isUnitA)
  5508. {
  5509. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5510. 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++)
  5511. {
  5512. 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"));
  5513. 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"));
  5514. /*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)
  5515. {
  5516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5517. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5518. else
  5519. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5520. }
  5521. else
  5522. {
  5523. 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"));
  5524. }*/
  5525. 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")));
  5526. }
  5527. }
  5528. else
  5529. {
  5530. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5531. 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++)
  5532. {
  5533. 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"));
  5534. 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"));
  5535. /*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)
  5536. {
  5537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5538. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5539. else
  5540. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5541. }
  5542. else
  5543. {
  5544. 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"));
  5545. }*/
  5546. 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));
  5547. }
  5548. }
  5549. // Optional item
  5550. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5551. {
  5552. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5553. }
  5554. else
  5555. {
  5556. sprintf((char*)maxProfile.validFrom, " ");
  5557. }
  5558. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5559. {
  5560. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5561. }
  5562. else
  5563. {
  5564. sprintf((char*)maxProfile.validTo, " ");
  5565. }
  5566. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5567. {
  5568. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5569. }
  5570. else
  5571. {
  5572. sprintf((char*)maxProfile.recurrencyKind, " ");
  5573. }
  5574. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5575. {
  5576. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5577. }
  5578. else
  5579. {
  5580. sprintf((char*)maxProfile.transactionId, " ");
  5581. }
  5582. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5583. {
  5584. 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"));
  5585. }
  5586. else
  5587. {
  5588. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5589. }
  5590. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5591. {
  5592. 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")));
  5593. }
  5594. else
  5595. {
  5596. 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));
  5597. }
  5598. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5599. {
  5600. 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"));
  5601. }
  5602. else
  5603. {
  5604. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5605. }
  5606. }
  5607. }
  5608. }
  5609. json_object_put(obj);
  5610. }
  5611. fclose(fp);
  5612. /*
  5613. if(maxProfile.id !=-1)
  5614. {
  5615. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5616. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5617. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5618. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5619. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5620. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5621. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5622. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5623. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5624. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5625. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5626. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5627. {
  5628. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5629. {
  5630. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5631. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5632. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5633. }
  5634. }
  5635. }
  5636. else
  5637. DEBUG_INFO("MaxProfile not found.\n");
  5638. DEBUG_INFO("------------------------------------\n");*/
  5639. }
  5640. /*
  5641. * Align found profile start schedule & periods
  5642. */
  5643. //DEBUG_INFO("====================================\n");
  5644. /*
  5645. // For local test usage, force modify found profile start schedule info
  5646. 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);
  5647. 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);
  5648. 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);
  5649. */
  5650. if(txProfile.id != -1)
  5651. {
  5652. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5653. {
  5654. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5655. {
  5656. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5657. 0:
  5658. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5659. }
  5660. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5661. {
  5662. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5663. {
  5664. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5665. 0:
  5666. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5667. if(idxPeriod > 0)
  5668. {
  5669. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5670. {
  5671. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5672. }
  5673. }
  5674. }
  5675. }
  5676. }
  5677. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5678. {
  5679. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5680. {
  5681. 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?
  5682. 0:
  5683. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5684. }
  5685. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5686. {
  5687. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5688. {
  5689. 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?
  5690. 0:
  5691. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5692. if(idxPeriod > 0)
  5693. {
  5694. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5695. {
  5696. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5697. }
  5698. }
  5699. }
  5700. }
  5701. }
  5702. else
  5703. {
  5704. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5705. {
  5706. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5707. {
  5708. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5709. 0:
  5710. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5711. }
  5712. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5713. {
  5714. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5715. {
  5716. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5717. 0:
  5718. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5719. if(idxPeriod > 0)
  5720. {
  5721. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5722. {
  5723. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5724. }
  5725. }
  5726. }
  5727. }
  5728. }
  5729. else
  5730. {
  5731. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5732. {
  5733. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5734. 0:
  5735. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5736. }
  5737. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5738. {
  5739. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5740. {
  5741. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5742. 0:
  5743. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5744. if(idxPeriod > 0)
  5745. {
  5746. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5747. {
  5748. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5749. }
  5750. }
  5751. }
  5752. }
  5753. }
  5754. }
  5755. /*
  5756. DEBUG_INFO("txProfile after align.\n");
  5757. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  5758. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  5759. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  5760. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  5761. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  5762. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  5763. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  5764. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5765. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  5766. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5767. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5768. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5769. {
  5770. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5771. {
  5772. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5773. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5774. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5775. }
  5776. }*/
  5777. }
  5778. if(defaultTxProfile.id != -1)
  5779. {
  5780. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5781. {
  5782. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5783. {
  5784. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5785. 0:
  5786. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5787. }
  5788. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5789. {
  5790. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5791. {
  5792. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5793. 0:
  5794. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5795. if(idxPeriod > 0)
  5796. {
  5797. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5798. {
  5799. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5800. }
  5801. }
  5802. }
  5803. }
  5804. }
  5805. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5806. {
  5807. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5808. {
  5809. 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?
  5810. 0:
  5811. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5812. }
  5813. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5814. {
  5815. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5816. {
  5817. 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?
  5818. 0:
  5819. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5820. if(idxPeriod > 0)
  5821. {
  5822. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5823. {
  5824. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5825. }
  5826. }
  5827. }
  5828. }
  5829. }
  5830. else
  5831. {
  5832. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5833. {
  5834. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5835. {
  5836. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5837. 0:
  5838. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5839. }
  5840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5841. {
  5842. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5843. {
  5844. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5845. 0:
  5846. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5847. if(idxPeriod > 0)
  5848. {
  5849. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5850. {
  5851. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5852. }
  5853. }
  5854. }
  5855. }
  5856. }
  5857. else
  5858. {
  5859. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5860. {
  5861. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5862. 0:
  5863. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5864. }
  5865. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5866. {
  5867. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5868. {
  5869. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5870. 0:
  5871. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5872. if(idxPeriod > 0)
  5873. {
  5874. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5875. {
  5876. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5877. }
  5878. }
  5879. }
  5880. }
  5881. }
  5882. }
  5883. /*
  5884. DEBUG_INFO("defaultTxProfile after align.\n");
  5885. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5886. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5887. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5888. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5889. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5890. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5891. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5892. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5893. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5894. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5895. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5896. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5897. {
  5898. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5899. {
  5900. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5901. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5902. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5903. }
  5904. }
  5905. DEBUG_INFO("------------------------------------\n");*/
  5906. }
  5907. if(maxProfile.id != -1)
  5908. {
  5909. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5910. {
  5911. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5912. {
  5913. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5914. 0:
  5915. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5916. }
  5917. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5918. {
  5919. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5920. {
  5921. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5922. 0:
  5923. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5924. if(idxPeriod > 0)
  5925. {
  5926. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5927. {
  5928. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5929. }
  5930. }
  5931. }
  5932. }
  5933. }
  5934. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5935. {
  5936. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5937. {
  5938. 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?
  5939. 0:
  5940. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5941. }
  5942. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5943. {
  5944. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5945. {
  5946. 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?
  5947. 0:
  5948. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5949. if(idxPeriod > 0)
  5950. {
  5951. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5952. {
  5953. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5954. }
  5955. }
  5956. }
  5957. }
  5958. }
  5959. else
  5960. {
  5961. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5962. {
  5963. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5964. {
  5965. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5966. 0:
  5967. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5968. }
  5969. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5970. {
  5971. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5972. {
  5973. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5974. 0:
  5975. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5976. if(idxPeriod > 0)
  5977. {
  5978. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5979. {
  5980. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5981. }
  5982. }
  5983. }
  5984. }
  5985. }
  5986. else
  5987. {
  5988. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5989. {
  5990. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5991. 0:
  5992. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5993. }
  5994. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5995. {
  5996. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5997. {
  5998. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5999. 0:
  6000. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  6001. if(idxPeriod > 0)
  6002. {
  6003. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  6004. {
  6005. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  6006. }
  6007. }
  6008. }
  6009. }
  6010. }
  6011. }
  6012. /*
  6013. DEBUG_INFO("MaxProfile after align.\n");
  6014. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  6015. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  6016. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  6017. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  6018. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  6019. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  6020. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  6021. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  6022. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  6023. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  6024. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  6025. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  6026. {
  6027. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  6028. {
  6029. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  6030. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  6031. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  6032. }
  6033. }
  6034. DEBUG_INFO("------------------------------------\n");*/
  6035. }
  6036. /*
  6037. * Merge to conposite schedule
  6038. */
  6039. //DEBUG_INFO("====================================\n");
  6040. // Find each profile period quantity
  6041. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  6042. {
  6043. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  6044. limitMax = idx+1;
  6045. }
  6046. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  6047. {
  6048. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  6049. limitDef = idx+1;
  6050. }
  6051. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  6052. {
  6053. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  6054. limitTx = idx+1;
  6055. }
  6056. // TxProfile found, composite schedule based on it
  6057. if(txProfile.id != -1)
  6058. {
  6059. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  6060. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  6061. {
  6062. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  6063. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  6064. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  6065. {
  6066. if(maxProfile.id != -1)
  6067. {
  6068. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6069. {
  6070. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  6071. {
  6072. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6073. {
  6074. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  6075. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  6076. 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);
  6077. }
  6078. else
  6079. {
  6080. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  6081. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  6082. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  6083. }
  6084. }
  6085. if(idxMaxPeriod == (limitMax-1))
  6086. {
  6087. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6088. {
  6089. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6090. {
  6091. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6092. compositePeriodIdx++;
  6093. }
  6094. else
  6095. {
  6096. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6097. }
  6098. }
  6099. }
  6100. }
  6101. }
  6102. else
  6103. {
  6104. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6105. {
  6106. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  6107. compositePeriodIdx++;
  6108. }
  6109. else
  6110. {
  6111. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  6112. }
  6113. }
  6114. }
  6115. if(idxTxPeriod == (limitTx-1))
  6116. {
  6117. if(defaultTxProfile.id != -1)
  6118. {
  6119. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  6120. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  6121. {
  6122. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  6123. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  6124. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  6125. {
  6126. if(maxProfile.id != -1)
  6127. {
  6128. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6129. {
  6130. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  6131. {
  6132. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6133. {
  6134. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6135. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6136. 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);
  6137. }
  6138. else
  6139. {
  6140. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6141. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6142. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  6143. }
  6144. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6145. {
  6146. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6147. {
  6148. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6149. compositePeriodIdx++;
  6150. }
  6151. else
  6152. {
  6153. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6154. }
  6155. }
  6156. // Delete duplicate period
  6157. if(compositePeriodIdx > 1)
  6158. {
  6159. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6160. {
  6161. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6162. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6163. compositePeriodIdx -= 1;
  6164. }
  6165. }
  6166. }
  6167. else
  6168. {
  6169. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6170. {
  6171. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6172. compositePeriodIdx++;
  6173. }
  6174. else
  6175. {
  6176. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6177. }
  6178. break;
  6179. }
  6180. }
  6181. }
  6182. else
  6183. {
  6184. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6185. {
  6186. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6187. compositePeriodIdx++;
  6188. }
  6189. else
  6190. {
  6191. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6192. }
  6193. }
  6194. }
  6195. }
  6196. }
  6197. }
  6198. }
  6199. }
  6200. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  6201. else if(defaultTxProfile.id != -1)
  6202. {
  6203. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  6204. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  6205. {
  6206. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  6207. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  6208. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  6209. {
  6210. if(maxProfile.id != -1)
  6211. {
  6212. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6213. {
  6214. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  6215. {
  6216. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6217. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6218. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6219. {
  6220. 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);
  6221. }
  6222. else
  6223. {
  6224. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  6225. }
  6226. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6227. {
  6228. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6229. {
  6230. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6231. compositePeriodIdx++;
  6232. }
  6233. else
  6234. {
  6235. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6236. }
  6237. }
  6238. // Delete duplicate period
  6239. if(compositePeriodIdx > 1)
  6240. {
  6241. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6242. {
  6243. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6244. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6245. compositePeriodIdx -= 1;
  6246. }
  6247. }
  6248. }
  6249. else
  6250. {
  6251. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6252. {
  6253. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6254. compositePeriodIdx++;
  6255. }
  6256. else
  6257. {
  6258. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6259. }
  6260. break;
  6261. }
  6262. }
  6263. }
  6264. else
  6265. {
  6266. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6267. {
  6268. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6269. compositePeriodIdx++;
  6270. }
  6271. else
  6272. {
  6273. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6274. }
  6275. }
  6276. }
  6277. }
  6278. }
  6279. // Fill other period by MaxProfile
  6280. if(maxProfile.id != -1)
  6281. {
  6282. if(compositePeriodIdx==0)
  6283. {
  6284. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  6285. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  6286. {
  6287. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6288. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6289. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6290. {
  6291. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6292. {
  6293. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6294. compositePeriodIdx++;
  6295. }
  6296. else
  6297. {
  6298. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6299. }
  6300. }
  6301. }
  6302. }
  6303. else
  6304. {
  6305. int lastCompositePeriodIdx = compositePeriodIdx;
  6306. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6307. {
  6308. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6309. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6310. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6311. {
  6312. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  6313. {
  6314. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  6315. {
  6316. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6317. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6318. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  6319. }
  6320. else
  6321. {
  6322. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6323. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6324. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  6325. }
  6326. }
  6327. if(tmpPeriod.limit != -1)
  6328. {
  6329. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  6330. {
  6331. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  6332. {
  6333. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6334. compositePeriodIdx++;
  6335. }
  6336. else
  6337. {
  6338. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6339. }
  6340. }
  6341. // Delete duplicate period
  6342. if(compositePeriodIdx > 1)
  6343. {
  6344. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6345. {
  6346. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6347. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6348. compositePeriodIdx -= 1;
  6349. }
  6350. }
  6351. }
  6352. }
  6353. }
  6354. }
  6355. }
  6356. if(compositeProfile.chargingSchedule[idxSchedule].duration < durationReq)
  6357. {
  6358. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6359. {
  6360. if((idxPeriod >= 0) && (compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1))
  6361. {
  6362. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = compositeProfile.chargingSchedule[idxSchedule].duration;
  6363. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  6364. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].numberPhases;
  6365. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  6366. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6367. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6368. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6369. DEBUG_INFO("------------------------------------------------\n");
  6370. break;
  6371. }
  6372. }
  6373. }
  6374. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  6375. DEBUG_INFO("Connector-%d composite schedule ready.\n", evseId);
  6376. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  6377. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  6378. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  6379. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6380. {
  6381. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  6382. {
  6383. compositeProfile.id = 1;
  6384. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6385. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6386. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6387. }
  6388. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  6389. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  6390. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  6391. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  6392. }
  6393. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  6394. if(line)
  6395. free(line);
  6396. ShmOCPP20Data->CSUMsg.bits[(evseId==0?0:evseId-1)].ChargingProfileConf = ON;
  6397. }
  6398. //==========================================
  6399. // Init all share memory
  6400. //==========================================
  6401. int InitShareMemory()
  6402. {
  6403. int result = PASS;
  6404. int MeterSMId;
  6405. //creat ShmSysConfigAndInfo
  6406. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  6407. {
  6408. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  6409. result = FAIL;
  6410. }
  6411. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6412. {
  6413. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  6414. result = FAIL;
  6415. }
  6416. else
  6417. {}
  6418. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  6419. {
  6420. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  6421. result = FAIL;
  6422. }
  6423. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6424. {
  6425. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  6426. result = FAIL;
  6427. }
  6428. else
  6429. {}
  6430. //creat ShmPsuData
  6431. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  6432. {
  6433. DEBUG_ERROR("shmget ShmPsuData NG\n");
  6434. result = FAIL;
  6435. }
  6436. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6437. {
  6438. DEBUG_ERROR("shmat ShmPsuData NG\n");
  6439. result = FAIL;
  6440. }
  6441. else
  6442. {}
  6443. //creat ShmOCPP20Data
  6444. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  6445. {
  6446. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  6447. result = FAIL;
  6448. }
  6449. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6450. {
  6451. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  6452. result = FAIL;
  6453. }
  6454. else
  6455. {}
  6456. /****************************** For Initial Settings************************************************/
  6457. /*
  6458. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  6459. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  6460. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  6461. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  6462. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  6463. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  6464. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  6465. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  6466. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  6467. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  6468. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  6469. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  6470. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  6471. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  6472. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  6473. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  6474. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  6475. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  6476. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  6477. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  6478. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  6479. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  6480. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  6481. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  6482. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  6483. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  6484. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  6485. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  6486. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  6487. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  6488. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  6489. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  6490. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  6491. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  6492. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  6493. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  6494. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  6495. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  6496. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  6497. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  6498. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  6499. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  6500. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  6501. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  6502. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  6503. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  6504. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  6505. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  6506. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  6507. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  6508. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  6509. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  6510. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  6511. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  6512. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  6513. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  6514. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  6515. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  6516. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  6517. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  6518. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  6519. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  6520. */
  6521. return result;
  6522. }
  6523. int ProcessShareMemory()
  6524. {
  6525. int result = PASS;
  6526. if(InitShareMemory() == FAIL)
  6527. {
  6528. DEBUG_ERROR("InitShareMemory NG\n");
  6529. if(ShmStatusCodeData!=NULL)
  6530. {
  6531. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  6532. }
  6533. result = FAIL;
  6534. }
  6535. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  6536. {
  6537. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  6538. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6539. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  6540. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  6541. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  6542. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L') ||
  6543. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='Z'))
  6544. ) // 'D' means DC
  6545. {
  6546. // DO series
  6547. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  6548. {
  6549. gunTotalNumber += 1;
  6550. gunType[gun_index] = GUN_TYPE_DO;
  6551. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6552. {
  6553. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  6554. {
  6555. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6556. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6557. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  6558. }
  6559. }
  6560. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6561. {
  6562. case Gun_Type_Chademo:
  6563. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  6564. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6567. {
  6568. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6569. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6570. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  6571. }
  6572. }
  6573. break;
  6574. case Gun_Type_CCS_2:
  6575. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  6576. for (int index = 0; index < CCS_QUANTITY; index++)
  6577. {
  6578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6579. {
  6580. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6581. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6582. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  6583. }
  6584. }
  6585. break;
  6586. case Gun_Type_GB:
  6587. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  6588. for (int index = 0; index < GB_QUANTITY; index++)
  6589. {
  6590. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6591. {
  6592. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6593. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6594. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  6595. }
  6596. }
  6597. break;
  6598. case Gun_Type_AC:
  6599. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  6600. for (int index = 0; index < AC_QUANTITY; index++)
  6601. {
  6602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6603. {
  6604. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6605. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6606. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  6607. }
  6608. }
  6609. break;
  6610. default:
  6611. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  6612. break;
  6613. }
  6614. }
  6615. }
  6616. else
  6617. {
  6618. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  6619. {
  6620. gunTotalNumber += 1;
  6621. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6622. {
  6623. case Gun_Type_Chademo:
  6624. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  6625. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  6626. break;
  6627. case Gun_Type_CCS_2:
  6628. gunType[gun_index] = GUN_TYPE_CCS;
  6629. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  6630. break;
  6631. case Gun_Type_GB:
  6632. gunType[gun_index] = GUN_TYPE_GBT;
  6633. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  6634. break;
  6635. case Gun_Type_AC:
  6636. gunType[gun_index] = GUN_TYPE_AC;
  6637. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  6638. break;
  6639. default:
  6640. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  6641. break;
  6642. }
  6643. }
  6644. }
  6645. }
  6646. else
  6647. {
  6648. DEBUG_ERROR("Model name parsing fail.\n");
  6649. result = FAIL;
  6650. }
  6651. if(result != PASS)sleep(5);
  6652. return result;
  6653. }
  6654. //---------------------common routine---------------------------//
  6655. void checkNetworkProfile(void)
  6656. {
  6657. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  6658. json_object *priority;
  6659. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  6660. if(!is_error(priority))
  6661. {
  6662. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  6663. {
  6664. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  6665. {
  6666. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  6667. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  6668. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  6669. {
  6670. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  6671. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  6672. break;
  6673. }
  6674. }
  6675. }
  6676. }
  6677. json_object_put(priority);
  6678. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  6679. }
  6680. void checkRemoteStart(uint8_t evseIdx)
  6681. {
  6682. uint8_t tempIndex;
  6683. int isAllowStart = TRUE;
  6684. char cmdBuf[512];
  6685. //check Transaction active
  6686. if(gunType[evseIdx-1] == GUN_TYPE_CHAdeMO)
  6687. {
  6688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6689. {
  6690. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6691. }
  6692. else
  6693. {
  6694. tempIndex = (evseIdx-1);
  6695. }
  6696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6697. {
  6698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6699. {
  6700. 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))
  6701. {
  6702. //Reserved
  6703. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  6704. }
  6705. 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))
  6706. {
  6707. //Reserved
  6708. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  6709. isAllowStart = FALSE;
  6710. }
  6711. else
  6712. {
  6713. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6714. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6715. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6716. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6717. {
  6718. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  6719. isAllowStart = FALSE;
  6720. }
  6721. }//END FOR ELSE
  6722. }
  6723. }// END FOR CHAdeMO_QUANTITY
  6724. }
  6725. else if(gunType[evseIdx-1] == GUN_TYPE_CCS)
  6726. {
  6727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6728. {
  6729. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6730. }
  6731. else
  6732. {
  6733. tempIndex = (evseIdx-1);
  6734. }
  6735. for (int index = 0; index < CCS_QUANTITY; index++)
  6736. {
  6737. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6738. {
  6739. 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))
  6740. {
  6741. //Reserved
  6742. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  6743. }
  6744. 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))
  6745. {
  6746. //Reserved
  6747. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  6748. isAllowStart = FALSE;
  6749. }
  6750. else
  6751. {
  6752. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6753. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6754. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6755. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6756. {
  6757. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  6758. isAllowStart = FALSE;
  6759. }
  6760. }// END FOR ELSE
  6761. }
  6762. }// END FOR CCS_QUANTITY
  6763. }
  6764. else if(gunType[evseIdx-1] == GUN_TYPE_GBT)
  6765. {
  6766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6767. {
  6768. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6769. }
  6770. else
  6771. {
  6772. tempIndex = (evseIdx-1);
  6773. }
  6774. for (int index = 0; index < GB_QUANTITY; index++)
  6775. {
  6776. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6777. {
  6778. 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))
  6779. {
  6780. //Reserved
  6781. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  6782. }
  6783. 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))
  6784. {
  6785. //Reserved
  6786. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  6787. isAllowStart = FALSE;
  6788. }
  6789. else
  6790. {
  6791. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6792. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6793. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6794. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6795. {
  6796. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  6797. isAllowStart = FALSE;
  6798. }
  6799. }// END FOR ELSE
  6800. }
  6801. } // END FOR GB_QUANTITY
  6802. }
  6803. else if(gunType[evseIdx-1] == GUN_TYPE_DO)
  6804. {
  6805. tempIndex = (evseIdx-1);
  6806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6807. {
  6808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  6809. {
  6810. 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))
  6811. {
  6812. //Reserved
  6813. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  6814. }
  6815. 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))
  6816. {
  6817. //Reserved
  6818. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  6819. isAllowStart = FALSE;
  6820. }
  6821. else
  6822. {
  6823. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6824. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6825. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6826. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6827. {
  6828. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  6829. isAllowStart = FALSE;
  6830. }
  6831. }// END FOR ELSE
  6832. }
  6833. } // END FOR GB_QUANTITY
  6834. }
  6835. else
  6836. {
  6837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6838. {
  6839. tempIndex = 2;
  6840. }
  6841. else
  6842. {
  6843. tempIndex = (evseIdx-1);
  6844. }
  6845. for (int index = 0; index < AC_QUANTITY; index++)
  6846. {
  6847. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6848. {
  6849. 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))
  6850. {
  6851. //Reserved
  6852. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  6853. }
  6854. 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))
  6855. {
  6856. //Reserved
  6857. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  6858. isAllowStart = FALSE;
  6859. }
  6860. else
  6861. {
  6862. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6863. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6864. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6865. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6866. {
  6867. DEBUG_WARN("AC connector not allow start cause busy.\n");
  6868. isAllowStart = FALSE;
  6869. }
  6870. }//END FOR ELSE
  6871. }
  6872. }// END FOR AC_QUANTITY
  6873. }
  6874. if(isAllowStart == TRUE)
  6875. {
  6876. if(ShmOCPP20Data->RequestStartTransaction[evseIdx -1].chargingProfile.id > 0)
  6877. {
  6878. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  6879. {
  6880. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdx);
  6881. system(cmdBuf);
  6882. }
  6883. }
  6884. ShmOCPP20Data->CsMsg.bits[evseIdx-1].RequestStartTransactionReq = ON;
  6885. }
  6886. }
  6887. void CheckSystemValue(void)
  6888. {
  6889. char filenmae[100]={0};
  6890. char str[100]={0};
  6891. int tempIndex = 0;
  6892. //===============================
  6893. // EVSE operation check
  6894. //===============================
  6895. //===============================
  6896. // Heartbeat check
  6897. //===============================
  6898. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  6899. {
  6900. //parameter for test
  6901. if(HeartBeatWithNOResponse < 1)
  6902. sendHeartbeatRequest(0);
  6903. //==============================================
  6904. // Reset Waiting Time
  6905. //==============================================
  6906. HeartBeatWithNOResponse += 1;
  6907. }
  6908. //===============================
  6909. // CSU Trigger Authorize Request
  6910. //===============================
  6911. if(isWebsocketSendable &&
  6912. (server_sign == TRUE) &&
  6913. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6914. (authorizeRetryTimes < 3))
  6915. {
  6916. sendAuthorizeRequest(0);
  6917. authorizeRetryTimes = authorizeRetryTimes + 1;
  6918. if(authorizeRetryTimes < 3)
  6919. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6920. }
  6921. else if((server_sign == TRUE) &&
  6922. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6923. (authorizeRetryTimes >= 3))
  6924. {
  6925. authorizeRetryTimes = 0;
  6926. SetOcppConnStatus(FALSE);
  6927. server_sign = FALSE;
  6928. }
  6929. else if((server_sign == FALSE) &&
  6930. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true") == 0) &&
  6931. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  6932. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6933. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6934. {
  6935. sendAuthorizeRequest(0);
  6936. }
  6937. //===============================
  6938. // NotifyMonitoringReportRequest
  6939. //===============================
  6940. if(isWebsocketSendable &&
  6941. (server_sign == TRUE) &&
  6942. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6943. {
  6944. ShmOCPP20Data->NotifyMonitoringReport.requestId = ShmOCPP20Data->GetMonitoringReport.requestId;
  6945. ShmOCPP20Data->NotifyMonitoringReport.tbc = 0;
  6946. ShmOCPP20Data->NotifyMonitoringReport.seqNo = 0;
  6947. getNowDatetime(ShmOCPP20Data->NotifyMonitoringReport.generatedAt);
  6948. sendNotifyMonitoringReportRequest();
  6949. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6950. }
  6951. if(isWebsocketSendable &&
  6952. (server_sign == TRUE) &&
  6953. (ShmOCPP20Data->GetReport.requestId > 0))
  6954. {
  6955. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6956. {
  6957. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6958. {
  6959. /*
  6960. * TODO:
  6961. * 1. Report component that are active
  6962. */
  6963. }
  6964. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6965. {
  6966. /*
  6967. * TODO:
  6968. * 1. Report component that are available
  6969. */
  6970. }
  6971. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6972. {
  6973. /*
  6974. * TODO:
  6975. * 1. Report component that are enable
  6976. */
  6977. }
  6978. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6979. {
  6980. /*
  6981. * TODO:
  6982. * 1. Report component that are problem
  6983. */
  6984. }
  6985. else
  6986. {
  6987. /*
  6988. * TODO:
  6989. * 1. Process unknown criteria condition
  6990. */
  6991. }
  6992. }
  6993. ShmOCPP20Data->GetReport.requestId = 0;
  6994. }
  6995. if(isWebsocketSendable &&
  6996. (server_sign == TRUE) &&
  6997. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6998. {
  6999. uint8_t reportIdx = 0;
  7000. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  7001. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  7002. {
  7003. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  7004. {
  7005. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  7006. {
  7007. 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))
  7008. {
  7009. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  7010. reportIdx++;
  7011. }
  7012. }
  7013. else
  7014. {
  7015. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  7016. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  7017. ShmOCPP20Data->NotifyReport.seqNo += 1;
  7018. else
  7019. ShmOCPP20Data->NotifyReport.seqNo = 0;
  7020. sendNotifyReportRequest();
  7021. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  7022. reportIdx = 0;
  7023. idx_var--;
  7024. }
  7025. }
  7026. }
  7027. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  7028. {
  7029. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  7030. {
  7031. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  7032. {
  7033. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  7034. reportIdx++;
  7035. }
  7036. else
  7037. {
  7038. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  7039. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  7040. ShmOCPP20Data->NotifyReport.seqNo += 1;
  7041. else
  7042. ShmOCPP20Data->NotifyReport.seqNo = 0;
  7043. sendNotifyReportRequest();
  7044. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  7045. reportIdx = 0;
  7046. idx_var--;
  7047. }
  7048. }
  7049. }
  7050. else
  7051. {
  7052. /*
  7053. * TODO:
  7054. * 1. Fill out summary inventory to response message, currently not support
  7055. */
  7056. }
  7057. if(reportIdx > 0)
  7058. {
  7059. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  7060. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  7061. ShmOCPP20Data->NotifyReport.seqNo += 1;
  7062. else
  7063. ShmOCPP20Data->NotifyReport.seqNo = 0;
  7064. sendNotifyReportRequest();
  7065. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  7066. reportIdx = 0;
  7067. }
  7068. ShmOCPP20Data->GetBaseReport.requestId = 0;
  7069. }
  7070. if(isWebsocketSendable &&
  7071. (server_sign == TRUE) &&
  7072. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  7073. {
  7074. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  7075. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  7076. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  7077. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  7078. else
  7079. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  7080. sendNotifyEventRequest();
  7081. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  7082. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  7083. }
  7084. if(isWebsocketSendable &&
  7085. (server_sign == TRUE) &&
  7086. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  7087. {
  7088. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  7089. {
  7090. /*
  7091. * TODO:
  7092. * 1.
  7093. */
  7094. }
  7095. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  7096. {
  7097. /*
  7098. * TODO:
  7099. * 1.
  7100. */
  7101. }
  7102. else
  7103. {
  7104. /*
  7105. * TODO:
  7106. * 1.
  7107. */
  7108. }
  7109. sendGet15118EVCertificateRequest();
  7110. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  7111. }
  7112. if(isWebsocketSendable &&
  7113. (server_sign == TRUE) &&
  7114. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  7115. {
  7116. sendSecurityEventNotificationRequest();
  7117. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  7118. }
  7119. if(isWebsocketSendable &&
  7120. (server_sign == TRUE) &&
  7121. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  7122. {
  7123. sendNotifyCustomerInformationRequest();
  7124. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  7125. }
  7126. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7127. {
  7128. // ClockAlign MeterValue
  7129. 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))
  7130. {
  7131. //check Transaction active
  7132. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7133. {
  7134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7135. {
  7136. tempIndex = ((gun_index==2) ? 1: 0);
  7137. }
  7138. else
  7139. {
  7140. tempIndex = gun_index;
  7141. }
  7142. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7143. {
  7144. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7145. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7146. {
  7147. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7148. }
  7149. }// End for CHAdeMO
  7150. }
  7151. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7152. {
  7153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7154. {
  7155. tempIndex = ((gun_index==2) ? 1: 0);
  7156. }
  7157. else
  7158. {
  7159. tempIndex = gun_index;
  7160. }
  7161. for (int index = 0; index < CCS_QUANTITY; index++)
  7162. {
  7163. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7164. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7165. {
  7166. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7167. }
  7168. } // End for CCS
  7169. }
  7170. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7171. {
  7172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7173. {
  7174. tempIndex = ((gun_index==2) ? 1: 0);
  7175. }
  7176. else
  7177. {
  7178. tempIndex = gun_index;
  7179. }
  7180. for (int index = 0; index < GB_QUANTITY; index++)
  7181. {
  7182. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7183. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7184. {
  7185. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7186. }
  7187. }// End for GB
  7188. }
  7189. else if(gunType[gun_index] == GUN_TYPE_DO)
  7190. {
  7191. tempIndex = gun_index;
  7192. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7193. {
  7194. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7195. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7196. {
  7197. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7198. }
  7199. }
  7200. }
  7201. else
  7202. {
  7203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7204. {
  7205. tempIndex = 2;
  7206. }
  7207. else
  7208. {
  7209. tempIndex = gun_index;
  7210. }
  7211. for (int index = 0; index < AC_QUANTITY; index++)
  7212. {
  7213. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7214. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7215. {
  7216. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7217. }
  7218. }//End for AC
  7219. }
  7220. }
  7221. }
  7222. //===============================
  7223. // Each connector operation check
  7224. //===============================
  7225. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  7226. {
  7227. //==========================================
  7228. // Check remote start without connector id
  7229. //==========================================
  7230. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  7231. {
  7232. int evseIdInt = -1;
  7233. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  7234. {
  7235. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  7236. {
  7237. evseIdInt = (gun_index+1);
  7238. DEBUG_INFO("Detect connector of evse-%02d connected ready to start.\n", evseIdInt);
  7239. checkRemoteStart(evseIdInt);
  7240. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7241. break;
  7242. }
  7243. }
  7244. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  7245. {
  7246. DEBUG_WARN("Remote start request without evse id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  7247. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7248. }
  7249. }
  7250. //==========================================
  7251. // csu trigger DataTransferReq
  7252. //==========================================
  7253. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  7254. {
  7255. sendDataTransferRequest(gun_index);
  7256. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  7257. }
  7258. //==============================================
  7259. // Charger status notification & Transaction event report
  7260. //==============================================
  7261. //--- Check Mode Change ---//
  7262. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7263. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7264. {
  7265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7266. {
  7267. tempIndex = ((gun_index==2) ? 1: 0);
  7268. }
  7269. else
  7270. {
  7271. tempIndex = gun_index;
  7272. }
  7273. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7274. {
  7275. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7276. {
  7277. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  7278. {
  7279. //if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7280. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7281. /*if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7283. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7284. {
  7285. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7286. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7287. else
  7288. {
  7289. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7290. {
  7291. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7292. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7293. }
  7294. }
  7295. }*/
  7296. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  7297. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  7298. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7299. {
  7300. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7301. if((access(filenmae,F_OK))!=-1)
  7302. {
  7303. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7304. sprintf(str,"rm -f %s",filenmae);
  7305. system(str);
  7306. }
  7307. }
  7308. }
  7309. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7310. #if 1 // for TempStopTransaction
  7311. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7312. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7313. {
  7314. checkTempStopTransaction(gun_index);
  7315. }
  7316. #endif
  7317. }
  7318. }
  7319. }
  7320. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7321. {
  7322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7323. {
  7324. tempIndex = ((gun_index==2) ? 1: 0);
  7325. }
  7326. else
  7327. {
  7328. tempIndex = gun_index;
  7329. }
  7330. for (int index = 0; index < CCS_QUANTITY; index++)
  7331. {
  7332. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7333. {
  7334. 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]*/ )
  7335. {
  7336. //if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7337. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7338. /*if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7339. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7340. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7341. {
  7342. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7343. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7344. else
  7345. {
  7346. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7347. {
  7348. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7349. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7350. }
  7351. }
  7352. }*/
  7353. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  7354. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  7355. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7356. {
  7357. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7358. if((access(filenmae,F_OK))!=-1)
  7359. {
  7360. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7361. sprintf(str,"rm -f %s",filenmae);
  7362. system(str);
  7363. }
  7364. }
  7365. }
  7366. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7367. #if 1 // for TempStopTransaction
  7368. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7369. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7370. {
  7371. checkTempStopTransaction(gun_index);
  7372. }
  7373. #endif
  7374. }
  7375. }
  7376. }
  7377. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7378. {
  7379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7380. {
  7381. tempIndex = ((gun_index==2) ? 1: 0);
  7382. }
  7383. else
  7384. {
  7385. tempIndex = gun_index;
  7386. }
  7387. for (int index = 0; index < GB_QUANTITY; index++)
  7388. {
  7389. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7390. {
  7391. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  7392. {
  7393. //if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7394. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7395. /*if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7396. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7397. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]))
  7398. {
  7399. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7400. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7401. else
  7402. {
  7403. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7404. {
  7405. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7406. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7407. }
  7408. }
  7409. }*/
  7410. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  7411. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  7412. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7413. {
  7414. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7415. if((access(filenmae,F_OK))!=-1)
  7416. {
  7417. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7418. sprintf(str,"rm -f %s",filenmae);
  7419. system(str);
  7420. }
  7421. }
  7422. }
  7423. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7424. #if 1 // for TempStopTransaction
  7425. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7426. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7427. {
  7428. checkTempStopTransaction(gun_index);
  7429. }
  7430. #endif
  7431. }
  7432. }
  7433. }
  7434. else if(gunType[gun_index] == GUN_TYPE_DO)
  7435. {
  7436. tempIndex = gun_index;
  7437. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7438. {
  7439. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7440. {
  7441. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  7442. {
  7443. //if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_AUTHORIZING)
  7444. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7445. /*if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  7446. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE) &&
  7447. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]))
  7448. {
  7449. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  7450. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7451. else
  7452. {
  7453. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7454. {
  7455. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7456. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7457. }
  7458. }
  7459. }*/
  7460. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  7461. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  7462. 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
  7463. {
  7464. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7465. if((access(filenmae,F_OK))!=-1)
  7466. {
  7467. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7468. sprintf(str,"rm -f %s",filenmae);
  7469. system(str);
  7470. }
  7471. }
  7472. }
  7473. 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);
  7474. #if 1 // for TempStopTransaction
  7475. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  7476. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7477. {
  7478. checkTempStopTransaction(gun_index);
  7479. }
  7480. #endif
  7481. }
  7482. }
  7483. }
  7484. else
  7485. {
  7486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7487. {
  7488. tempIndex = 2;
  7489. }
  7490. else
  7491. {
  7492. tempIndex = gun_index;
  7493. }
  7494. for (int index = 0; index < AC_QUANTITY; index++)
  7495. {
  7496. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7497. {
  7498. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  7499. {
  7500. //if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7501. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7502. /*if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7503. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7504. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) && (AcPreviousSystemStatus[index] != 99))
  7505. {
  7506. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7507. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7508. else
  7509. {
  7510. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7511. {
  7512. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7513. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7514. }
  7515. }
  7516. }*/
  7517. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  7518. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  7519. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7520. {
  7521. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7522. if((access(filenmae,F_OK))!=-1)
  7523. {
  7524. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7525. sprintf(str,"rm -f %s",filenmae);
  7526. system(str);
  7527. }
  7528. }
  7529. }
  7530. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7531. #if 1 // for TempStopTransaction
  7532. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7533. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7534. {
  7535. checkTempStopTransaction(gun_index);
  7536. }
  7537. #endif
  7538. }
  7539. }// END
  7540. }
  7541. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  7542. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  7543. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") == 0) &&
  7544. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  7545. {
  7546. sendStatusNotificationRequest(gun_index);
  7547. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  7548. }
  7549. //==============================================
  7550. // CSU Trigger or timer timeout refresh Smart Charging Profile
  7551. //==============================================
  7552. if((ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON) ||
  7553. ((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))))
  7554. {
  7555. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  7556. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  7557. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  7558. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  7559. }
  7560. //==============================================
  7561. // CSU transaction event
  7562. //==============================================
  7563. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON || cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  7564. {
  7565. sendTransactionEventRequest(gun_index);
  7566. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  7567. cpinitateMsg.bits[gun_index].TriggerTransactionEventReq = OFF;
  7568. //storeTempStopTransaction(gun_index);
  7569. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  7570. }
  7571. //==============================================
  7572. // Meter report
  7573. //==============================================
  7574. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  7575. {
  7576. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger, FALSE);
  7577. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  7578. }
  7579. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  7580. {
  7581. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock, FALSE);
  7582. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  7583. }
  7584. // Sample period MeterValue
  7585. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0) &&
  7586. (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)))
  7587. {
  7588. //check Transaction active
  7589. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7590. {
  7591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7592. {
  7593. tempIndex = ((gun_index==2) ? 1: 0);
  7594. }
  7595. else
  7596. {
  7597. tempIndex = gun_index;
  7598. }
  7599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7600. {
  7601. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7602. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7603. {
  7604. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7605. {
  7606. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7607. }
  7608. }
  7609. }// End for CHAdeMO
  7610. }
  7611. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7612. {
  7613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7614. {
  7615. tempIndex = ((gun_index==2) ? 1: 0);
  7616. }
  7617. else
  7618. {
  7619. tempIndex = gun_index;
  7620. }
  7621. for (int index = 0; index < CCS_QUANTITY; index++)
  7622. {
  7623. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7624. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7625. {
  7626. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7627. {
  7628. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7629. }
  7630. }
  7631. } // End for CCS
  7632. }
  7633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7634. {
  7635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7636. {
  7637. tempIndex = ((gun_index==2) ? 1: 0);
  7638. }
  7639. else
  7640. {
  7641. tempIndex = gun_index;
  7642. }
  7643. for (int index = 0; index < GB_QUANTITY; index++)
  7644. {
  7645. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7646. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7647. {
  7648. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7649. {
  7650. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7651. }
  7652. }
  7653. }// End for GB
  7654. }
  7655. else if(gunType[gun_index] == GUN_TYPE_DO)
  7656. {
  7657. tempIndex = gun_index;
  7658. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7659. {
  7660. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7661. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7662. {
  7663. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7664. {
  7665. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7666. }
  7667. }
  7668. }
  7669. }
  7670. else
  7671. {
  7672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7673. {
  7674. tempIndex = 2;
  7675. }
  7676. else
  7677. {
  7678. tempIndex = gun_index;
  7679. }
  7680. for (int index = 0; index < AC_QUANTITY; index++)
  7681. {
  7682. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7683. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7684. {
  7685. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7686. {
  7687. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7688. }
  7689. }
  7690. }//End for AC
  7691. }
  7692. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7693. {
  7694. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7695. {
  7696. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, FALSE);
  7697. }
  7698. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7699. }
  7700. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  7701. }
  7702. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value) > 0) &&
  7703. (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)))
  7704. {
  7705. //check Transaction active
  7706. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7707. {
  7708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7709. {
  7710. tempIndex = ((gun_index==2) ? 1: 0);
  7711. }
  7712. else
  7713. {
  7714. tempIndex = gun_index;
  7715. }
  7716. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7717. {
  7718. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7719. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7720. {
  7721. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7722. {
  7723. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7724. }
  7725. }
  7726. }// End for CHAdeMO
  7727. }
  7728. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7729. {
  7730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7731. {
  7732. tempIndex = ((gun_index==2) ? 1: 0);
  7733. }
  7734. else
  7735. {
  7736. tempIndex = gun_index;
  7737. }
  7738. for (int index = 0; index < CCS_QUANTITY; index++)
  7739. {
  7740. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7741. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7742. {
  7743. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7744. {
  7745. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7746. }
  7747. }
  7748. } // End for CCS
  7749. }
  7750. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7751. {
  7752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7753. {
  7754. tempIndex = ((gun_index==2) ? 1: 0);
  7755. }
  7756. else
  7757. {
  7758. tempIndex = gun_index;
  7759. }
  7760. for (int index = 0; index < GB_QUANTITY; index++)
  7761. {
  7762. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7763. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7764. {
  7765. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7766. {
  7767. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7768. }
  7769. }
  7770. }// End for GB
  7771. }
  7772. else if(gunType[gun_index] == GUN_TYPE_DO)
  7773. {
  7774. tempIndex = gun_index;
  7775. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7776. {
  7777. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7778. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7779. {
  7780. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7781. {
  7782. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7783. }
  7784. }
  7785. }
  7786. }
  7787. else
  7788. {
  7789. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7790. {
  7791. tempIndex = 2;
  7792. }
  7793. else
  7794. {
  7795. tempIndex = gun_index;
  7796. }
  7797. for (int index = 0; index < AC_QUANTITY; index++)
  7798. {
  7799. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7800. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7801. {
  7802. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7803. {
  7804. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7805. }
  7806. }
  7807. }//End for AC
  7808. }
  7809. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7810. {
  7811. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7812. {
  7813. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, TRUE);
  7814. }
  7815. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7816. }
  7817. refreshStartTimer(&clientTime.SampledDataTxEnded[gun_index]);
  7818. }
  7819. //==============================================
  7820. // Check Connector reserved
  7821. //==============================================
  7822. //===============================
  7823. // Check if Reserve is expired
  7824. //===============================
  7825. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  7826. {
  7827. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  7828. {
  7829. DEBUG_INFO("reserve expired.\n");
  7830. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  7831. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  7832. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  7833. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  7834. }
  7835. }//END OF Check if Reserve is expired
  7836. //==========================================
  7837. // csu trigger FirmwareStatusNotificationReq
  7838. //==========================================
  7839. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  7840. {
  7841. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  7842. }
  7843. //==========================================
  7844. // csu cleared charging limit request
  7845. //==========================================
  7846. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  7847. {
  7848. sendClearedChargingLimitRequest(gun_index);
  7849. }
  7850. //==========================================
  7851. // csu trigger CancelReservationConf
  7852. //==========================================
  7853. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  7854. {
  7855. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  7856. }
  7857. //==========================================
  7858. // csu notify EV charging need request
  7859. //==========================================
  7860. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  7861. {
  7862. sendNotifyEVChargingNeedsRequest(gun_index);
  7863. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  7864. }
  7865. //==========================================
  7866. // csu notify EV charging schedule request
  7867. //==========================================
  7868. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq == ON))
  7869. {
  7870. sendNotifyEVChargingScheduleRequest(gun_index);
  7871. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  7872. }
  7873. //==========================================
  7874. // csu trigger ChangeAvailabilityConf
  7875. //==========================================
  7876. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  7877. {
  7878. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  7879. }
  7880. //==========================================
  7881. // csu trigger UnlockConnectorConf
  7882. //==========================================
  7883. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  7884. {
  7885. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  7886. }
  7887. //==========================================
  7888. // csu trigger ReserveNowConf
  7889. //==========================================
  7890. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  7891. {
  7892. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  7893. }
  7894. //==========================================
  7895. // csu trigger ReserveNowConf
  7896. //==========================================
  7897. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  7898. {
  7899. sendReservationStatusUpdateRequest(gun_index);
  7900. }
  7901. //==========================================
  7902. // csu trigger LogStatusNotificationReq
  7903. //==========================================
  7904. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  7905. {
  7906. if(isCancelUploadLog == TRUE)
  7907. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7908. else
  7909. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  7910. }
  7911. //==========================================
  7912. // csu trigger SignCertificateReq
  7913. //==========================================
  7914. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  7915. {
  7916. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  7917. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  7918. {
  7919. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  7920. }
  7921. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  7922. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  7923. {
  7924. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  7925. }
  7926. }
  7927. }
  7928. }
  7929. //==========================================
  7930. // send request routine
  7931. //==========================================
  7932. int sendAuthorizeRequest(int gun_index)
  7933. {
  7934. mtrace();
  7935. int result = FAIL;
  7936. char message[4096]={0};
  7937. char guid[37];
  7938. char tempdata[128]={0};
  7939. json_object *Authorize = json_object_new_object();
  7940. json_object *idToken = json_object_new_object();
  7941. DEBUG_INFO("sendAuthorizeRequest...\n");
  7942. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  7943. //Local Authorize
  7944. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "true")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  7945. {
  7946. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  7947. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7948. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  7949. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  7950. result = PASS;
  7951. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7952. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7953. authorizeRetryTimes = 0;
  7954. return result;
  7955. }
  7956. 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)) ||
  7957. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true") == 0)))
  7958. {
  7959. // Query idtag from cache
  7960. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  7961. // Query idtag from list
  7962. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7963. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  7964. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7965. {
  7966. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  7967. {
  7968. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7969. }
  7970. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  7971. {
  7972. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7973. }
  7974. // Return authorize result if does not connect to server
  7975. if(!ShmOCPP20Data->OcppConnStatus)
  7976. {
  7977. DEBUG_INFO("Local Authorization Fail.\n");
  7978. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7979. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7980. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  7981. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7982. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7983. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7984. authorizeRetryTimes = 0;
  7985. return result;
  7986. }
  7987. }
  7988. else
  7989. {
  7990. DEBUG_INFO("Local Authorization get result.\n");
  7991. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  7992. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7993. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  7994. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  7995. else
  7996. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  7997. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7998. result = PASS;
  7999. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  8000. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  8001. authorizeRetryTimes = 0;
  8002. return result;
  8003. }
  8004. }
  8005. //get data from shared memory
  8006. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  8007. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  8008. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  8009. if(strcmp((char*)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenType_eMAID]) == 0)
  8010. {
  8011. memset(&ShmOCPP20Data->Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  8012. int parseCertResult = FAIL;
  8013. json_object *iso15118CertificateHashData = json_object_new_array();
  8014. // Read CERTIFICATE_PnCAuth file content
  8015. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  8016. {
  8017. memset(ShmOCPP20Data->Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.certificate));
  8018. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  8019. char *line = NULL;
  8020. size_t len = 0;
  8021. while(getline(&line, &len, fp) != -1)
  8022. {
  8023. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  8024. strcat((char *)ShmOCPP20Data->Authorize.certificate, line);
  8025. }
  8026. fclose(fp);
  8027. }
  8028. if(strlen((char*)ShmOCPP20Data->Authorize.certificate) > 0)
  8029. json_object_object_add(Authorize, "certificate", json_object_new_string((char*)ShmOCPP20Data->Authorize.certificate));
  8030. char parseData[512] = {0};
  8031. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  8032. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  8033. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  8034. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  8035. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  8036. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  8037. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  8038. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  8039. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  8040. strcpy((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  8041. for(int idx=0; idx < 4; idx++)
  8042. {
  8043. if(strlen((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  8044. {
  8045. json_object *OCSPRequestDataType = json_object_new_object();
  8046. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  8047. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  8048. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  8049. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].serialNumber));
  8050. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL));
  8051. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  8052. parseCertResult = PASS;
  8053. }
  8054. }
  8055. if(parseCertResult == PASS)
  8056. {
  8057. json_object_object_add(Authorize, "iso15118CertificateHashData", iso15118CertificateHashData);
  8058. }
  8059. else
  8060. {
  8061. sprintf((char*)ShmOCPP20Data->Authorize.Response_certificateStatus, "NoCertificateAvailable");
  8062. sprintf((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Invalid");
  8063. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON;
  8064. }
  8065. }
  8066. json_object_object_add(Authorize, "idToken", idToken);
  8067. random_uuid(guid);
  8068. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  8069. json_object_put(Authorize);
  8070. LWS_Send(message);
  8071. sprintf(tempdata, "Authorize,%d", gun_index);
  8072. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8073. {
  8074. result = PASS;
  8075. }
  8076. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  8077. return result;
  8078. }
  8079. int sendBootNotificationRequest()
  8080. {
  8081. mtrace();
  8082. int result = FAIL;
  8083. char message[4096]={0};
  8084. char guid[37]={0};
  8085. char tempdata[128]={0};
  8086. json_object *BootNotification = json_object_new_object();
  8087. json_object *chargingStation = json_object_new_object();
  8088. json_object *modem = json_object_new_object();
  8089. DEBUG_INFO("sendBootNotificationRequest...\n");
  8090. // Fill BootNotification fields
  8091. DB_getBooType();
  8092. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  8093. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8094. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8095. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  8096. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  8097. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  8098. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  8099. {
  8100. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  8101. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  8102. json_object_object_add(chargingStation, "modem", modem);
  8103. }
  8104. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  8105. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  8106. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  8107. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  8108. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  8109. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  8110. random_uuid(guid);
  8111. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  8112. json_object_put(BootNotification);
  8113. LWS_Send(message);
  8114. sprintf(tempdata, "BootNotification,0");
  8115. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8116. {
  8117. result = PASS;
  8118. }
  8119. return result;
  8120. }
  8121. int sendClearedChargingLimitRequest(int gun_index)
  8122. {
  8123. mtrace();
  8124. int result = FAIL;
  8125. char message[4096]={0};
  8126. char guid[37]={0};
  8127. char tempdata[128]={0};
  8128. json_object *ClearedChargingLimit = json_object_new_object();
  8129. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  8130. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  8131. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  8132. random_uuid(guid);
  8133. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  8134. json_object_put(ClearedChargingLimit);
  8135. LWS_Send(message);
  8136. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  8137. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8138. {
  8139. result = PASS;
  8140. }
  8141. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  8142. return result;
  8143. }
  8144. int sendDataTransferRequest(int gun_index)
  8145. {
  8146. mtrace();
  8147. char message[1000]={0};
  8148. char guid[37]={0};
  8149. char tempdata[65]={0};
  8150. int result = FAIL;
  8151. DEBUG_INFO("sendDataTransferRequest...\n");
  8152. random_uuid(guid);
  8153. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  8154. MESSAGE_TYPE_CALL,
  8155. guid,
  8156. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  8157. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  8158. ShmOCPP20Data->DataTransfer[gun_index].data);
  8159. LWS_Send(message);
  8160. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  8161. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8162. {
  8163. result = PASS;
  8164. }
  8165. return result;
  8166. }
  8167. int sendFirmwareStatusNotificationRequest(char *status)
  8168. {
  8169. mtrace();
  8170. int result = FAIL;
  8171. char message[110]={0};
  8172. char guid[37]={0};
  8173. char tempdata[65]={0};
  8174. json_object *FirmwareStatusNotification = json_object_new_object();
  8175. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  8176. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  8177. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  8178. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  8179. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  8180. random_uuid(guid);
  8181. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8182. json_object_put(FirmwareStatusNotification);
  8183. LWS_SendNow(message);
  8184. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  8185. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8186. {
  8187. result = PASS;
  8188. }
  8189. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  8190. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  8191. //record status
  8192. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  8193. {
  8194. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  8195. }
  8196. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  8197. {
  8198. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  8199. }
  8200. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  8201. {
  8202. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  8203. }
  8204. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  8205. {
  8206. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  8207. }
  8208. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  8209. {
  8210. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  8211. }
  8212. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  8213. {
  8214. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  8215. }
  8216. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  8217. {
  8218. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  8219. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8220. }
  8221. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  8222. {
  8223. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  8224. }
  8225. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  8226. {
  8227. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  8228. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8229. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8230. }
  8231. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  8232. {
  8233. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  8234. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8235. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8236. }
  8237. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  8238. {
  8239. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  8240. }
  8241. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  8242. {
  8243. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  8244. }
  8245. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  8246. {
  8247. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  8248. }
  8249. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  8250. {
  8251. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  8252. }
  8253. return result;
  8254. }
  8255. int sendGet15118EVCertificateRequest()
  8256. {
  8257. mtrace();
  8258. int result = FAIL;
  8259. char message[4096]={0};
  8260. char guid[37]={0};
  8261. char tempdata[128]={0};
  8262. json_object *Get15118EVCertificate = json_object_new_object();
  8263. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  8264. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  8265. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  8266. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  8267. random_uuid(guid);
  8268. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  8269. json_object_put(Get15118EVCertificate);
  8270. LWS_Send(message);
  8271. sprintf(tempdata, "Get15118EVCertificate,0");
  8272. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8273. {
  8274. result = PASS;
  8275. }
  8276. return result;
  8277. }
  8278. int sendGetCertificateStatusRequest()
  8279. {
  8280. mtrace();
  8281. int result = FAIL;
  8282. char message[4096]={0};
  8283. char guid[37]={0};
  8284. char tempdata[128]={0};
  8285. json_object *GetCertificateStatus = json_object_new_object();
  8286. json_object *ocspRequestData = json_object_new_object();
  8287. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  8288. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  8289. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  8290. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  8291. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  8292. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  8293. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  8294. random_uuid(guid);
  8295. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  8296. json_object_put(GetCertificateStatus);
  8297. LWS_Send(message);
  8298. sprintf(tempdata, "GetCertificateStatus,0");
  8299. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8300. {
  8301. result = PASS;
  8302. }
  8303. return result;
  8304. }
  8305. int sendHeartbeatRequest()
  8306. {
  8307. mtrace();
  8308. int result = FAIL;
  8309. char message[40096]={0};
  8310. char guid[37]={0};
  8311. char tempdata[128]={0};
  8312. DEBUG_INFO("sendHeartbeatRequest...\n");
  8313. random_uuid(guid);
  8314. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{}]"
  8315. , MESSAGE_TYPE_CALL
  8316. , guid );
  8317. LWS_Send(message);
  8318. sprintf(tempdata, "Heartbeat,%d", 0);
  8319. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8320. {
  8321. result = PASS;
  8322. }
  8323. return result;
  8324. }
  8325. int sendLogStatusNotificationRequest(char *status)
  8326. {
  8327. mtrace();
  8328. int result = FAIL;
  8329. char message[4096]={0};
  8330. char guid[37]={0};
  8331. char tempdata[128]={0};
  8332. json_object *LogStatusNotification = json_object_new_object();
  8333. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8334. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  8335. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  8336. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  8337. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  8338. random_uuid(guid);
  8339. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8340. json_object_put(LogStatusNotification);
  8341. LWS_SendNow(message);
  8342. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8343. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8344. {
  8345. result = PASS;
  8346. }
  8347. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  8348. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  8349. //record status
  8350. if(strcmp(status,"BadMessage")==0)
  8351. {
  8352. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  8353. }
  8354. else if(strcmp(status,"Idle")==0)
  8355. {
  8356. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  8357. }
  8358. else if(strcmp(status,"NotSupportedOperation")==0)
  8359. {
  8360. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  8361. }
  8362. else if(strcmp(status,"PermissionDenied")==0)
  8363. {
  8364. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  8365. }
  8366. else if(strcmp(status,"Uploaded")==0)
  8367. {
  8368. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  8369. }
  8370. else if(strcmp(status,"UploadFailure")==0)
  8371. {
  8372. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  8373. }
  8374. else if(strcmp(status,"Uploading")==0)
  8375. {
  8376. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  8377. }
  8378. return result;
  8379. }
  8380. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType, uint8_t isSampledDataTxEnd)
  8381. {
  8382. mtrace();
  8383. int result = FAIL;
  8384. char guid[37]={0};
  8385. char tempdata[65]={0};
  8386. int tempIndex = 0;
  8387. DEBUG_INFO("sendMeterValuesRequest...\n");
  8388. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  8389. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  8390. //set value
  8391. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  8392. //UTC Date time
  8393. struct timeval tmnow;
  8394. struct tm *tm;
  8395. char buf[28];//, usec_buf[6];
  8396. gettimeofday(&tmnow, NULL);
  8397. time_t t;
  8398. t = time(NULL);
  8399. /*UTC time and date*/
  8400. tm = gmtime(&t);
  8401. if(dataType == ReadingContextEnumType_Sample_Clock)
  8402. {
  8403. struct tm *tmTarget;
  8404. struct timeb tbTarget;
  8405. tbTarget.time = mktime(tm);
  8406. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  8407. tmTarget = gmtime(&tbTarget.time);
  8408. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  8409. }
  8410. else
  8411. {
  8412. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8413. }
  8414. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  8415. struct ChargingInfoData *targetChargingInfoData = getTargetChargingInfoData(gun_index);
  8416. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  8417. //idx_sample=0;
  8418. //********************************(1)Current.Import L1************************************************/
  8419. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8420. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8421. (dataType == ReadingContextEnumType_Trigger))
  8422. {
  8423. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8424. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrent*100))/100.0;
  8425. if(gunType[gun_index] == GUN_TYPE_AC)
  8426. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8427. else
  8428. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8429. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  8430. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8431. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8432. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  8433. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  8434. }
  8435. //idx_sample=1;
  8436. //********************************(2)Energy.Active.Import.Register ************************************************/
  8437. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8438. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8439. (dataType == ReadingContextEnumType_Trigger))
  8440. {
  8441. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8442. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(targetChargingInfoData->PowerConsumption*100))/100.0;
  8443. if(gunType[gun_index] == GUN_TYPE_AC)
  8444. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8445. else
  8446. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8447. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  8448. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  8449. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8450. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  8451. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8452. }
  8453. //idx_sample=2;
  8454. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  8455. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8456. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8457. (dataType == ReadingContextEnumType_Trigger))
  8458. {
  8459. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8460. if(dataType == ReadingContextEnumType_Sample_Clock)
  8461. {
  8462. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousClockPowerConsumption[gun_index]);
  8463. periousClockPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8464. }
  8465. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  8466. {
  8467. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  8468. periousPeriodicPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8469. }
  8470. else
  8471. {
  8472. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  8473. }
  8474. if(gunType[gun_index] == GUN_TYPE_AC)
  8475. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8476. else
  8477. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8478. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  8479. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  8480. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8481. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  8482. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8483. }
  8484. //idx_sample=3;
  8485. //********************************(4)Power.Active.Import************************************************/
  8486. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8487. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8488. (dataType == ReadingContextEnumType_Trigger))
  8489. {
  8490. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8491. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(targetChargingInfoData->PresentChargingPower*100))/100.0;
  8492. if(gunType[gun_index] == GUN_TYPE_AC)
  8493. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8494. else
  8495. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8496. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  8497. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  8498. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8499. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  8500. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  8501. }
  8502. //idx_sample=4;
  8503. //***********************************************(5)VOLTAGE L1******************************************************/
  8504. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8505. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8506. (dataType == ReadingContextEnumType_Trigger))
  8507. {
  8508. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8509. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltage*100))/100.0;
  8510. if(gunType[gun_index] == GUN_TYPE_AC)
  8511. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8512. else
  8513. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8514. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  8515. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8516. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8517. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  8518. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  8519. }
  8520. //***********************************************(6)SOC******************************************************/
  8521. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8522. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8523. (dataType == ReadingContextEnumType_Trigger))
  8524. {
  8525. 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))
  8526. {
  8527. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = targetChargingInfoData->EvBatterySoc;
  8528. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  8529. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  8530. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8531. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  8532. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  8533. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  8534. }
  8535. }
  8536. //********************************(7)Current.Import L2************************************************/
  8537. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8538. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8539. (dataType == ReadingContextEnumType_Trigger))
  8540. {
  8541. // Only for AC 3 phase
  8542. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8543. {
  8544. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL2*100))/100.0;
  8545. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8546. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  8547. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8548. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8549. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  8550. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  8551. }
  8552. }
  8553. //********************************(8)Current.Import L3************************************************/
  8554. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8555. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8556. (dataType == ReadingContextEnumType_Trigger))
  8557. {
  8558. // Only for AC 3 phase
  8559. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8560. {
  8561. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL3*100))/100.0;
  8562. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8563. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  8564. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8565. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8566. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  8567. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  8568. }
  8569. }
  8570. //***********************************************(9)VOLTAGE L2******************************************************/
  8571. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8572. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8573. (dataType == ReadingContextEnumType_Trigger))
  8574. {
  8575. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8576. {
  8577. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL2*100))/100.0;
  8578. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8579. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8580. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8581. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8582. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8583. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8584. }
  8585. }
  8586. //***********************************************(10)VOLTAGE L3******************************************************/
  8587. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8588. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8589. (dataType == ReadingContextEnumType_Trigger))
  8590. {
  8591. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8592. {
  8593. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL3*100))/100.0;
  8594. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8595. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8596. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8597. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8598. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8599. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8600. }
  8601. }
  8602. //***********************************************(11)Current.Offered******************************************************/
  8603. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8604. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8605. (dataType == ReadingContextEnumType_Trigger))
  8606. {
  8607. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8608. if(gunType[gun_index] == GUN_TYPE_AC)
  8609. {
  8610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8611. {
  8612. tempIndex = 2;
  8613. }
  8614. else
  8615. {
  8616. tempIndex = gun_index;
  8617. }
  8618. for (int index = 0; index < AC_QUANTITY; index++)
  8619. {
  8620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8621. {
  8622. uint16_t currentOffer;
  8623. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8624. {
  8625. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8626. }
  8627. else
  8628. {
  8629. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8630. }
  8631. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8632. }
  8633. }
  8634. }
  8635. else
  8636. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t)(targetChargingInfoData->AvailableChargingCurrent/10);
  8637. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8638. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8639. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8640. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8641. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8642. }
  8643. //***********************************************(12)Power.Offered******************************************************/
  8644. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8645. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8646. (dataType == ReadingContextEnumType_Trigger))
  8647. {
  8648. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8649. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t)(targetChargingInfoData->AvailableChargingPower*100);
  8650. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8651. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8652. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8653. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8654. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8655. }
  8656. // Message create ====================================================================================================
  8657. random_uuid(guid);
  8658. json_object *MeterValueReq = json_object_new_object();
  8659. json_object *meterValues = json_object_new_array();
  8660. json_object *sampledValues = json_object_new_array();
  8661. json_object *sampledValuesBuffer = json_object_new_array();
  8662. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8663. {
  8664. json_object *meterValue = json_object_new_object();
  8665. json_object *MeterValueBuffer = json_object_new_object();
  8666. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8667. {
  8668. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8669. {
  8670. json_object *sampledValue = json_object_new_object();
  8671. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8672. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8673. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8674. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8675. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8676. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8677. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8678. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8679. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8680. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8681. {
  8682. json_object *signedMeterValue = json_object_new_object();
  8683. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8684. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8685. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8686. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8687. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8688. }
  8689. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8690. {
  8691. json_object *unitOfMeasure = json_object_new_object();
  8692. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8693. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8694. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8695. }
  8696. json_object_array_add(sampledValues, sampledValue);
  8697. // For StopTxn data
  8698. if((isSampledDataTxEnd == TRUE) &&
  8699. (((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)) ||
  8700. ((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))))
  8701. {
  8702. json_object *sampledValue = json_object_new_object();
  8703. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8704. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8705. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8706. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8707. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8708. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8709. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8710. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8711. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8712. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8713. {
  8714. json_object *signedMeterValue = json_object_new_object();
  8715. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8716. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8717. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8718. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8719. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8720. }
  8721. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8722. {
  8723. json_object *unitOfMeasure = json_object_new_object();
  8724. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8725. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8726. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8727. }
  8728. json_object_array_add(sampledValuesBuffer, sampledValue);
  8729. }
  8730. }
  8731. }
  8732. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8733. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8734. json_object_array_add(meterValues, meterValue);
  8735. // For StopTxn data
  8736. if((isSampledDataTxEnd == TRUE) && (dataType != ReadingContextEnumType_Trigger) &&
  8737. (json_object_array_length(sampledValuesBuffer) > 0))
  8738. {
  8739. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8740. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  8741. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  8742. meterValueBufferInsert(gun_index, dataType, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  8743. else
  8744. 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));
  8745. json_object_put(MeterValueBuffer);
  8746. }
  8747. else
  8748. {
  8749. json_object_put(sampledValuesBuffer);
  8750. json_object_put(MeterValueBuffer);
  8751. }
  8752. idxMeter++;
  8753. }
  8754. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8755. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8756. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8757. ,MESSAGE_TYPE_CALL
  8758. ,guid
  8759. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8760. json_object_put(MeterValueReq);
  8761. if((dataType != ReadingContextEnumType_Trigger) &&
  8762. (dataType != ReadingContextEnumType_Sample_Clock))
  8763. {
  8764. // Transaction meter value send by TransactionEvent message
  8765. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8766. if(isSampledDataTxEnd != TRUE)
  8767. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8768. result = PASS;
  8769. }
  8770. else
  8771. {
  8772. // Put request guid to hash map
  8773. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8774. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8775. {
  8776. result = PASS;
  8777. }
  8778. if((dataType != ReadingContextEnumType_Trigger) &&
  8779. (dataType != ReadingContextEnumType_Sample_Clock))
  8780. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8781. else
  8782. {
  8783. if(FirstHeartBeat)
  8784. LWS_Send(queuedata);
  8785. }
  8786. }
  8787. return result;
  8788. }
  8789. int sendNotifyChargingLimitRequest(int gun_index)
  8790. {
  8791. mtrace();
  8792. int result = FAIL;
  8793. char message[4096]={0};
  8794. char guid[37]={0};
  8795. char tempdata[128]={0};
  8796. json_object *NotifyChargingLimit = json_object_new_object();
  8797. json_object *chargingLimit = json_object_new_object();
  8798. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8799. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8800. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8801. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8802. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8803. random_uuid(guid);
  8804. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8805. json_object_put(NotifyChargingLimit);
  8806. LWS_Send(message);
  8807. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8808. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8809. {
  8810. result = PASS;
  8811. }
  8812. return result;
  8813. }
  8814. int sendNotifyCustomerInformationRequest()
  8815. {
  8816. mtrace();
  8817. int result = FAIL;
  8818. char message[4096]={0};
  8819. char guid[37]={0};
  8820. char tempdata[128]={0};
  8821. json_object *NotifyCustomerInformation = json_object_new_object();
  8822. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8823. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8824. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8825. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8826. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8827. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8828. random_uuid(guid);
  8829. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8830. json_object_put(NotifyCustomerInformation);
  8831. LWS_Send(message);
  8832. sprintf(tempdata, "NotifyCustomerInformation,0");
  8833. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8834. {
  8835. result = PASS;
  8836. }
  8837. return result;
  8838. }
  8839. int sendNotifyDisplayMessagesRequest()
  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 *NotifyDisplayMessages = json_object_new_object();
  8847. json_object *messageInfos = json_object_new_array();
  8848. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8849. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8850. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8851. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8852. {
  8853. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8854. {
  8855. json_object *messageInfo = json_object_new_object();
  8856. json_object *message = json_object_new_object();
  8857. json_object *display = json_object_new_object();
  8858. json_object *evse = json_object_new_object();
  8859. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8860. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8861. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8862. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8863. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8864. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8865. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8866. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8867. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8868. json_object_object_add(messageInfo, "message", message);
  8869. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8870. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8871. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8872. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8873. json_object_object_add(display, "evse",evse);
  8874. json_object_object_add(messageInfo, "evse", display);
  8875. json_object_array_add(messageInfos, messageInfo);
  8876. }
  8877. }
  8878. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8879. random_uuid(guid);
  8880. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8881. json_object_put(NotifyDisplayMessages);
  8882. LWS_Send(message);
  8883. sprintf(tempdata, "NotifyDisplayMessages,0");
  8884. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8885. {
  8886. result = PASS;
  8887. }
  8888. return result;
  8889. }
  8890. int sendNotifyEVChargingNeedsRequest(int gun_index)
  8891. {
  8892. mtrace();
  8893. int result = FAIL;
  8894. char message[4096]={0};
  8895. char guid[37]={0};
  8896. char tempdata[128]={0};
  8897. json_object *NotifyEVChargingNeeds = json_object_new_object();
  8898. json_object *chargingNeeds = json_object_new_object();
  8899. json_object *acChargingParameters = json_object_new_object();
  8900. json_object *dcChargingParameters = json_object_new_object();
  8901. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8902. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8903. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8904. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8905. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8906. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8907. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8908. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8909. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8910. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8911. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8912. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8913. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8914. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8915. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8916. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8917. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8918. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8919. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8920. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8921. random_uuid(guid);
  8922. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8923. json_object_put(NotifyEVChargingNeeds);
  8924. LWS_Send(message);
  8925. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8926. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8927. {
  8928. result = PASS;
  8929. }
  8930. return result;
  8931. }
  8932. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8933. {
  8934. mtrace();
  8935. int result = FAIL;
  8936. char message[4096]={0};
  8937. char guid[37]={0};
  8938. char tempdata[128]={0};
  8939. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8940. json_object *chargingSchedule = json_object_new_object();
  8941. json_object *periods = json_object_new_array();
  8942. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8943. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8944. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8945. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8946. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8947. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8948. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8949. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8950. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8951. {
  8952. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8953. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8954. {
  8955. json_object *Period = json_object_new_object();
  8956. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8957. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8958. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8959. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8960. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8961. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8962. json_object_array_add(periods, Period);
  8963. }
  8964. }
  8965. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8966. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8967. random_uuid(guid);
  8968. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8969. json_object_put(NotifyEVChargingSchedule);
  8970. LWS_Send(message);
  8971. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8972. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8973. {
  8974. result = PASS;
  8975. }
  8976. return result;
  8977. }
  8978. int sendNotifyEventRequest()
  8979. {
  8980. mtrace();
  8981. int result = FAIL;
  8982. char message[4096]={0};
  8983. char guid[37]={0};
  8984. char tempdata[128]={0};
  8985. json_object *NotifyEvent = json_object_new_object();
  8986. json_object *eventDatas = json_object_new_array();
  8987. DEBUG_INFO("sendNotifyEventRequest...\n");
  8988. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8989. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8990. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8991. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8992. {
  8993. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8994. {
  8995. json_object *eventData = json_object_new_object();
  8996. json_object *component = json_object_new_object();
  8997. json_object *evse = json_object_new_object();
  8998. json_object *variable = json_object_new_object();
  8999. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  9000. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  9001. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  9002. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  9003. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  9004. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  9005. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  9006. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  9007. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  9008. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  9009. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  9010. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  9011. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  9012. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  9013. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  9014. json_object_object_add(component, "evse",evse);
  9015. json_object_object_add(eventData, "component", component);
  9016. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  9017. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  9018. json_object_object_add(eventData, "variable", variable);
  9019. json_object_array_add(eventDatas, eventData);
  9020. }
  9021. }
  9022. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  9023. random_uuid(guid);
  9024. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  9025. json_object_put(NotifyEvent);
  9026. LWS_Send(message);
  9027. sprintf(tempdata, "NotifyEvent,0");
  9028. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9029. {
  9030. result = PASS;
  9031. }
  9032. return result;
  9033. }
  9034. int sendNotifyMonitoringReportRequest()
  9035. {
  9036. mtrace();
  9037. int result = FAIL;
  9038. char message[4096]={0};
  9039. char guid[37]={0};
  9040. char tempdata[128]={0};
  9041. json_object *NotifyMonitoringReport = json_object_new_object();
  9042. json_object *monitors = json_object_new_array();
  9043. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  9044. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  9045. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  9046. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  9047. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  9048. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  9049. {
  9050. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  9051. {
  9052. json_object *monitor = json_object_new_object();
  9053. json_object *component = json_object_new_object();
  9054. json_object *evse = json_object_new_object();
  9055. json_object *variable = json_object_new_object();
  9056. json_object *variableMonitorings = json_object_new_array();
  9057. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  9058. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  9059. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  9060. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  9061. json_object_object_add(component, "evse",evse);
  9062. json_object_object_add(monitor, "component", component);
  9063. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  9064. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  9065. json_object_object_add(monitor, "variable", variable);
  9066. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  9067. {
  9068. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  9069. {
  9070. json_object *variableMonitoring = json_object_new_object();
  9071. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  9072. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  9073. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  9074. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  9075. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  9076. json_object_array_add(variableMonitorings, variableMonitoring);
  9077. }
  9078. }
  9079. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  9080. json_object_array_add(monitors, monitor);
  9081. }
  9082. }
  9083. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  9084. random_uuid(guid);
  9085. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  9086. json_object_put(NotifyMonitoringReport);
  9087. LWS_Send(message);
  9088. sprintf(tempdata, "NotifyMonitoringReport,0");
  9089. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9090. {
  9091. result = PASS;
  9092. }
  9093. return result;
  9094. }
  9095. int sendNotifyReportRequest()
  9096. {
  9097. mtrace();
  9098. int result = FAIL;
  9099. char message[4096]={0};
  9100. char guid[37]={0};
  9101. char tempdata[128]={0};
  9102. json_object *NotifyReport = json_object_new_object();
  9103. json_object *reportDatas = json_object_new_array();
  9104. DEBUG_INFO("sendNotifyReportRequest...\n");
  9105. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  9106. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  9107. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  9108. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  9109. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  9110. {
  9111. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  9112. {
  9113. json_object *reportData = json_object_new_object();
  9114. json_object *component = json_object_new_object();
  9115. json_object *evse = json_object_new_object();
  9116. json_object *variable = json_object_new_object();
  9117. json_object *variableAttributes = json_object_new_array();
  9118. json_object *variableCharacteristics = json_object_new_object();
  9119. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  9120. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  9121. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  9122. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  9123. json_object_object_add(component, "evse",evse);
  9124. json_object_object_add(reportData, "component", component);
  9125. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  9126. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  9127. json_object_object_add(reportData, "variable",variable);
  9128. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  9129. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  9130. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  9131. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  9132. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  9133. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  9134. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  9135. {
  9136. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  9137. {
  9138. json_object *variableAttribute = json_object_new_object();
  9139. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  9140. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  9141. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  9142. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  9143. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  9144. json_object_array_add(variableAttributes, variableAttribute);
  9145. }
  9146. }
  9147. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  9148. json_object_array_add(reportDatas, reportData);
  9149. }
  9150. }
  9151. json_object_object_add(NotifyReport, "reportData", reportDatas);
  9152. random_uuid(guid);
  9153. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  9154. json_object_put(NotifyReport);
  9155. LWS_SendNow(message);
  9156. sprintf(tempdata, "NotifyReport,0");
  9157. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9158. {
  9159. result = PASS;
  9160. }
  9161. return result;
  9162. }
  9163. int sendPublishFirmwareStatusNotificationRequest()
  9164. {
  9165. mtrace();
  9166. int result = FAIL;
  9167. char message[4096]={0};
  9168. char guid[37]={0};
  9169. char tempdata[128]={0};
  9170. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  9171. json_object *locations = json_object_new_array();
  9172. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  9173. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  9174. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  9175. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  9176. {
  9177. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  9178. }
  9179. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  9180. random_uuid(guid);
  9181. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  9182. json_object_put(PublishFirmwareStatusNotification);
  9183. LWS_Send(message);
  9184. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  9185. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9186. {
  9187. result = PASS;
  9188. }
  9189. return result;
  9190. }
  9191. int sendReportChargingProfilesRequest(int gun_index)
  9192. {
  9193. mtrace();
  9194. int result = FAIL;
  9195. char message[4096]={0};
  9196. char guid[37]={0};
  9197. char tempdata[128]={0};
  9198. json_object *ReportChargingProfiles = json_object_new_object();
  9199. json_object *chargingProfiles = json_object_new_array();
  9200. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  9201. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  9202. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  9203. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  9204. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  9205. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  9206. {
  9207. json_object *chargingProfile = json_object_new_object();
  9208. json_object *chargingSchedules = json_object_new_array();
  9209. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  9210. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  9211. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  9212. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  9213. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  9214. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  9215. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  9216. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  9217. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  9218. {
  9219. json_object *chargingSchedule = json_object_new_object();
  9220. json_object *chargingSchedulePeriods = json_object_new_array();
  9221. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  9222. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  9223. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  9224. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  9225. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  9226. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  9227. {
  9228. json_object *chargingSchedulePeriod = json_object_new_object();
  9229. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  9230. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  9231. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  9232. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  9233. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  9234. }
  9235. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  9236. json_object_array_add(chargingSchedules, chargingSchedule);
  9237. }
  9238. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  9239. json_object_array_add(chargingProfiles, chargingProfile);
  9240. }
  9241. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  9242. random_uuid(guid);
  9243. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  9244. json_object_put(ReportChargingProfiles);
  9245. LWS_Send(message);
  9246. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  9247. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9248. {
  9249. result = PASS;
  9250. }
  9251. return result;
  9252. }
  9253. int sendReservationStatusUpdateRequest(int gun_index)
  9254. {
  9255. mtrace();
  9256. int result = FAIL;
  9257. char message[4096]={0};
  9258. char guid[37]={0};
  9259. char tempdata[128]={0};
  9260. json_object *ReservationStatusUpdate = json_object_new_object();
  9261. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  9262. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  9263. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  9264. random_uuid(guid);
  9265. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  9266. json_object_put(ReservationStatusUpdate);
  9267. LWS_Send(message);
  9268. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  9269. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9270. {
  9271. result = PASS;
  9272. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  9273. }
  9274. return result;
  9275. }
  9276. int sendSecurityEventNotificationRequest()
  9277. {
  9278. mtrace();
  9279. int result = FAIL;
  9280. char message[4096]={0};
  9281. char guid[37]={0};
  9282. char tempdata[128]={0};
  9283. struct timeval tmnow;
  9284. struct tm *tm;
  9285. char buf[28];//, usec_buf[6];
  9286. json_object *SecurityEventNotification = json_object_new_object();
  9287. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  9288. DB_getSecurityEventType();
  9289. gettimeofday(&tmnow, NULL);
  9290. time_t t;
  9291. t = time(NULL);
  9292. /*UTC time and date*/
  9293. tm = gmtime(&t);
  9294. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9295. #if 0 // remove temporally
  9296. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9297. strcat(buf,".");
  9298. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9299. strcat(buf,usec_buf);
  9300. #endif
  9301. printf("%s",buf);
  9302. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  9303. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  9304. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  9305. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  9306. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  9307. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  9308. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  9309. random_uuid(guid);
  9310. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  9311. json_object_put(SecurityEventNotification);
  9312. LWS_Send(message);
  9313. sprintf(tempdata, "SecurityEventNotification,0");
  9314. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9315. {
  9316. result = PASS;
  9317. }
  9318. return result;
  9319. }
  9320. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  9321. {
  9322. mtrace();
  9323. int result = FAIL;
  9324. char message[4096]={0};
  9325. char guid[37]={0};
  9326. char tempdata[128]={0};
  9327. json_object *SignCertificate = json_object_new_object();
  9328. DEBUG_INFO("sendSignCertificateRequest...\n");
  9329. // Read csr file content
  9330. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  9331. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?CSR_V2G:CSR_CP),"r");
  9332. char *line = NULL;
  9333. size_t len = 0;
  9334. while(getline(&line, &len, fp) != -1)
  9335. {
  9336. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  9337. {
  9338. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  9339. }
  9340. }
  9341. fclose(fp);
  9342. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  9343. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  9344. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  9345. random_uuid(guid);
  9346. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  9347. json_object_put(SignCertificate);
  9348. LWS_Send(message);
  9349. sprintf(tempdata, "SignCertificate,0");
  9350. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9351. {
  9352. result = PASS;
  9353. }
  9354. return result;
  9355. }
  9356. int sendStatusNotificationRequest(int gun_index)
  9357. {
  9358. mtrace();
  9359. int result = FAIL;
  9360. char message[600]={0};
  9361. char guid[37];
  9362. int currentStatus = 0;
  9363. struct timeval tmnow;
  9364. struct tm *tm;
  9365. char buf[28];//, usec_buf[6];
  9366. char tempdata[65]={0};
  9367. int tempIndex = 0;
  9368. uint8_t isStateChanged = TRUE;
  9369. DEBUG_INFO("sendStatusNotificationRequest...\n");
  9370. gettimeofday(&tmnow, NULL);
  9371. time_t t;
  9372. t = time(NULL);
  9373. /*UTC time and date*/
  9374. tm = gmtime(&t);
  9375. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9376. #if 0 // remove temporally
  9377. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9378. strcat(buf,".");
  9379. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9380. strcat(buf,usec_buf);
  9381. #endif
  9382. printf("%s",buf);
  9383. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  9384. ShmOCPP20Data->StatusNotification[gun_index].connectorId = 1;
  9385. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  9386. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  9387. /*
  9388. enum _SYSTEM_STATUS
  9389. {
  9390. S_BOOTING = 0,
  9391. S_IDLE, = 1
  9392. S_AUTHORIZING, =2
  9393. S_REASSIGN_CHECK, =3
  9394. S_REASSIGN, =4
  9395. S_PRECHARGE, =5
  9396. S_PREPARING_FOR_EV, =6
  9397. S_PREPARING_FOR_EVSE, =7
  9398. S_CHARGING, =8
  9399. S_TERMINATING, =9
  9400. S_COMPLETE, =10
  9401. S_ALARM, =11
  9402. S_FAULT =12
  9403. }
  9404. */
  9405. //check Transaction active
  9406. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  9407. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9408. {
  9409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9410. {
  9411. tempIndex = ((gun_index==2) ? 1: 0);
  9412. }
  9413. else
  9414. {
  9415. tempIndex = gun_index;
  9416. }
  9417. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9418. {
  9419. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9420. {
  9421. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9422. {
  9423. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9424. {
  9425. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9426. }
  9427. else
  9428. {
  9429. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9430. }
  9431. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9432. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9433. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9434. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9435. }
  9436. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9437. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9438. ) //S_PRECHARGE
  9439. {
  9440. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9441. }
  9442. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9443. {
  9444. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9445. }
  9446. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9447. {
  9448. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9449. }
  9450. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9451. {
  9452. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9453. }
  9454. 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
  9455. {
  9456. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9457. }
  9458. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9459. {
  9460. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9461. }
  9462. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9463. {
  9464. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9465. }
  9466. } //end of the same index
  9467. }//end of for CHAdeMO_QUANTITY
  9468. }
  9469. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9470. {
  9471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9472. {
  9473. tempIndex = ((gun_index==2) ? 1: 0);
  9474. }
  9475. else
  9476. {
  9477. tempIndex = gun_index;
  9478. }
  9479. for (int index = 0; index < CCS_QUANTITY; index++)
  9480. {
  9481. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9482. {
  9483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9484. {
  9485. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9486. {
  9487. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9488. }
  9489. else
  9490. {
  9491. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9492. }
  9493. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9494. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9495. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9496. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9497. }
  9498. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9499. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9500. ) //S_PRECHARGE
  9501. {
  9502. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9503. }
  9504. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9505. {
  9506. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9507. }
  9508. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9509. {
  9510. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9511. }
  9512. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9513. {
  9514. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9515. }
  9516. 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
  9517. {
  9518. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9519. }
  9520. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9521. {
  9522. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9523. }
  9524. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9525. {
  9526. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9527. }
  9528. } //end of the same index
  9529. } // end of for CCS_QUANTITY
  9530. }
  9531. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9532. {
  9533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9534. {
  9535. tempIndex = ((gun_index==2) ? 1: 0);
  9536. }
  9537. else
  9538. {
  9539. tempIndex = gun_index;
  9540. }
  9541. for (int index = 0; index < GB_QUANTITY; index++)
  9542. {
  9543. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9544. {
  9545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9546. {
  9547. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9548. {
  9549. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9550. }
  9551. else
  9552. {
  9553. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9554. }
  9555. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9556. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9557. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9558. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9559. }
  9560. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9561. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9562. ) //S_PRECHARGE
  9563. {
  9564. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9565. }
  9566. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9567. {
  9568. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9569. }
  9570. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9571. {
  9572. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9573. }
  9574. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9575. {
  9576. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9577. }
  9578. 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
  9579. {
  9580. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9581. }
  9582. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9583. {
  9584. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9585. }
  9586. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9587. {
  9588. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9589. }
  9590. } //end of the same index
  9591. } // end of for GB_QUANTITY
  9592. }
  9593. else if(gunType[gun_index] == GUN_TYPE_DO)
  9594. {
  9595. tempIndex = gun_index;
  9596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9597. {
  9598. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9599. {
  9600. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9601. {
  9602. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9603. {
  9604. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9605. }
  9606. else
  9607. {
  9608. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9609. }
  9610. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9611. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9612. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9613. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9614. }
  9615. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9616. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9617. ) //S_PRECHARGE
  9618. {
  9619. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9620. }
  9621. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9622. {
  9623. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9624. }
  9625. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9626. {
  9627. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9628. }
  9629. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9630. {
  9631. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9632. }
  9633. 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
  9634. {
  9635. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9636. }
  9637. 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
  9638. {
  9639. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9640. }
  9641. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9642. {
  9643. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9644. }
  9645. } //end of the same index
  9646. }
  9647. }
  9648. else
  9649. {
  9650. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9651. {
  9652. tempIndex = 2;
  9653. }
  9654. else
  9655. {
  9656. tempIndex = gun_index;
  9657. }
  9658. for (int index = 0; index < AC_QUANTITY; index++)
  9659. {
  9660. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9661. {
  9662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9663. {
  9664. 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))
  9665. {
  9666. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9667. }
  9668. else
  9669. {
  9670. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9671. }
  9672. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9673. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9674. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9675. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9676. }
  9677. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9678. {
  9679. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9680. }
  9681. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9682. {
  9683. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9684. }
  9685. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9686. {
  9687. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9688. }
  9689. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9690. {
  9691. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9692. }
  9693. 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
  9694. {
  9695. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9696. }
  9697. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9698. {
  9699. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9700. }
  9701. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9702. {
  9703. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9704. }
  9705. }//end of the same index
  9706. }//end of for AC_QUANTITY
  9707. }
  9708. //it's option
  9709. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9710. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9711. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") != 0))
  9712. {
  9713. isStateChanged = FALSE;
  9714. }
  9715. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9716. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9717. random_uuid(guid);
  9718. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9719. , MESSAGE_TYPE_CALL
  9720. , guid
  9721. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9722. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9723. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9724. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9725. if((server_sign == TRUE) && isStateChanged)
  9726. {
  9727. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9728. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9729. LWS_Send(message);
  9730. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9731. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9732. {
  9733. result = PASS;
  9734. }
  9735. }
  9736. else
  9737. {
  9738. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9739. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9740. result = PASS;
  9741. }
  9742. return result;
  9743. }
  9744. int sendTransactionEventRequest(int gun_index)
  9745. {
  9746. mtrace();
  9747. int result = FAIL;
  9748. char message[QUEUE_MESSAGE_LENGTH]={0};
  9749. char guid[37]={0};
  9750. char tempdata[128]={0};
  9751. uint8_t tempIndex;
  9752. json_object *TransactionEvent = json_object_new_object();
  9753. json_object *transactionInfo = json_object_new_object();
  9754. json_object *idToken = json_object_new_object();
  9755. json_object *evse = json_object_new_object();
  9756. json_object *meterValues = json_object_new_array();
  9757. char TempStopTransaction[256];
  9758. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9759. DEBUG_INFO("sendTransactionEventRequest...\n");
  9760. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9761. {
  9762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9763. {
  9764. tempIndex = ((gun_index==2) ? 1: 0);
  9765. }
  9766. else
  9767. {
  9768. tempIndex = gun_index;
  9769. }
  9770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9771. {
  9772. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9773. {
  9774. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9775. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9776. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9777. else
  9778. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9779. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9780. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9781. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9782. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9783. {
  9784. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9785. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9786. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9787. {
  9788. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9789. }
  9790. else
  9791. {
  9792. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9793. }
  9794. }
  9795. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9796. {
  9797. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9798. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9799. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9800. }
  9801. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9802. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9803. ) //S_PRECHARGE
  9804. {
  9805. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9806. {
  9807. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9808. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9809. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9810. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9811. }
  9812. else
  9813. {
  9814. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9815. }
  9816. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9817. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9818. }
  9819. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9820. {
  9821. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9822. {
  9823. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9824. {
  9825. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9826. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9827. }
  9828. else
  9829. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9830. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9831. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9832. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9833. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9834. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9835. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  9836. }
  9837. else
  9838. {
  9839. storeTempStopTransaction(gun_index);
  9840. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9841. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9842. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9843. }
  9844. }
  9845. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9846. {
  9847. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9848. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9849. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9850. if((access(TempStopTransaction,F_OK))!=-1)
  9851. {
  9852. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9853. }
  9854. }
  9855. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9856. {
  9857. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9858. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9859. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9860. }
  9861. 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
  9862. {
  9863. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9864. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9865. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9866. }
  9867. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9868. {
  9869. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9870. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9871. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9872. }
  9873. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9874. {
  9875. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9876. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9877. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9878. }
  9879. } //end of the same index
  9880. }//end of for CHAdeMO_QUANTITY
  9881. }
  9882. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9883. {
  9884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9885. {
  9886. tempIndex = ((gun_index==2) ? 1: 0);
  9887. }
  9888. else
  9889. {
  9890. tempIndex = gun_index;
  9891. }
  9892. for (int index = 0; index < CCS_QUANTITY; index++)
  9893. {
  9894. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9895. {
  9896. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9897. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9898. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9899. else
  9900. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9901. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9902. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9903. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9904. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9905. {
  9906. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9907. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9908. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9909. {
  9910. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9911. }
  9912. else
  9913. {
  9914. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9915. }
  9916. }
  9917. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9918. {
  9919. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9920. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9921. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9922. }
  9923. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9924. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9925. ) //S_PRECHARGE
  9926. {
  9927. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9928. {
  9929. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9930. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9931. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9932. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9933. }
  9934. else
  9935. {
  9936. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9937. }
  9938. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9939. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9940. }
  9941. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9942. {
  9943. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9944. {
  9945. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9946. {
  9947. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9948. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9949. }
  9950. else
  9951. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9952. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9953. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9954. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9955. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9956. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9957. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  9958. }
  9959. else
  9960. {
  9961. storeTempStopTransaction(gun_index);
  9962. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9963. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9964. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9965. }
  9966. }
  9967. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9968. {
  9969. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9970. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9971. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9972. if((access(TempStopTransaction,F_OK))!=-1)
  9973. {
  9974. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9975. }
  9976. }
  9977. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9978. {
  9979. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9980. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9981. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9982. }
  9983. 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
  9984. {
  9985. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9986. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9987. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9988. }
  9989. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9990. {
  9991. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9992. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9993. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9994. }
  9995. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9996. {
  9997. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9998. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9999. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10000. }
  10001. } //end of the same index
  10002. } // end of for CCS_QUANTITY
  10003. }
  10004. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10005. {
  10006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10007. {
  10008. tempIndex = ((gun_index==2) ? 1: 0);
  10009. }
  10010. else
  10011. {
  10012. tempIndex = gun_index;
  10013. }
  10014. for (int index = 0; index < GB_QUANTITY; index++)
  10015. {
  10016. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10017. {
  10018. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10019. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10020. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10021. else
  10022. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10023. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10024. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10025. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10026. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10027. {
  10028. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10029. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10030. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  10031. {
  10032. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10033. }
  10034. else
  10035. {
  10036. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10037. }
  10038. }
  10039. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10040. {
  10041. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10042. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10043. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10044. }
  10045. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10046. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10047. ) //S_PRECHARGE
  10048. {
  10049. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10050. {
  10051. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10052. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  10053. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  10054. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10055. }
  10056. else
  10057. {
  10058. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10059. }
  10060. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10061. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10062. }
  10063. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10064. {
  10065. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10066. {
  10067. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  10068. {
  10069. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10070. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10071. }
  10072. else
  10073. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10074. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10075. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  10076. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  10077. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10078. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10079. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  10080. }
  10081. else
  10082. {
  10083. storeTempStopTransaction(gun_index);
  10084. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10085. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10086. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10087. }
  10088. }
  10089. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10090. {
  10091. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10092. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10093. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10094. if((access(TempStopTransaction,F_OK))!=-1)
  10095. {
  10096. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10097. }
  10098. }
  10099. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10100. {
  10101. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10102. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10103. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10104. }
  10105. 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
  10106. {
  10107. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10108. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10109. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10110. }
  10111. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10112. {
  10113. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10114. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10115. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10116. }
  10117. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10118. {
  10119. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10120. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10121. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10122. }
  10123. } //end of the same index
  10124. } // end of for GB_QUANTITY
  10125. }
  10126. else if(gunType[gun_index] == GUN_TYPE_DO)
  10127. {
  10128. tempIndex = gun_index;
  10129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10130. {
  10131. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10132. {
  10133. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10134. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10135. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10136. else
  10137. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10138. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10139. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10140. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10141. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10142. {
  10143. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10144. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10145. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  10146. {
  10147. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10148. }
  10149. else
  10150. {
  10151. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10152. }
  10153. }
  10154. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10155. {
  10156. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10157. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10158. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10159. }
  10160. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10161. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10162. ) //S_PRECHARGE
  10163. {
  10164. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10165. {
  10166. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10167. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10168. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10169. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10170. }
  10171. else
  10172. {
  10173. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10174. }
  10175. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10176. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10177. }
  10178. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10179. {
  10180. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10181. {
  10182. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  10183. {
  10184. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10185. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10186. }
  10187. else
  10188. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10189. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10190. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10191. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10192. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10193. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10194. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  10195. }
  10196. else
  10197. {
  10198. storeTempStopTransaction(gun_index);
  10199. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10200. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10201. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10202. }
  10203. }
  10204. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10205. {
  10206. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10207. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10208. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10209. if((access(TempStopTransaction,F_OK))!=-1)
  10210. {
  10211. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10212. }
  10213. }
  10214. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10215. {
  10216. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10217. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10218. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10219. }
  10220. 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
  10221. {
  10222. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10223. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10224. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10225. }
  10226. 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
  10227. {
  10228. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10229. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10230. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10231. }
  10232. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10233. {
  10234. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10235. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10236. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10237. }
  10238. } //end of the same index
  10239. }
  10240. }
  10241. else
  10242. {
  10243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10244. {
  10245. tempIndex = 2;
  10246. }
  10247. else
  10248. {
  10249. tempIndex = gun_index;
  10250. }
  10251. for (int index = 0; index < AC_QUANTITY; index++)
  10252. {
  10253. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10254. {
  10255. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10256. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10257. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10258. else
  10259. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10260. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10261. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10262. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10263. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  10264. {
  10265. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10266. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10267. 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))
  10268. {
  10269. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10270. }
  10271. else
  10272. {
  10273. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10274. }
  10275. }
  10276. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10277. {
  10278. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10279. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10280. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10281. }
  10282. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10283. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10284. ) //S_PRECHARGE
  10285. {
  10286. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10287. {
  10288. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10289. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10290. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10291. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10292. }
  10293. else
  10294. {
  10295. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10296. }
  10297. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10298. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10299. }
  10300. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10301. {
  10302. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10303. {
  10304. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10305. {
  10306. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10307. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10308. }
  10309. else
  10310. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10311. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10312. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10313. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10314. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10315. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10316. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  10317. }
  10318. else
  10319. {
  10320. storeTempStopTransaction(gun_index);
  10321. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10322. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10323. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10324. }
  10325. }
  10326. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10327. {
  10328. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10329. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10330. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10331. if((access(TempStopTransaction,F_OK))!=-1)
  10332. {
  10333. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10334. }
  10335. }
  10336. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10337. {
  10338. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10339. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10340. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10341. }
  10342. 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
  10343. {
  10344. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10345. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10346. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10347. }
  10348. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10349. {
  10350. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10351. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10352. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10353. }
  10354. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10355. {
  10356. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10357. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10358. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10359. }
  10360. }//end of the same index
  10361. }//end of for AC_QUANTITY
  10362. }
  10363. // Check if this message is triggered by TriggerMessage
  10364. if(cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  10365. {
  10366. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10367. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Trigger]);
  10368. }
  10369. // Clear meterValue buffer for the next transaction
  10370. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10371. {
  10372. meterValueBufferClear(gun_index);
  10373. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Transaction_Begin, FALSE);
  10374. }
  10375. // Message
  10376. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  10377. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  10378. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  10379. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  10380. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  10381. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  10382. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  10383. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  10384. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  10385. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  10386. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  10387. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  10388. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  10389. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  10390. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  10391. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  10392. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  10393. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  10394. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10395. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  10396. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  10397. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  10398. {
  10399. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  10400. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  10401. json_object_object_add(TransactionEvent, "idToken", idToken);
  10402. }
  10403. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  10404. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  10405. json_object_object_add(TransactionEvent, "evse", evse);
  10406. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  10407. {
  10408. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  10409. {
  10410. json_object *meterValue = json_object_new_object();
  10411. json_object *sampledValues = json_object_new_array();
  10412. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  10413. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  10414. {
  10415. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  10416. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) ||
  10417. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) ||
  10418. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) ||
  10419. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  10420. {
  10421. 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)) ||
  10422. ((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) == NULL)))
  10423. {
  10424. json_object *sampledValue = json_object_new_object();
  10425. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  10426. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  10427. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  10428. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  10429. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  10430. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  10431. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  10432. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  10433. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  10434. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  10435. {
  10436. json_object *unitOfMeasure = json_object_new_object();
  10437. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  10438. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  10439. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  10440. }
  10441. json_object_array_add(sampledValues, sampledValue);
  10442. }
  10443. }
  10444. }
  10445. json_object_object_add(meterValue, "sampledValue", sampledValues);
  10446. json_object_array_add(meterValues, meterValue);
  10447. }
  10448. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10449. }
  10450. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10451. {
  10452. json_object *meterValues = json_object_new_array();
  10453. meterValueBufferQuery(gun_index, meterValues);
  10454. if(json_object_array_length(meterValues) > 0)
  10455. {
  10456. DEBUG_INFO("parsed meterValue: %s\n", json_object_to_json_string_ext(meterValues, JSON_C_TO_STRING_PLAIN));
  10457. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10458. }
  10459. }
  10460. random_uuid(guid);
  10461. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  10462. json_object_put(TransactionEvent);
  10463. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  10464. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  10465. {
  10466. result = PASS;
  10467. }
  10468. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  10469. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10470. {
  10471. OCPP_insert_transaction_msg(YES, message);
  10472. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  10473. }
  10474. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10475. {
  10476. OCPP_insert_transaction_msg(NO, message);
  10477. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  10478. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  10479. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  10480. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  10481. }
  10482. return result;
  10483. }
  10484. //==========================================
  10485. // send confirm routine
  10486. //==========================================
  10487. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  10488. {
  10489. mtrace();
  10490. int result = FAIL;
  10491. char message[4096]={0};
  10492. json_object *CancelReservation = json_object_new_object();
  10493. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  10494. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  10495. sprintf(message,"[%d,\"%s\",%s]"
  10496. ,MESSAGE_TYPE_CALLRESULT
  10497. ,uuid
  10498. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  10499. json_object_put(CancelReservation);
  10500. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  10501. LWS_Send(message);
  10502. result = TRUE;
  10503. return result;
  10504. }
  10505. int sendCertificateSignedConfirmation(char *uuid)
  10506. {
  10507. mtrace();
  10508. int result = FAIL;
  10509. char message[4096]={0};
  10510. json_object *CertificateSigned = json_object_new_object();
  10511. json_object *statusInfo = json_object_new_object();
  10512. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  10513. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10514. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10515. {
  10516. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10517. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10518. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10519. }
  10520. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10521. sprintf(message,"[%d,\"%s\",%s]"
  10522. ,MESSAGE_TYPE_CALLRESULT
  10523. ,uuid
  10524. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10525. json_object_put(CertificateSigned);
  10526. LWS_Send(message);
  10527. result = TRUE;
  10528. return result;
  10529. }
  10530. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10531. {
  10532. mtrace();
  10533. int result = FAIL;
  10534. char message[4096]={0};
  10535. json_object *ChangeAvailability = json_object_new_object();
  10536. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10537. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10538. sprintf(message,"[%d,\"%s\",%s]"
  10539. ,MESSAGE_TYPE_CALLRESULT
  10540. ,uuid
  10541. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10542. json_object_put(ChangeAvailability);
  10543. LWS_Send(message);
  10544. result = TRUE;
  10545. return result;
  10546. }
  10547. int sendClearCacheConfirmation(char *uuid)
  10548. {
  10549. mtrace();
  10550. int result = FAIL;
  10551. char message[4096]={0};
  10552. json_object *ClearCache = json_object_new_object();
  10553. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10554. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10555. sprintf(message,"[%d,\"%s\",%s]"
  10556. ,MESSAGE_TYPE_CALLRESULT
  10557. ,uuid
  10558. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10559. json_object_put(ClearCache);
  10560. LWS_Send(message);
  10561. result = TRUE;
  10562. return result;
  10563. }
  10564. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10565. {
  10566. mtrace();
  10567. int result = FAIL;
  10568. char message[500]={0};
  10569. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10570. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10571. LWS_Send(message);
  10572. return result;
  10573. }
  10574. int sendClearDisplayMessageConfirmation(char *uuid)
  10575. {
  10576. mtrace();
  10577. int result = FAIL;
  10578. char message[4096]={0};
  10579. json_object *ClearDisplayMessage = json_object_new_object();
  10580. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10581. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10582. sprintf(message,"[%d,\"%s\",%s]"
  10583. ,MESSAGE_TYPE_CALLRESULT
  10584. ,uuid
  10585. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10586. json_object_put(ClearDisplayMessage);
  10587. LWS_Send(message);
  10588. result = TRUE;
  10589. return result;
  10590. }
  10591. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10592. {
  10593. mtrace();
  10594. int result = FAIL;
  10595. char message[4096]={0};
  10596. json_object *ClearVariableMonitoring = json_object_new_object();
  10597. json_object *clearMonitoringResults = json_object_new_array();
  10598. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10599. for(int idx=0;idx<variableQuantity;idx++)
  10600. {
  10601. json_object *clearMonitoringResult = json_object_new_object();
  10602. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10603. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10604. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10605. }
  10606. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10607. sprintf(message,"[%d,\"%s\",%s]"
  10608. ,MESSAGE_TYPE_CALLRESULT
  10609. ,uuid
  10610. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10611. json_object_put(ClearVariableMonitoring);
  10612. LWS_Send(message);
  10613. result = TRUE;
  10614. return result;
  10615. }
  10616. int sendCostUpdatedConfirmation(char *uuid)
  10617. {
  10618. mtrace();
  10619. int result = FAIL;
  10620. char message[4096]={0};
  10621. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10622. sprintf(message,"[%d,\"%s\",{}]"
  10623. ,MESSAGE_TYPE_CALLRESULT
  10624. ,uuid);
  10625. LWS_Send(message);
  10626. result = TRUE;
  10627. return result;
  10628. }
  10629. int sendCustomerInformationConfirmation(char *uuid)
  10630. {
  10631. mtrace();
  10632. int result = FAIL;
  10633. char message[4096]={0};
  10634. json_object *CustomerInformation = json_object_new_object();
  10635. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10636. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10637. sprintf(message,"[%d,\"%s\",%s]"
  10638. ,MESSAGE_TYPE_CALLRESULT
  10639. ,uuid
  10640. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10641. json_object_put(CustomerInformation);
  10642. LWS_Send(message);
  10643. result = TRUE;
  10644. return result;
  10645. }
  10646. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10647. {
  10648. mtrace();
  10649. int result = FAIL;
  10650. char message[4096]={0};
  10651. json_object *DataTransfer = json_object_new_object();
  10652. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10653. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10654. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10655. sprintf(message,"[%d,\"%s\",%s]"
  10656. ,MESSAGE_TYPE_CALLRESULT
  10657. ,uuid
  10658. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10659. json_object_put(DataTransfer);
  10660. LWS_Send(message);
  10661. result = TRUE;
  10662. return result;
  10663. }
  10664. int sendDeleteCertificateConfirmation(char *uuid)
  10665. {
  10666. mtrace();
  10667. int result = FAIL;
  10668. char message[4096]={0};
  10669. json_object *DeleteCertificate = json_object_new_object();
  10670. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10671. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10672. sprintf(message,"[%d,\"%s\",%s]"
  10673. ,MESSAGE_TYPE_CALLRESULT
  10674. ,uuid
  10675. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10676. json_object_put(DeleteCertificate);
  10677. LWS_Send(message);
  10678. result = TRUE;
  10679. return result;
  10680. }
  10681. int sendGetBaseReportConfirmation(char *uuid)
  10682. {
  10683. mtrace();
  10684. int result = FAIL;
  10685. char message[4096]={0};
  10686. json_object *GetBaseReport = json_object_new_object();
  10687. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10688. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10689. sprintf(message,"[%d,\"%s\",%s]"
  10690. ,MESSAGE_TYPE_CALLRESULT
  10691. ,uuid
  10692. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10693. json_object_put(GetBaseReport);
  10694. LWS_Send(message);
  10695. result = TRUE;
  10696. return result;
  10697. }
  10698. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10699. {
  10700. mtrace();
  10701. int result = FAIL;
  10702. char message[4096]={0};
  10703. json_object *GetChargingProfiles = json_object_new_object();
  10704. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10705. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10706. sprintf(message,"[%d,\"%s\",%s]"
  10707. ,MESSAGE_TYPE_CALLRESULT
  10708. ,uuid
  10709. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10710. json_object_put(GetChargingProfiles);
  10711. LWS_Send(message);
  10712. result = TRUE;
  10713. return result;
  10714. }
  10715. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int evseIdInt, int nPeriod)
  10716. {
  10717. mtrace();
  10718. int result = FAIL;
  10719. char message[4096]={0};
  10720. int CompositeScheduleIndex = 0;
  10721. json_object *GetCompositeSchedule = json_object_new_object();
  10722. json_object *schedule = json_object_new_object();
  10723. json_object *chargingSchedule = json_object_new_object();
  10724. json_object *chargingSchedulePeriod = json_object_new_array();
  10725. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10726. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10727. CompositeScheduleIndex = (evseIdInt > 0) ?(evseIdInt -1) : 0;
  10728. json_object_object_add(schedule, "evseId", json_object_new_int(evseIdInt));
  10729. if(nPeriod == 0)
  10730. {
  10731. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10732. {
  10733. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10734. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10735. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10736. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10737. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10738. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10739. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10740. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10741. uint8_t isNullSchedulePeriod = TRUE;
  10742. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10743. {
  10744. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10745. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10746. {
  10747. json_object *Period = json_object_new_object();
  10748. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10749. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10750. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10751. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10752. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10753. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10754. json_object_array_add(chargingSchedulePeriod, Period);
  10755. isNullSchedulePeriod = FALSE;
  10756. }
  10757. }
  10758. if(isNullSchedulePeriod == TRUE)
  10759. {
  10760. json_object *Period = json_object_new_object();
  10761. json_object_object_add(Period, "startPeriod", json_object_new_int(0));
  10762. float limit = ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  10763. json_object_object_add(Period, "limit", json_object_new_double(limit));
  10764. json_object_array_add(chargingSchedulePeriod, Period);
  10765. }
  10766. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10767. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10768. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10769. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10770. }
  10771. }
  10772. else
  10773. {
  10774. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10775. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10776. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10777. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10778. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10779. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10780. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10781. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10782. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10783. {
  10784. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10785. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10786. {
  10787. json_object *Period = json_object_new_object();
  10788. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10789. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10790. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10791. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10792. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10793. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10794. json_object_array_add(chargingSchedulePeriod, Period);
  10795. }
  10796. }
  10797. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10798. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10799. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10800. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10801. }
  10802. sprintf(message,"[%d,\"%s\",%s]"
  10803. ,MESSAGE_TYPE_CALLRESULT
  10804. ,uuid
  10805. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10806. json_object_put(GetCompositeSchedule);
  10807. LWS_Send(message);
  10808. result = TRUE;
  10809. return result;
  10810. }
  10811. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10812. {
  10813. mtrace();
  10814. int result = FAIL;
  10815. char message[4096]={0};
  10816. json_object *GetGetDisplayMessages = json_object_new_object();
  10817. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10818. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10819. sprintf(message,"[%d,\"%s\",%s]"
  10820. ,MESSAGE_TYPE_CALLRESULT
  10821. ,uuid
  10822. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10823. json_object_put(GetGetDisplayMessages);
  10824. LWS_Send(message);
  10825. result = TRUE;
  10826. return result;
  10827. }
  10828. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10829. {
  10830. mtrace();
  10831. int result = FAIL;
  10832. char message[4096]={0};
  10833. json_object *GetInstalledCertificateIds = json_object_new_object();
  10834. json_object *certificateHashDataChains = json_object_new_array();
  10835. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10836. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10837. for(int idx=0;idx<certQuantity;idx++)
  10838. {
  10839. json_object *cert = json_object_new_object();
  10840. json_object *certificateHashData = json_object_new_object();
  10841. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10842. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10843. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10844. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10845. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10846. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10847. json_object_array_add(certificateHashDataChains, cert);
  10848. }
  10849. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10850. sprintf(message,"[%d,\"%s\",%s]"
  10851. ,MESSAGE_TYPE_CALLRESULT
  10852. ,uuid
  10853. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10854. json_object_put(GetInstalledCertificateIds);
  10855. LWS_Send(message);
  10856. result = TRUE;
  10857. return result;
  10858. }
  10859. int sendGetLocalListVersionConfirmation(char *uuid)
  10860. {
  10861. mtrace();
  10862. int result = FAIL;
  10863. char message[4096]={0};
  10864. json_object *GetLocalListVersion = json_object_new_object();
  10865. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10866. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10867. sprintf(message,"[%d,\"%s\",%s]"
  10868. ,MESSAGE_TYPE_CALLRESULT
  10869. ,uuid
  10870. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10871. json_object_put(GetLocalListVersion);
  10872. LWS_Send(message);
  10873. result = TRUE;
  10874. return result;
  10875. }
  10876. int sendGetLogConfirmation(char *uuid)
  10877. {
  10878. mtrace();
  10879. int result = FAIL;
  10880. char message[4096]={0};
  10881. json_object *GetLog = json_object_new_object();
  10882. DEBUG_INFO("sendGetLogConfirmation...\n");
  10883. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10884. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10885. sprintf(message,"[%d,\"%s\",%s]"
  10886. ,MESSAGE_TYPE_CALLRESULT
  10887. ,uuid
  10888. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10889. json_object_put(GetLog);
  10890. LWS_Send(message);
  10891. result = TRUE;
  10892. return result;
  10893. }
  10894. int sendGetMonitoringReportConfirmation(char *uuid)
  10895. {
  10896. mtrace();
  10897. int result = FAIL;
  10898. char message[4096]={0};
  10899. json_object *GetMonitoringReport = json_object_new_object();
  10900. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10901. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10902. sprintf(message,"[%d,\"%s\",%s]"
  10903. ,MESSAGE_TYPE_CALLRESULT
  10904. ,uuid
  10905. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10906. json_object_put(GetMonitoringReport);
  10907. LWS_Send(message);
  10908. result = TRUE;
  10909. return result;
  10910. }
  10911. int sendGetReportConfirmation(char *uuid)
  10912. {
  10913. mtrace();
  10914. int result = FAIL;
  10915. char message[4096]={0};
  10916. json_object *GetReport = json_object_new_object();
  10917. DEBUG_INFO("sendGetReportConfirmation...\n");
  10918. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10919. sprintf(message,"[%d,\"%s\",%s]"
  10920. ,MESSAGE_TYPE_CALLRESULT
  10921. ,uuid
  10922. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10923. json_object_put(GetReport);
  10924. LWS_Send(message);
  10925. result = TRUE;
  10926. return result;
  10927. }
  10928. int sendGetTransactionStatusConfirmation(char *uuid)
  10929. {
  10930. mtrace();
  10931. int result = FAIL;
  10932. char message[4096]={0};
  10933. json_object *GetTransactionStatus = json_object_new_object();
  10934. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10935. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator));
  10936. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue));
  10937. sprintf(message,"[%d,\"%s\",%s]"
  10938. ,MESSAGE_TYPE_CALLRESULT
  10939. ,uuid
  10940. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10941. json_object_put(GetTransactionStatus);
  10942. LWS_Send(message);
  10943. result = TRUE;
  10944. return result;
  10945. }
  10946. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10947. {
  10948. mtrace();
  10949. int result = FAIL;
  10950. char message[4096]={0};
  10951. json_object *GetVariables = json_object_new_object();
  10952. json_object *getVariableResults = json_object_new_array();
  10953. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10954. for(int idx=0;idx<variableQuantity;idx++)
  10955. {
  10956. json_object *variableResult = json_object_new_object();
  10957. json_object *component = json_object_new_object();
  10958. json_object *variable = json_object_new_object();
  10959. json_object *evse = json_object_new_object();
  10960. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10961. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10962. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10963. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10964. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10965. if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id > 0)
  10966. {
  10967. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10968. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10969. json_object_object_add(component, "evse", evse);
  10970. }
  10971. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10972. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10973. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10974. json_object_object_add(variableResult, "component", component);
  10975. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10976. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10977. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10978. json_object_object_add(variableResult, "variable", variable);
  10979. json_object_array_add(getVariableResults, variableResult);
  10980. }
  10981. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10982. sprintf(message,"[%d,\"%s\",%s]"
  10983. ,MESSAGE_TYPE_CALLRESULT
  10984. ,uuid
  10985. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10986. json_object_put(GetVariables);
  10987. LWS_Send(message);
  10988. result = TRUE;
  10989. return result;
  10990. }
  10991. int sendInstallCertificateConfirmation(char *uuid)
  10992. {
  10993. mtrace();
  10994. int result = FAIL;
  10995. char message[4096]={0};
  10996. json_object *InstallCertificate = json_object_new_object();
  10997. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10998. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10999. sprintf(message,"[%d,\"%s\",%s]"
  11000. ,MESSAGE_TYPE_CALLRESULT
  11001. ,uuid
  11002. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  11003. json_object_put(InstallCertificate);
  11004. LWS_Send(message);
  11005. result = TRUE;
  11006. return result;
  11007. }
  11008. int sendPublishFirmwareConfirmation(char *uuid)
  11009. {
  11010. mtrace();
  11011. int result = FAIL;
  11012. char message[4096]={0};
  11013. json_object *PublishFirmware = json_object_new_object();
  11014. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  11015. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  11016. sprintf(message,"[%d,\"%s\",%s]"
  11017. ,MESSAGE_TYPE_CALLRESULT
  11018. ,uuid
  11019. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  11020. json_object_put(PublishFirmware);
  11021. LWS_Send(message);
  11022. result = TRUE;
  11023. return result;
  11024. }
  11025. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  11026. {
  11027. mtrace();
  11028. int result = FAIL;
  11029. char message[4096]={0};
  11030. json_object *RemoteStartTransaction = json_object_new_object();
  11031. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  11032. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  11033. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  11034. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  11035. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  11036. sprintf(message,"[%d,\"%s\",%s]"
  11037. ,MESSAGE_TYPE_CALLRESULT
  11038. ,uuid
  11039. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  11040. json_object_put(RemoteStartTransaction);
  11041. LWS_Send(message);
  11042. result = TRUE;
  11043. return result;
  11044. }
  11045. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  11046. {
  11047. mtrace();
  11048. int result = FAIL;
  11049. char message[4096]={0};
  11050. json_object *RemoteStopTransaction = json_object_new_object();
  11051. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  11052. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  11053. sprintf(message,"[%d,\"%s\",%s]"
  11054. ,MESSAGE_TYPE_CALLRESULT
  11055. ,uuid
  11056. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  11057. json_object_put(RemoteStopTransaction);
  11058. LWS_Send(message);
  11059. result = TRUE;
  11060. return result;
  11061. }
  11062. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  11063. {
  11064. mtrace();
  11065. int result = FAIL;
  11066. char message[4096]={0};
  11067. json_object *ReserveNow = json_object_new_object();
  11068. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  11069. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  11070. sprintf(message,"[%d,\"%s\",%s]"
  11071. ,MESSAGE_TYPE_CALLRESULT
  11072. ,uuid
  11073. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  11074. json_object_put(ReserveNow);
  11075. LWS_Send(message);
  11076. result = TRUE;
  11077. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  11078. return result;
  11079. }
  11080. int sendResetConfirmation(char *uuid)
  11081. {
  11082. mtrace();
  11083. int result = FAIL;
  11084. char message[4096]={0};
  11085. json_object *Reset = json_object_new_object();
  11086. DEBUG_INFO("sendResetConfirmation...\n");
  11087. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  11088. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  11089. sprintf(message,"[%d,\"%s\",%s]"
  11090. ,MESSAGE_TYPE_CALLRESULT
  11091. ,uuid
  11092. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  11093. json_object_put(Reset);
  11094. LWS_Send(message);
  11095. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  11096. {
  11097. DB_updateBootType(BootReasonEnumType_RemoteReset);
  11098. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  11099. }
  11100. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  11101. {
  11102. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  11103. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  11104. }
  11105. result = TRUE;
  11106. return result;
  11107. }
  11108. int sendSendLocalListConfirmation(char *uuid)
  11109. {
  11110. mtrace();
  11111. int result = FAIL;
  11112. char message[4096]={0};
  11113. json_object *SendLocalList = json_object_new_object();
  11114. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  11115. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  11116. sprintf(message,"[%d,\"%s\",%s]"
  11117. ,MESSAGE_TYPE_CALLRESULT
  11118. ,uuid
  11119. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  11120. json_object_put(SendLocalList);
  11121. LWS_Send(message);
  11122. result = TRUE;
  11123. return result;
  11124. }
  11125. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  11126. {
  11127. mtrace();
  11128. int result = FAIL;
  11129. char message[4096]={0};
  11130. json_object *SetChargingProfile = json_object_new_object();
  11131. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  11132. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  11133. sprintf(message,"[%d,\"%s\",%s]"
  11134. ,MESSAGE_TYPE_CALLRESULT
  11135. ,uuid
  11136. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11137. json_object_put(SetChargingProfile);
  11138. LWS_Send(message);
  11139. result = TRUE;
  11140. return result;
  11141. }
  11142. int sendSetDisplayMessagesConfirmation(char *uuid)
  11143. {
  11144. mtrace();
  11145. int result = FAIL;
  11146. char message[4096]={0};
  11147. json_object *SetDisplayMessage = json_object_new_object();
  11148. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  11149. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  11150. sprintf(message,"[%d,\"%s\",%s]"
  11151. ,MESSAGE_TYPE_CALLRESULT
  11152. ,uuid
  11153. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  11154. json_object_put(SetDisplayMessage);
  11155. LWS_Send(message);
  11156. result = TRUE;
  11157. return result;
  11158. }
  11159. int sendSetMonitoringBaseConfirmation(char *uuid)
  11160. {
  11161. mtrace();
  11162. int result = FAIL;
  11163. char message[4096]={0};
  11164. json_object *SetMonitoringBase = json_object_new_object();
  11165. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  11166. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  11167. sprintf(message,"[%d,\"%s\",%s]"
  11168. ,MESSAGE_TYPE_CALLRESULT
  11169. ,uuid
  11170. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  11171. json_object_put(SetMonitoringBase);
  11172. LWS_Send(message);
  11173. result = TRUE;
  11174. return result;
  11175. }
  11176. int sendSetMonitoringLevelConfirmation(char *uuid)
  11177. {
  11178. mtrace();
  11179. int result = FAIL;
  11180. char message[4096]={0};
  11181. json_object *SetMonitoringLevel = json_object_new_object();
  11182. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  11183. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  11184. sprintf(message,"[%d,\"%s\",%s]"
  11185. ,MESSAGE_TYPE_CALLRESULT
  11186. ,uuid
  11187. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  11188. json_object_put(SetMonitoringLevel);
  11189. LWS_Send(message);
  11190. result = TRUE;
  11191. return result;
  11192. }
  11193. int sendSetNetworkProfileConfirmation(char *uuid)
  11194. {
  11195. mtrace();
  11196. int result = FAIL;
  11197. char message[4096]={0};
  11198. json_object *SetNetworkProfile = json_object_new_object();
  11199. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  11200. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  11201. sprintf(message,"[%d,\"%s\",%s]"
  11202. ,MESSAGE_TYPE_CALLRESULT
  11203. ,uuid
  11204. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  11205. json_object_put(SetNetworkProfile);
  11206. LWS_Send(message);
  11207. result = TRUE;
  11208. return result;
  11209. }
  11210. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  11211. {
  11212. mtrace();
  11213. int result = FAIL;
  11214. char message[4096]={0};
  11215. json_object *SetVariableMonitoring = json_object_new_object();
  11216. json_object *setMonitoringResults = json_object_new_array();
  11217. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  11218. for(int idx=0;idx<variableQuantity;idx++)
  11219. {
  11220. json_object *variableMonitorResult = json_object_new_object();
  11221. json_object *component = json_object_new_object();
  11222. json_object *variable = json_object_new_object();
  11223. json_object *evse = json_object_new_object();
  11224. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  11225. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  11226. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  11227. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  11228. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  11229. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  11230. json_object_object_add(component, "evse", evse);
  11231. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  11232. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  11233. json_object_object_add(variableMonitorResult, "component", component);
  11234. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  11235. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  11236. json_object_object_add(variableMonitorResult, "variable", variable);
  11237. json_object_array_add(setMonitoringResults, variableMonitorResult);
  11238. }
  11239. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  11240. sprintf(message,"[%d,\"%s\",%s]"
  11241. ,MESSAGE_TYPE_CALLRESULT
  11242. ,uuid
  11243. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  11244. json_object_put(SetVariableMonitoring);
  11245. LWS_Send(message);
  11246. result = TRUE;
  11247. return result;
  11248. }
  11249. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  11250. {
  11251. mtrace();
  11252. int result = FAIL;
  11253. char message[4096]={0};
  11254. json_object *SetVariable = json_object_new_object();
  11255. json_object *setVariableResults = json_object_new_array();
  11256. DEBUG_INFO("sendSetVariableConfirmation...\n");
  11257. for(int idx=0;idx<variableQuantity;idx++)
  11258. {
  11259. json_object *variableResult = json_object_new_object();
  11260. json_object *component = json_object_new_object();
  11261. json_object *variable = json_object_new_object();
  11262. json_object *evse = json_object_new_object();
  11263. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  11264. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  11265. if(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id > 0)
  11266. {
  11267. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  11268. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  11269. json_object_object_add(component, "evse", evse);
  11270. }
  11271. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  11272. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance) > 0)
  11273. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  11274. json_object_object_add(variableResult, "component", component);
  11275. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  11276. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance)>0)
  11277. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  11278. json_object_object_add(variableResult, "variable", variable);
  11279. json_object_array_add(setVariableResults, variableResult);
  11280. }
  11281. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  11282. sprintf(message,"[%d,\"%s\",%s]"
  11283. ,MESSAGE_TYPE_CALLRESULT
  11284. ,uuid
  11285. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  11286. json_object_put(SetVariable);
  11287. LWS_Send(message);
  11288. result = TRUE;
  11289. return result;
  11290. }
  11291. int sendTriggerMessageConfirmation(char *uuid)
  11292. {
  11293. mtrace();
  11294. int result = FAIL;
  11295. char message[4096]={0};
  11296. json_object *TriggerMessage = json_object_new_object();
  11297. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  11298. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  11299. sprintf(message,"[%d,\"%s\",%s]",
  11300. MESSAGE_TYPE_CALLRESULT,
  11301. uuid,
  11302. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  11303. json_object_put(TriggerMessage);
  11304. LWS_Send(message);
  11305. result = TRUE;
  11306. return result;
  11307. }
  11308. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  11309. {
  11310. mtrace();
  11311. int result = FAIL;
  11312. char message[4096]={0};
  11313. json_object *UnlockConnector = json_object_new_object();
  11314. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  11315. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  11316. sprintf(message,"[%d,\"%s\",%s]",
  11317. MESSAGE_TYPE_CALLRESULT,
  11318. uuid,
  11319. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  11320. json_object_put(UnlockConnector);
  11321. LWS_Send(message);
  11322. result = TRUE;
  11323. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  11324. return result;
  11325. }
  11326. int sendUnpublishFirmwareConfirmation(char *uuid)
  11327. {
  11328. mtrace();
  11329. int result = FAIL;
  11330. char message[4096]={0};
  11331. json_object *UnpublishFirmware = json_object_new_object();
  11332. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  11333. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  11334. sprintf(message,"[%d,\"%s\",%s]"
  11335. ,MESSAGE_TYPE_CALLRESULT
  11336. ,uuid
  11337. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  11338. json_object_put(UnpublishFirmware);
  11339. LWS_Send(message);
  11340. result = TRUE;
  11341. return result;
  11342. }
  11343. int sendUpdateFirmwareConfirmation(char *uuid)
  11344. {
  11345. mtrace();
  11346. int result = FAIL;
  11347. char message[4096]={0};
  11348. json_object *UpdateFirmware = json_object_new_object();
  11349. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  11350. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  11351. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  11352. sprintf(message,"[%d,\"%s\",%s]"
  11353. ,MESSAGE_TYPE_CALLRESULT
  11354. ,uuid
  11355. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  11356. json_object_put(UpdateFirmware);
  11357. LWS_Send(message);
  11358. result = TRUE;
  11359. return result;
  11360. }
  11361. int sendUnknownConfirmation(char *uuid)
  11362. {
  11363. mtrace();
  11364. int result = FAIL;
  11365. char message[256]={0};
  11366. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  11367. DEBUG_INFO("sendUnknownConfirmation...\n");
  11368. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  11369. LWS_Send(message);
  11370. result = TRUE;
  11371. return result;
  11372. }
  11373. //==========================================
  11374. // send CallError routine
  11375. //==========================================
  11376. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  11377. {
  11378. mtrace();
  11379. char message[220]={0};
  11380. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  11381. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  11382. LWS_Send(message);
  11383. }
  11384. //==========================================
  11385. // Handle server request routine Start
  11386. //==========================================
  11387. int handleCancelReservationRequest(char *uuid, char *payload)
  11388. {
  11389. mtrace();
  11390. int result = FAIL;
  11391. int gunNO = 0;
  11392. int reservationIdInt = -1;
  11393. DEBUG_INFO("handleCancelReservationRequest...\n");
  11394. json_object *CancelReservation;
  11395. CancelReservation = json_tokener_parse(payload);
  11396. if(!is_error(CancelReservation))
  11397. {
  11398. // Required data
  11399. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  11400. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  11401. }
  11402. json_object_put(CancelReservation);
  11403. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  11404. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  11405. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  11406. if(reservationIdInt != -1)
  11407. {
  11408. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11409. //check Transaction active
  11410. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  11411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11412. {
  11413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  11414. {
  11415. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11416. if(gunType[2] == GUN_TYPE_CHAdeMO)
  11417. {
  11418. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  11419. }
  11420. else
  11421. {
  11422. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  11423. }
  11424. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11425. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11426. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11427. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11428. goto end;
  11429. }
  11430. }
  11431. for (int index = 0; index < CCS_QUANTITY; index++)
  11432. {
  11433. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  11434. {
  11435. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11436. if(gunType[2] == GUN_TYPE_CCS)
  11437. {
  11438. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  11439. }
  11440. else
  11441. {
  11442. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  11443. }
  11444. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11445. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11446. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11447. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11448. goto end;
  11449. }
  11450. }
  11451. for (int index = 0; index < GB_QUANTITY; index++)
  11452. {
  11453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  11454. {
  11455. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11456. if(gunType[2] == GUN_TYPE_GBT)
  11457. {
  11458. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  11459. }
  11460. else
  11461. {
  11462. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11463. }
  11464. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11465. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11466. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11467. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11468. goto end;
  11469. }
  11470. }
  11471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11472. {
  11473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  11474. {
  11475. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11476. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11477. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11478. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11479. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11480. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11481. goto end;
  11482. }
  11483. }
  11484. for (int index = 0; index < AC_QUANTITY; index++)
  11485. {
  11486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  11487. {
  11488. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11490. {
  11491. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  11492. }
  11493. else
  11494. {
  11495. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  11496. }
  11497. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11498. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11499. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11500. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11501. goto end;
  11502. }
  11503. }
  11504. }
  11505. //The reservationId does NOT match the reservationId
  11506. sendCancelReservationConfirmation(uuid, gunNO);
  11507. end:
  11508. // Fill in ocpp packet uuid
  11509. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  11510. return result;
  11511. }
  11512. int handleCertificateSignedRequest(char *uuid, char *payload)
  11513. {
  11514. mtrace();
  11515. int result = FAIL;
  11516. json_object *CertificateSigned;
  11517. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11518. CertificateSigned = json_tokener_parse(payload);
  11519. if(!is_error(CertificateSigned))
  11520. {
  11521. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  11522. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  11523. // Required data
  11524. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  11525. // Optional data
  11526. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  11527. {
  11528. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  11529. }
  11530. else
  11531. {
  11532. if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11533. {
  11534. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]);
  11535. }
  11536. else if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11537. {
  11538. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]);
  11539. }
  11540. }
  11541. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11542. {
  11543. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  11544. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11545. fclose(fp);
  11546. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11547. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11548. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  11549. {
  11550. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11551. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  11552. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  11553. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  11554. }
  11555. else
  11556. {
  11557. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11558. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11559. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11560. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11561. }
  11562. }
  11563. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11564. {
  11565. FILE *fp = fopen("/Storage/OCPP/tempV2G.pem", "w");
  11566. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11567. fclose(fp);
  11568. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11569. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11570. if(certVerify(PRIVATE_KEY_V2G, "/Storage/OCPP/tempV2G.pem") == PASS)
  11571. {
  11572. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11573. system("rm -f /Storage/OCPP/certV2G_fallback.pem");
  11574. rename(CERTIFICATE_V2G, "/Storage/OCPP/certV2G_fallback.pem");
  11575. rename("/Storage/OCPP/tempV2G.pem", CERTIFICATE_V2G);
  11576. }
  11577. else
  11578. {
  11579. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11580. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11581. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11582. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11583. }
  11584. }
  11585. else
  11586. {
  11587. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11588. }
  11589. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11590. }
  11591. else
  11592. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11593. json_object_put(CertificateSigned);
  11594. sendCertificateSignedConfirmation(uuid);
  11595. return result;
  11596. }
  11597. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11598. {
  11599. mtrace();
  11600. int result = FAIL;
  11601. int evseId = 0, gunIndex = 0;
  11602. char operationalStatus[16]={0};
  11603. char comfirmstr[20];
  11604. //int specificId = FALSE;
  11605. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11606. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11607. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11608. json_object *ChangeAvailability;
  11609. ChangeAvailability = json_tokener_parse(payload);
  11610. if(!is_error(ChangeAvailability))
  11611. {
  11612. // Required data
  11613. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11614. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11615. // Requested evse. (When omitted, the message refers to the Charging Station as a whole.)
  11616. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11617. {
  11618. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id") != NULL)
  11619. {
  11620. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11621. if(evseId > 0){}
  11622. //specificId = TRUE;
  11623. else
  11624. goto end;
  11625. }
  11626. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11627. {
  11628. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11629. if(gunIndex != 1)
  11630. goto end;
  11631. }
  11632. }
  11633. }
  11634. json_object_put(ChangeAvailability);
  11635. if((evseId != 0) && (evseId <= gunTotalNumber))
  11636. {
  11637. ShmOCPP20Data->ChangeAvailability[evseId-1].evse.id = evseId;
  11638. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11639. }
  11640. else if(evseId == 0)
  11641. {
  11642. for(int i=0; i < gunTotalNumber; i++)
  11643. {
  11644. ShmOCPP20Data->ChangeAvailability[i].evse.id = i+1;
  11645. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11646. }
  11647. }
  11648. /*if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11649. {
  11650. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = 1;
  11651. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11652. }
  11653. else if(gunIndex == 0)
  11654. {
  11655. for(int i=0; i < gunTotalNumber; i++)
  11656. {
  11657. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = 1;
  11658. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11659. }
  11660. }*/
  11661. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11662. {
  11663. //----------------------evseId is 0 ------------------------------------------------//
  11664. if(evseId == 0)
  11665. {
  11666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11667. {
  11668. for(int i=0; i < gunTotalNumber; i++)
  11669. {
  11670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11671. {
  11672. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11673. {
  11674. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11675. {
  11676. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11677. goto end;
  11678. }
  11679. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11680. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11681. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11682. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11683. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11684. {
  11685. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11686. goto end;
  11687. }
  11688. }
  11689. }//END FOR CHAdeMO_QUANTITY
  11690. for (int index = 0; index < CCS_QUANTITY; index++)
  11691. {
  11692. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11693. {
  11694. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11695. {
  11696. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11697. goto end;
  11698. }
  11699. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11700. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11701. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11702. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11703. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11704. {
  11705. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11706. goto end;
  11707. }
  11708. }
  11709. }//END FOR CCS_QUANTITY
  11710. for (int index = 0; index < GB_QUANTITY; index++)
  11711. {
  11712. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11713. {
  11714. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11715. {
  11716. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11717. goto end;
  11718. }
  11719. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11720. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11721. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11722. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11723. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11724. {
  11725. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11726. goto end;
  11727. }
  11728. }
  11729. }// END FOR GB_QUANTITY
  11730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11731. {
  11732. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11733. {
  11734. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11735. {
  11736. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11737. goto end;
  11738. }
  11739. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11740. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11741. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11742. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11743. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11744. {
  11745. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11746. goto end;
  11747. }
  11748. }
  11749. }// END FOR DO_QUANTITY
  11750. for (int index = 0; index < AC_QUANTITY; index++)
  11751. {
  11752. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11753. {
  11754. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11755. {
  11756. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11757. goto end;
  11758. }
  11759. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11760. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11761. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11762. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11763. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11764. {
  11765. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11766. goto end;
  11767. }
  11768. }
  11769. }//END FOR AC_QUANTITY
  11770. }// END FOR gunTotalNumber
  11771. }
  11772. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11773. {
  11774. for(int i=0; i < gunTotalNumber; i++)
  11775. {
  11776. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11777. {
  11778. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11779. goto end;
  11780. }
  11781. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11782. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11783. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11784. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11785. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11786. {
  11787. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11788. goto end;
  11789. }
  11790. }
  11791. }
  11792. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11793. goto end;
  11794. }
  11795. //----------------------gunIndex is not 0 ------------------------------------------------//
  11796. //check Transaction active
  11797. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11798. {
  11799. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO))
  11800. {
  11801. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11802. {
  11803. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11804. goto end;
  11805. }
  11806. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11807. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11808. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11809. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11810. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11811. {
  11812. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11813. goto end;
  11814. }
  11815. else
  11816. {
  11817. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11818. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11819. goto end;
  11820. }
  11821. }
  11822. }//END FOR CHAdeMO_QUANTITY
  11823. for (int index = 0; index < CCS_QUANTITY; index++)
  11824. {
  11825. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS))
  11826. {
  11827. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11828. {
  11829. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11830. goto end;
  11831. }
  11832. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11833. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11834. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11835. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11836. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11837. {
  11838. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11839. goto end;
  11840. }
  11841. else
  11842. {
  11843. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11844. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11845. goto end;
  11846. }
  11847. }
  11848. }//END FOR CCS_QUANTITY
  11849. for (int index = 0; index < GB_QUANTITY; index++)
  11850. {
  11851. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))
  11852. {
  11853. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11854. {
  11855. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11856. goto end;
  11857. }
  11858. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11859. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11860. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11861. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11862. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11863. {
  11864. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11865. goto end;
  11866. }
  11867. else
  11868. {
  11869. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11870. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11871. goto end;
  11872. }
  11873. }
  11874. }// END FOR GB_QUANTITY
  11875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11876. {
  11877. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))
  11878. {
  11879. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11880. {
  11881. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11882. goto end;
  11883. }
  11884. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11885. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11886. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11887. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11888. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11889. {
  11890. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11891. goto end;
  11892. }
  11893. else
  11894. {
  11895. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11896. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11897. goto end;
  11898. }
  11899. }
  11900. }// END FOR DO_QUANTITY
  11901. for (int index = 0; index < AC_QUANTITY; index++)
  11902. {
  11903. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC))
  11904. {
  11905. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11906. {
  11907. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11908. goto end;
  11909. }
  11910. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11911. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11912. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11913. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11914. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11915. {
  11916. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11917. goto end;
  11918. }
  11919. else
  11920. {
  11921. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11922. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11923. goto end;
  11924. }
  11925. }
  11926. }//END FOR AC_QUANTITY
  11927. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11928. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11929. {
  11930. //----------------------gunIndex is 0 ------------------------------------------------//
  11931. if(evseId == 0)
  11932. {
  11933. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11934. {
  11935. for(int i=0; i < gunTotalNumber; i++)
  11936. {
  11937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11938. {
  11939. 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
  11940. {
  11941. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11942. goto end;
  11943. }
  11944. }//END FOR CHAdeMO_QUANTITY
  11945. for (int index = 0; index < CCS_QUANTITY; index++)
  11946. {
  11947. 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
  11948. {
  11949. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11950. goto end;
  11951. }
  11952. }//END FOR CCS_QUANTITY
  11953. for (int index = 0; index < GB_QUANTITY; index++)
  11954. {
  11955. 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
  11956. {
  11957. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11958. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11959. goto end;
  11960. }
  11961. }// END FOR GB_QUANTITY
  11962. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11963. {
  11964. 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
  11965. {
  11966. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11967. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11968. goto end;
  11969. }
  11970. }// END FOR DO_QUANTITY
  11971. for (int index = 0; index < AC_QUANTITY; index++)
  11972. {
  11973. 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
  11974. {
  11975. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11976. goto end;
  11977. }
  11978. }//END FOR CHAdeMO_QUANTITY
  11979. }// END FOR gunTotalNumber
  11980. }
  11981. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11982. {
  11983. for(int i=0; i < gunTotalNumber; i++)
  11984. {
  11985. for (int index = 0; index < AC_QUANTITY; index++)
  11986. {
  11987. 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
  11988. {
  11989. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11990. goto end;
  11991. }
  11992. }//END FOR CHAdeMO_QUANTITY
  11993. } // END FOR gunTotalNumber
  11994. }
  11995. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11996. goto end;
  11997. }
  11998. //----------------------gunIndex is not 0 ------------------------------------------------//
  11999. //check Transaction active
  12000. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12001. {
  12002. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  12003. {
  12004. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  12005. goto end;
  12006. }
  12007. }//END FOR CHAdeMO_QUANTITY
  12008. for (int index = 0; index < CCS_QUANTITY; index++)
  12009. {
  12010. if ((((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  12011. {
  12012. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  12013. goto end;
  12014. }
  12015. }//END FOR CCS_QUANTITY
  12016. for (int index = 0; index < GB_QUANTITY; index++)
  12017. {
  12018. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  12019. {
  12020. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  12021. goto end;
  12022. }
  12023. }// END FOR GB_QUANTITY
  12024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12025. {
  12026. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  12027. {
  12028. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  12029. goto end;
  12030. }
  12031. }// END FOR DO_QUANTITY
  12032. for (int index = 0; index < AC_QUANTITY; index++)
  12033. {
  12034. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  12035. {
  12036. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  12037. goto end;
  12038. }
  12039. }//END FOR AC_QUANTITY
  12040. }//END FOR AvailabilityEnumTypeStr[Operative]
  12041. end:
  12042. if((evseId > 0) && (evseId <= gunTotalNumber))
  12043. {
  12044. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].Response_status, "%s", comfirmstr );
  12045. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  12046. ShmOCPP20Data->CsMsg.bits[evseId-1].ChangeAvailabilityReq = ON;
  12047. }
  12048. else if(evseId == 0)
  12049. {
  12050. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  12051. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  12052. {
  12053. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  12054. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  12055. }
  12056. }
  12057. else
  12058. {
  12059. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  12060. }
  12061. sendChangeAvailabilityConfirmation(uuid, (evseId==0?evseId:evseId-1));
  12062. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12063. return result;
  12064. }
  12065. int handleClearCacheRequest(char *uuid, char *payload)
  12066. {
  12067. mtrace();
  12068. int result = FAIL;
  12069. char rmFileCmd[100]={0};
  12070. struct stat stats;
  12071. DEBUG_INFO("handleClearCacheRequest...\n");
  12072. stat("/Storage/OCPP", &stats);
  12073. // Check for directory existence
  12074. if (S_ISDIR(stats.st_mode) == 1)
  12075. {}
  12076. else
  12077. {
  12078. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  12079. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  12080. system(rmFileCmd);
  12081. }
  12082. if(DB_cleanLocalCache() != PASS)
  12083. {
  12084. DEBUG_INFO("open AuthorizationCache file failed\n");
  12085. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  12086. }
  12087. else
  12088. {
  12089. DEBUG_INFO("open AuthorizationCache file successful\n");
  12090. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  12091. }
  12092. sendClearCacheConfirmation(uuid);
  12093. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12094. return result;
  12095. }
  12096. int handleClearChargingProfileRequest(char *uuid, char *payload)
  12097. {
  12098. mtrace();
  12099. int result = FAIL;
  12100. int resultRename;
  12101. int evseIdInt, chargingProfileIdInt, stackLevelInt;
  12102. char chargingProfilePurposeStr[26]={0};
  12103. int tempevseIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  12104. char tempchargingProfilePurposeStr[26]={0};
  12105. char sstr[160]={0};
  12106. char str[100]={0};
  12107. int c = 0;
  12108. char *loc;
  12109. char fname[200]={0};
  12110. char comfirmstr[20]={0};
  12111. char word[1600]={0};
  12112. int clearflag = FALSE;
  12113. int chargingProfileIdIsNULL = FALSE;
  12114. int evseIsNULL = FALSE;
  12115. int chargingProfilePurposeIsNULL = FALSE;
  12116. int stackLevelIsNULL = FALSE;
  12117. //int GotoEnd = FALSE;
  12118. FILE *fptr1, *fptr2;
  12119. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  12120. int n_chargingProfile=0;
  12121. int isEmptyFile = FALSE;
  12122. char sLineWord[1600]={0};
  12123. char chargingProfiles[10][100]={0};
  12124. int ChargeProfileCount = 0;
  12125. int ch;
  12126. evseIdInt = chargingProfileIdInt = stackLevelInt = 0;
  12127. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  12128. json_object *ClearChargingProfile;
  12129. ClearChargingProfile = json_tokener_parse(payload);
  12130. if(!is_error(ClearChargingProfile))
  12131. {
  12132. // Optional data
  12133. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  12134. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  12135. else
  12136. chargingProfileIdIsNULL = TRUE;
  12137. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  12138. evseIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  12139. else
  12140. evseIsNULL = TRUE;
  12141. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  12142. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  12143. else
  12144. chargingProfilePurposeIsNULL = TRUE;
  12145. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  12146. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  12147. else
  12148. stackLevelIsNULL = TRUE;
  12149. }
  12150. json_object_put(ClearChargingProfile);
  12151. if(evseIsNULL == FALSE)
  12152. {
  12153. switch(evseIdInt)
  12154. {
  12155. case 0:
  12156. if(chargingProfilePurposeIsNULL == TRUE)
  12157. {
  12158. int l = 0;
  12159. strcpy(fname, ChargingStationMaxProfile_JSON);
  12160. if((access(fname,F_OK))!=-1)
  12161. {
  12162. strcpy(chargingProfiles[l], fname);
  12163. l = l + 1;
  12164. }
  12165. strcpy(fname, TxDefaultProfile_0_JSON);
  12166. if((access(fname,F_OK))!=-1)
  12167. {
  12168. strcpy(chargingProfiles[l], fname);
  12169. l = l + 1;
  12170. }
  12171. ChargeProfileCount = l;
  12172. }
  12173. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  12174. {
  12175. strcpy(fname, ChargingStationMaxProfile_JSON);
  12176. if((access(fname,F_OK))!=-1)
  12177. {
  12178. strcpy(chargingProfiles[0], fname);
  12179. ChargeProfileCount = 1;
  12180. }
  12181. }
  12182. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12183. {
  12184. strcpy(fname, TxDefaultProfile_0_JSON);
  12185. if((access(fname,F_OK))!=-1)
  12186. {
  12187. strcpy(chargingProfiles[0], fname);
  12188. ChargeProfileCount = 1;
  12189. }
  12190. }
  12191. break;
  12192. default:
  12193. if(chargingProfilePurposeIsNULL == TRUE)
  12194. {
  12195. int m = 0;
  12196. memset(fname, 0, ARRAY_SIZE(fname));
  12197. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12198. if((access(fname,F_OK))!=-1)
  12199. {
  12200. strcpy(chargingProfiles[m], fname);
  12201. m = m + 1;
  12202. }
  12203. memset(fname, 0, ARRAY_SIZE(fname));
  12204. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12205. if((access(fname,F_OK))!=-1)
  12206. {
  12207. strcpy(chargingProfiles[m], fname);
  12208. m = m + 1;
  12209. }
  12210. ChargeProfileCount = m;
  12211. }
  12212. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12213. {
  12214. //strcpy(fname, TxDefaultProfile_1_JSON);
  12215. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12216. if((access(fname,F_OK))!=-1)
  12217. {
  12218. strcpy(chargingProfiles[0], fname);
  12219. ChargeProfileCount = 1;
  12220. }
  12221. }
  12222. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  12223. {
  12224. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12225. if((access(fname,F_OK))!=-1)
  12226. {
  12227. strcpy(chargingProfiles[0], fname);
  12228. ChargeProfileCount = 1;
  12229. }
  12230. }
  12231. //strcpy(fname, ChargePointMaxProfile_JSON );
  12232. break;
  12233. }
  12234. }
  12235. else // Check all Charging Profiles
  12236. {
  12237. int i = 0;
  12238. char fnametemp[200]={0};
  12239. ChargeProfileCount = 0;
  12240. //Check ChargePointMaxProfile.json exit
  12241. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12242. {
  12243. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  12244. i = i + 1;
  12245. }
  12246. //Check TxDefaultProfile_%d.json
  12247. for(int j=1; j <= gunTotalNumber; j++)
  12248. {
  12249. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12250. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  12251. if((access(fnametemp,F_OK))!=-1)
  12252. {
  12253. strcpy(chargingProfiles[i], fnametemp);
  12254. i = i + 1;
  12255. }
  12256. }
  12257. //Check TxProfile_%d.json
  12258. for(int j=1; j <= gunTotalNumber; j++)
  12259. {
  12260. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12261. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  12262. if((access(fnametemp,F_OK))!=-1)
  12263. {
  12264. strcpy(chargingProfiles[i], fnametemp);
  12265. i = i + 1;
  12266. }
  12267. }
  12268. ChargeProfileCount = i;
  12269. }// End connectorIsNULL is TRUE
  12270. if(ChargeProfileCount == 0)
  12271. {
  12272. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12273. goto end;
  12274. }
  12275. if(evseIsNULL == FALSE && (evseIdInt != 0) && ( (evseIdInt-1) > gunTotalNumber) )
  12276. {
  12277. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12278. goto end;
  12279. }
  12280. if((evseIsNULL == FALSE) && (evseIdInt == 0) )
  12281. {
  12282. memset(str, 0, ARRAY_SIZE(str));
  12283. // clear temp file
  12284. sprintf(str,"rm -f %s",temp);
  12285. system(str);
  12286. for(int k=0; k < ChargeProfileCount; k++)
  12287. {
  12288. memset(str, 0, ARRAY_SIZE(str));
  12289. //clear file in C
  12290. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12291. system(str);
  12292. }
  12293. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12294. goto end;
  12295. }
  12296. else if(evseIsNULL == TRUE)
  12297. {
  12298. for(int k=0; k < ChargeProfileCount; k++)
  12299. {
  12300. fptr1 = fopen(chargingProfiles[k], "r");
  12301. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  12302. //Check Charging Profile Count
  12303. while(fscanf(fptr1, "%s", word) != EOF)
  12304. {
  12305. //DEBUG_INFO("word=%s\n",word);
  12306. if(strstr(word, "id")!= NULL)
  12307. {
  12308. //DEBUG_INFO("test id \n");
  12309. n_chargingProfile = n_chargingProfile + 1;
  12310. //DEBUG_INFO("id Found\n");
  12311. }
  12312. }
  12313. rewind(fptr1);
  12314. //search Charging Profile Element
  12315. //int i= 0;
  12316. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12317. {
  12318. //------------------------tempconnectorIdInt------------------------//
  12319. loc = strstr(sLineWord, "evseId");
  12320. c = 0;
  12321. memset(sstr ,0, sizeof(sstr) );
  12322. while (loc[strlen("evseId")+2+c] != ',')
  12323. {
  12324. sstr[c] = loc[strlen("evseId")+2+c];
  12325. c++;
  12326. }
  12327. sstr[c] = '\0';
  12328. tempevseIdInt = atoi(sstr);
  12329. printf("file's gun number is %d\n", tempevseIdInt);
  12330. //--------------------------id--------------------//
  12331. c = 0;
  12332. loc = strstr(sLineWord, "id");
  12333. memset(sstr ,0, ARRAY_SIZE(sstr));
  12334. while (loc[strlen("id")+2+c] != ',')
  12335. {
  12336. sstr[c] = loc[strlen("id")+2+c];
  12337. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12338. c++;
  12339. }
  12340. sstr[c] = '\0';
  12341. tempchargingProfileIdInt = atoi(sstr);
  12342. //stackLevel
  12343. c = 0;
  12344. loc = strstr(sLineWord, "stackLevel");
  12345. memset(sstr ,0, ARRAY_SIZE(sstr));
  12346. while (loc[strlen("stackLevel")+2+c] != ',')
  12347. {
  12348. sstr[c] = loc[strlen("stackLevel")+2+c];
  12349. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12350. c++;
  12351. }
  12352. sstr[c] = '\0';
  12353. tempstackLevelInt = atoi(sstr);
  12354. c = 0;
  12355. loc = strstr(sLineWord, "chargingProfilePurpose");
  12356. memset(sstr ,0, ARRAY_SIZE(sstr));
  12357. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12358. {
  12359. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12360. c++;
  12361. }
  12362. sstr[c] = '\0';
  12363. strcpy(tempchargingProfilePurposeStr, sstr);
  12364. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12365. {
  12366. //------- not write to fptr2-------//
  12367. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12368. //clearflag = TRUE;
  12369. }
  12370. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  12371. {
  12372. //------- not write to fptr2-------//
  12373. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12374. }
  12375. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12376. {
  12377. //------- not write to fptr2-------//
  12378. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12379. }
  12380. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  12381. {
  12382. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12383. }
  12384. else
  12385. {
  12386. fprintf(fptr2, sLineWord);//writing data into file
  12387. }
  12388. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12389. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12390. if(clearflag == TRUE)
  12391. {
  12392. fclose(fptr1);
  12393. fclose(fptr2);
  12394. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12395. system(str);
  12396. // clear temp file
  12397. sprintf(str,"rm -f %s",temp);
  12398. system(str);
  12399. }
  12400. else
  12401. {
  12402. fclose(fptr1);
  12403. fclose(fptr2);
  12404. memset(str, 0, ARRAY_SIZE(str));
  12405. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12406. system(str);
  12407. resultRename = rename(temp, chargingProfiles[k]);
  12408. if(resultRename == 0)
  12409. {
  12410. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  12411. }
  12412. else
  12413. {
  12414. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  12415. }
  12416. if(comfirmstr[0]== 0)
  12417. {
  12418. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12419. }
  12420. //Check chargingProfile is empty file
  12421. /*------ Read the file ----------------*/
  12422. fptr1=fopen(chargingProfiles[k],"r");
  12423. ch=fgetc(fptr1);
  12424. rewind(fptr1);
  12425. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12426. if(ch!=EOF)
  12427. {
  12428. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12429. {
  12430. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12431. if(sLineWord[0]=='\0')
  12432. {
  12433. isEmptyFile = TRUE;
  12434. break;
  12435. }
  12436. else
  12437. {
  12438. isEmptyFile = FALSE;
  12439. break;
  12440. }
  12441. }
  12442. }
  12443. else
  12444. isEmptyFile = TRUE;
  12445. fclose(fptr1);
  12446. if(isEmptyFile == TRUE)
  12447. {
  12448. memset(str, 0, ARRAY_SIZE(str));
  12449. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12450. system(str);
  12451. }
  12452. }
  12453. }// End of while(int k=0; k < ChargePointCount; k++)
  12454. }
  12455. else if((evseIsNULL == FALSE) && (evseIdInt != 0) )
  12456. {
  12457. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  12458. for(int k=0; k < ChargeProfileCount; k++)
  12459. {
  12460. fptr1 = fopen(chargingProfiles[k], "r");
  12461. fptr2 = fopen(temp, "w+");
  12462. //Check Charging Profile Count
  12463. while(fscanf(fptr1, "%s", word) != EOF)
  12464. {
  12465. //DEBUG_INFO("word=%s\n",word);
  12466. if(strstr(word, "id")!= NULL)
  12467. {
  12468. n_chargingProfile = n_chargingProfile + 1;
  12469. }
  12470. }
  12471. rewind(fptr1);
  12472. //search Charging Profile Element
  12473. //int i= 0;
  12474. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12475. {
  12476. //*************************tempevseIdInt*********************************/
  12477. loc = strstr(sLineWord, "evseId");
  12478. c = 0;
  12479. memset(sstr ,0, ARRAY_SIZE(sstr));
  12480. while (loc[strlen("evseId")+2+c] != ',')
  12481. {
  12482. sstr[c] = loc[strlen("evseId")+2+c];
  12483. c++;
  12484. }
  12485. sstr[c] = '\0';
  12486. tempevseIdInt = atoi(sstr);
  12487. //id
  12488. c = 0;
  12489. loc = strstr(sLineWord, "id");
  12490. memset(sstr ,0, ARRAY_SIZE(sstr));
  12491. while (loc[strlen("id")+2+c] != ',')
  12492. {
  12493. sstr[c] = loc[strlen("id")+2+c];
  12494. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12495. c++;
  12496. }
  12497. sstr[c] = '\0';
  12498. tempchargingProfileIdInt = atoi(sstr);
  12499. //stackLevel
  12500. c = 0;
  12501. loc = strstr(sLineWord, "stackLevel");
  12502. memset(sstr ,0, ARRAY_SIZE(sstr));
  12503. while (loc[strlen("stackLevel")+2+c] != ',')
  12504. {
  12505. sstr[c] = loc[strlen("stackLevel")+2+c];
  12506. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12507. c++;
  12508. }
  12509. sstr[c] = '\0';
  12510. tempstackLevelInt = atoi(sstr);
  12511. c = 0;
  12512. loc = strstr(sLineWord, "chargingProfilePurpose");
  12513. memset(sstr ,0, ARRAY_SIZE(sstr));
  12514. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12515. {
  12516. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12517. c++;
  12518. }
  12519. sstr[c] = '\0';
  12520. strcpy(tempchargingProfilePurposeStr, sstr);
  12521. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12522. {
  12523. //------- not write to fptr2-------//
  12524. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12525. //clearflag = TRUE;
  12526. }
  12527. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12528. {
  12529. //------- not write to fptr2-------//
  12530. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12531. }
  12532. else if(stackLevelIsNULL == TRUE)
  12533. {
  12534. //Clear Whole File
  12535. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12536. clearflag = TRUE;
  12537. break;
  12538. }
  12539. else
  12540. {
  12541. fprintf(fptr2, sLineWord);//writing data into file
  12542. }
  12543. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12544. }
  12545. if(clearflag == TRUE)
  12546. {
  12547. fclose(fptr1);
  12548. fclose(fptr2);
  12549. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12550. system(str);
  12551. // clear temp file
  12552. sprintf(str,"rm -f %s",temp);
  12553. system(str);
  12554. }
  12555. else
  12556. {
  12557. fclose(fptr1);
  12558. fclose(fptr2);
  12559. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12560. system(str);
  12561. resultRename = rename(temp, chargingProfiles[k]);
  12562. if(resultRename == 0)
  12563. {
  12564. DEBUG_INFO("File ChargingProfile renamed successfully");
  12565. }
  12566. else
  12567. {
  12568. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  12569. }
  12570. if(comfirmstr[0]== 0)
  12571. {
  12572. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12573. }
  12574. //Check chargingProfile is empty file
  12575. /*------ Read the file ----------------*/
  12576. fptr1=fopen(chargingProfiles[k],"r");
  12577. ch=fgetc(fptr1);
  12578. rewind(fptr1);
  12579. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12580. if(ch!=EOF)
  12581. {
  12582. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12583. {
  12584. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12585. if(sLineWord[0]=='\0')
  12586. {
  12587. isEmptyFile = TRUE;
  12588. break;
  12589. }
  12590. else
  12591. {
  12592. isEmptyFile = FALSE;
  12593. break;
  12594. }
  12595. }
  12596. }
  12597. else
  12598. isEmptyFile = TRUE;
  12599. fclose(fptr1);
  12600. if(isEmptyFile == TRUE)
  12601. {
  12602. memset(str, 0, ARRAY_SIZE(str));
  12603. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12604. system(str);
  12605. }
  12606. /*------- End of reading ---------------*/
  12607. }
  12608. } // while(int k=0; k < ChargeProfileCount; k++)
  12609. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12610. end:
  12611. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12612. {
  12613. if(evseIdInt == 0)
  12614. {
  12615. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12616. {
  12617. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12618. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12619. }
  12620. }
  12621. else
  12622. {
  12623. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12624. checkCompositeSchedule(evseIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[evseIdInt-1], 0, TRUE);
  12625. }
  12626. }
  12627. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12628. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12629. return result;
  12630. }
  12631. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12632. {
  12633. mtrace();
  12634. int result = FAIL;
  12635. json_object *ClearDisplayMessage;
  12636. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12637. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12638. ClearDisplayMessage = json_tokener_parse(payload);
  12639. if(!is_error(ClearDisplayMessage))
  12640. {
  12641. // Required data
  12642. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12643. {
  12644. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12645. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12646. }
  12647. }
  12648. json_object_put(ClearDisplayMessage);
  12649. sendCostUpdatedConfirmation(uuid);
  12650. return result;
  12651. }
  12652. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12653. {
  12654. mtrace();
  12655. int result = FAIL;
  12656. int isSpecificIdfound = FALSE;
  12657. char sqlCmd[128];
  12658. char *errMsg = 0;
  12659. json_object *ClearVariableMonitoring;
  12660. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12661. ClearVariableMonitoring = json_tokener_parse(payload);
  12662. if(!is_error(ClearVariableMonitoring))
  12663. {
  12664. // Required data
  12665. if(json_object_array_length(json_object_object_get(ClearVariableMonitoring, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12666. {
  12667. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitoring, "id"));idx++)
  12668. {
  12669. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitoring, "id"), idx));
  12670. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12671. isSpecificIdfound = FALSE;
  12672. for(uint8_t idx_vm=0;idx_vm<10;idx_vm++)
  12673. {
  12674. if(ShmOCPP20Data->MonitoringComponentVariable[idx_vm].id == ShmOCPP20Data->ClearVariableMonitoring.id[idx])
  12675. {
  12676. isSpecificIdfound = TRUE;
  12677. sprintf(sqlCmd, "delete from ocpp20_variable_monitoring where id=%d", ShmOCPP20Data->ClearVariableMonitoring.id[idx]);
  12678. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  12679. {
  12680. DEBUG_INFO("SQL error: %s\n",errMsg);
  12681. }
  12682. }
  12683. }
  12684. if(isSpecificIdfound == TRUE)
  12685. {
  12686. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12687. }
  12688. else
  12689. {
  12690. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_NotFound]);
  12691. }
  12692. }
  12693. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12694. for(uint8_t idx_vm=0;idx_vm<10;idx_vm++)
  12695. {
  12696. memset(&ShmOCPP20Data->MonitoringComponentVariable, 0x00, sizeof(struct SetMonitoringDataType));
  12697. }
  12698. DB_variableMonitoringLoadFromDb();
  12699. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitoring, "id")));
  12700. }
  12701. }
  12702. json_object_put(ClearVariableMonitoring);
  12703. return result;
  12704. }
  12705. int handleCostUpdatedRequest(char *uuid, char *payload)
  12706. {
  12707. mtrace();
  12708. int result = FAIL;
  12709. json_object *CostUpdate;
  12710. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12711. CostUpdate = json_tokener_parse(payload);
  12712. if(!is_error(CostUpdate))
  12713. {
  12714. // Required data
  12715. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12716. {
  12717. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12718. }
  12719. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12720. {
  12721. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12722. }
  12723. }
  12724. json_object_put(CostUpdate);
  12725. sendCostUpdatedConfirmation(uuid);
  12726. return result;
  12727. }
  12728. int handleCustomerInformationRequest(char *uuid, char *payload)
  12729. {
  12730. mtrace();
  12731. int result = FAIL;
  12732. json_object *CustomerInformation;
  12733. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12734. CustomerInformation = json_tokener_parse(payload);
  12735. if(!is_error(CustomerInformation))
  12736. {
  12737. // Required data
  12738. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12739. {
  12740. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12741. }
  12742. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12743. {
  12744. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12745. }
  12746. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12747. {
  12748. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12749. }
  12750. // Optional data
  12751. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12752. {
  12753. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12754. {
  12755. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12756. }
  12757. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12758. {
  12759. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12760. }
  12761. }
  12762. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12763. {
  12764. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12765. {
  12766. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12767. }
  12768. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12769. {
  12770. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12771. }
  12772. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12773. {
  12774. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12775. }
  12776. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12777. {
  12778. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12779. }
  12780. }
  12781. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12782. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12783. }
  12784. else
  12785. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12786. json_object_put(CustomerInformation);
  12787. sendCustomerInformationConfirmation(uuid);
  12788. return result;
  12789. }
  12790. void createFirmwareVersionByDataTransfer(void)
  12791. {
  12792. json_object *FirmwareDataTransfer = json_object_new_object();
  12793. // AC & DC model
  12794. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12795. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12796. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12797. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12798. // DC model
  12799. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12800. {
  12801. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12802. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12803. (gunType[3] != GUN_TYPE_UNKNOWN))
  12804. {
  12805. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12806. }
  12807. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='L') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='Z'))
  12808. {
  12809. // DS DM DW
  12810. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12811. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12812. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12813. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12814. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12815. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12816. }
  12817. else
  12818. {
  12819. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12820. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12821. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12822. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12823. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12824. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12825. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12826. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12827. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12828. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12829. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12830. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12831. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12832. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12833. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12834. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12835. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12836. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12837. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12838. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12839. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12840. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12841. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12842. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12843. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12844. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12845. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12846. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12847. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12848. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12849. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12850. }
  12851. }
  12852. // 4G model
  12853. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12854. {
  12855. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12856. }
  12857. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12858. json_object_put(FirmwareDataTransfer);
  12859. }
  12860. int handleDataTransferRequest(char *uuid, char *payload)
  12861. {
  12862. mtrace();
  12863. int result = PASS;
  12864. DEBUG_INFO("handleDataTransferRequest...\n");
  12865. if((uuid != NULL) && (payload != NULL))
  12866. {
  12867. json_object *DataTransfer;
  12868. DataTransfer = json_tokener_parse(payload);
  12869. if(!is_error(DataTransfer))
  12870. {
  12871. // Required data
  12872. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12873. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12874. // Optional data
  12875. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12876. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12877. if(json_object_object_get(DataTransfer, "data") != NULL)
  12878. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12879. result = PASS;
  12880. }
  12881. json_object_put(DataTransfer);
  12882. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12883. {
  12884. // Send all moudle firmware version on EVSE
  12885. createFirmwareVersionByDataTransfer();
  12886. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12887. }
  12888. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12889. {
  12890. system("/usr/bin/run_tmate_restart.sh &");
  12891. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12892. }
  12893. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12894. {
  12895. json_object *data;
  12896. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12897. if(!is_error(data))
  12898. {
  12899. 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))
  12900. {
  12901. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12902. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12903. if(json_object_object_get(data, "SOC") != NULL)
  12904. {
  12905. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12906. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12907. }
  12908. if(json_object_object_get(data, "Energy") != NULL)
  12909. {
  12910. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12911. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12912. }
  12913. if(json_object_object_get(data, "Duration") != NULL)
  12914. {
  12915. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12916. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12917. }
  12918. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12919. }
  12920. else
  12921. {
  12922. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12923. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12924. }
  12925. }
  12926. else
  12927. {
  12928. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12929. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12930. }
  12931. json_object_put(data);
  12932. }
  12933. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12934. {
  12935. json_object *data;
  12936. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12937. if(!is_error(data))
  12938. {
  12939. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12940. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12941. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12942. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12943. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12944. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12945. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12946. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12947. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12948. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12949. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12950. }
  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. json_object_put(data);
  12957. }
  12958. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12959. {
  12960. json_object *data;
  12961. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12962. if(!is_error(data))
  12963. {
  12964. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12965. if(json_object_object_get(data, "Content_Type") != NULL)
  12966. {
  12967. 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))
  12968. {
  12969. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12970. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12971. {
  12972. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12973. }
  12974. }
  12975. else
  12976. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12977. }
  12978. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12979. }
  12980. else
  12981. {
  12982. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12983. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12984. }
  12985. json_object_put(data);
  12986. }
  12987. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12988. {
  12989. json_object *data;
  12990. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12991. if(!is_error(data))
  12992. {
  12993. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12994. if(json_object_object_get(data, "ConnectorId") != NULL)
  12995. {
  12996. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12997. }
  12998. if(json_object_object_get(data, "Page_Index") != NULL)
  12999. {
  13000. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  13001. }
  13002. if(json_object_object_get(data, "Duration") != NULL)
  13003. {
  13004. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  13005. }
  13006. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  13007. }
  13008. else
  13009. {
  13010. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13011. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13012. }
  13013. json_object_put(data);
  13014. }
  13015. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  13016. {
  13017. json_object *data;
  13018. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  13019. if(!is_error(data))
  13020. {
  13021. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  13022. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  13023. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  13024. {
  13025. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  13026. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  13027. else
  13028. {
  13029. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13030. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13031. }
  13032. }
  13033. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  13034. {
  13035. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  13036. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  13037. else
  13038. {
  13039. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13040. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13041. }
  13042. }
  13043. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  13044. {
  13045. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  13046. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  13047. else
  13048. {
  13049. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13050. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13051. }
  13052. }
  13053. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  13054. {
  13055. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  13056. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  13057. else
  13058. {
  13059. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13060. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13061. }
  13062. }
  13063. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  13064. {
  13065. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  13066. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  13067. else
  13068. {
  13069. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13070. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13071. }
  13072. }
  13073. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  13074. {
  13075. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  13076. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  13077. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  13078. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  13079. else
  13080. {
  13081. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13082. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13083. }
  13084. }
  13085. if(json_object_object_get(data, "isAuthentication") != NULL)
  13086. {
  13087. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  13088. {
  13089. case 0:
  13090. case 1:
  13091. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  13092. break;
  13093. default:
  13094. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13095. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13096. break;
  13097. }
  13098. }
  13099. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  13100. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13101. }
  13102. else
  13103. {
  13104. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13105. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13106. }
  13107. json_object_put(data);
  13108. }
  13109. else
  13110. {
  13111. // Can not find valid message id
  13112. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  13113. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  13114. ,ShmOCPP20Data->DataTransfer[0].vendorId
  13115. ,ShmOCPP20Data->DataTransfer[0].messageId
  13116. ,ShmOCPP20Data->DataTransfer[0].data);
  13117. }
  13118. }
  13119. else
  13120. {
  13121. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  13122. result = FAIL;
  13123. }
  13124. sendDataTransferConfirmation(uuid, 0);
  13125. return result;
  13126. }
  13127. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13128. {
  13129. mtrace();
  13130. int result = FAIL;
  13131. json_object *DeleteCertificate;
  13132. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13133. DeleteCertificate = json_tokener_parse(payload);
  13134. if(!is_error(DeleteCertificate))
  13135. {
  13136. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  13137. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  13138. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13139. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13140. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13141. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13142. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13143. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13144. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13145. DEBUG_INFO("serialNumber: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber);
  13146. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  13147. {
  13148. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  13149. }
  13150. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  13151. {
  13152. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  13153. }
  13154. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  13155. {
  13156. ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  13157. }
  13158. char temp[256] = {0};
  13159. char compareData[256] = {0};
  13160. int isMatch = TRUE;
  13161. // Check CentralSystemRootCertificate
  13162. if(access(ROOTCA_CS,F_OK) != -1)
  13163. {
  13164. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  13165. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  13166. for(int i = 0; compareData[i]; i++)
  13167. {
  13168. compareData[i] = tolower(compareData[i]);
  13169. }
  13170. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13171. isMatch = FALSE;
  13172. if(isMatch == TRUE)
  13173. {
  13174. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  13175. for(int i = 0; compareData[i]; i++)
  13176. {
  13177. compareData[i] = tolower(compareData[i]);
  13178. }
  13179. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13180. isMatch = FALSE;
  13181. }
  13182. if(isMatch == TRUE)
  13183. {
  13184. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  13185. for(int i = 0; compareData[i]; i++)
  13186. {
  13187. compareData[i] = tolower(compareData[i]);
  13188. }
  13189. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13190. isMatch = FALSE;
  13191. }
  13192. if(isMatch == TRUE)
  13193. {
  13194. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  13195. sprintf(temp, "rm -f %s", ROOTCA_CS);
  13196. system(temp);
  13197. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13198. goto End;
  13199. }
  13200. }
  13201. // Check ManufacturerRootCertificate
  13202. if(access(ROOTCA_MF,F_OK) != -1)
  13203. {
  13204. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  13205. isMatch = TRUE;
  13206. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  13207. for(int i = 0; compareData[i]; i++)
  13208. {
  13209. compareData[i] = tolower(compareData[i]);
  13210. }
  13211. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13212. isMatch = FALSE;
  13213. if(isMatch == TRUE)
  13214. {
  13215. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  13216. for(int i = 0; compareData[i]; i++)
  13217. {
  13218. compareData[i] = tolower(compareData[i]);
  13219. }
  13220. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13221. isMatch = FALSE;
  13222. }
  13223. if(isMatch == TRUE)
  13224. {
  13225. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  13226. for(int i = 0; compareData[i]; i++)
  13227. {
  13228. compareData[i] = tolower(compareData[i]);
  13229. }
  13230. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13231. isMatch = FALSE;
  13232. }
  13233. if(isMatch == TRUE)
  13234. {
  13235. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  13236. sprintf(temp, "rm -f %s", ROOTCA_MF);
  13237. system(temp);
  13238. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13239. goto End;
  13240. }
  13241. }
  13242. if(access(ROOTCA_V2G,F_OK) != -1)
  13243. {
  13244. DEBUG_INFO("Checking V2GRootCertificate...\n");
  13245. isMatch = TRUE;
  13246. parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, compareData);
  13247. for(int i = 0; compareData[i]; i++)
  13248. {
  13249. compareData[i] = tolower(compareData[i]);
  13250. }
  13251. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13252. isMatch = FALSE;
  13253. if(isMatch == TRUE)
  13254. {
  13255. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, compareData);
  13256. for(int i = 0; compareData[i]; i++)
  13257. {
  13258. compareData[i] = tolower(compareData[i]);
  13259. }
  13260. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13261. isMatch = FALSE;
  13262. }
  13263. if(isMatch == TRUE)
  13264. {
  13265. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  13266. for(int i = 0; compareData[i]; i++)
  13267. {
  13268. compareData[i] = tolower(compareData[i]);
  13269. }
  13270. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13271. isMatch = FALSE;
  13272. }
  13273. if(isMatch == TRUE)
  13274. {
  13275. DEBUG_INFO("Deleting V2GRootCertificate...\n");
  13276. sprintf(temp, "rm -f %s", ROOTCA_V2G);
  13277. system(temp);
  13278. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13279. goto End;
  13280. }
  13281. }
  13282. if(access(ROOTCA_MO,F_OK) != -1)
  13283. {
  13284. DEBUG_INFO("Checking MORootCertificate...\n");
  13285. isMatch = TRUE;
  13286. parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, compareData);
  13287. for(int i = 0; compareData[i]; i++)
  13288. {
  13289. compareData[i] = tolower(compareData[i]);
  13290. }
  13291. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13292. isMatch = FALSE;
  13293. if(isMatch == TRUE)
  13294. {
  13295. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, compareData);
  13296. for(int i = 0; compareData[i]; i++)
  13297. {
  13298. compareData[i] = tolower(compareData[i]);
  13299. }
  13300. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13301. isMatch = FALSE;
  13302. }
  13303. if(isMatch == TRUE)
  13304. {
  13305. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, compareData);
  13306. for(int i = 0; compareData[i]; i++)
  13307. {
  13308. compareData[i] = tolower(compareData[i]);
  13309. }
  13310. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13311. isMatch = FALSE;
  13312. }
  13313. if(isMatch == TRUE)
  13314. {
  13315. DEBUG_INFO("Deleting MORootCertificate...\n");
  13316. sprintf(temp, "rm -f %s", ROOTCA_MO);
  13317. system(temp);
  13318. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13319. goto End;
  13320. }
  13321. }
  13322. // Check certCP
  13323. if(access(CERTIFICATE_CP,F_OK) != -1)
  13324. {
  13325. DEBUG_INFO("Checking certCP...\n");
  13326. isMatch = TRUE;
  13327. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  13328. for(int i = 0; compareData[i]; i++)
  13329. {
  13330. compareData[i] = tolower(compareData[i]);
  13331. }
  13332. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13333. isMatch = FALSE;
  13334. if(isMatch == TRUE)
  13335. {
  13336. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  13337. for(int i = 0; compareData[i]; i++)
  13338. {
  13339. compareData[i] = tolower(compareData[i]);
  13340. }
  13341. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13342. isMatch = FALSE;
  13343. }
  13344. if(isMatch == TRUE)
  13345. {
  13346. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  13347. for(int i = 0; compareData[i]; i++)
  13348. {
  13349. compareData[i] = tolower(compareData[i]);
  13350. }
  13351. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13352. isMatch = FALSE;
  13353. }
  13354. if(isMatch == TRUE)
  13355. {
  13356. DEBUG_INFO("Deleting certCP...\n");
  13357. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  13358. system(temp);
  13359. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13360. goto End;
  13361. }
  13362. }
  13363. }
  13364. else
  13365. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  13366. End:
  13367. json_object_put(DeleteCertificate);
  13368. ShmOCPP20Data->MsMsg.bits.DeleteCertificateReq = 1;
  13369. sendDeleteCertificateConfirmation(uuid);
  13370. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13371. return result;
  13372. }
  13373. int handleGetBaseReportRequest(char *uuid, char *payload)
  13374. {
  13375. mtrace();
  13376. int result = FAIL;
  13377. json_object *GetBaseRepor;
  13378. DEBUG_INFO("handleGetBaseReportRequest...\n");
  13379. GetBaseRepor = json_tokener_parse(payload);
  13380. if(!is_error(GetBaseRepor))
  13381. {
  13382. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  13383. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  13384. // Required data
  13385. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  13386. {
  13387. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  13388. }
  13389. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  13390. {
  13391. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  13392. }
  13393. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  13394. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13395. else
  13396. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13397. }
  13398. else
  13399. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13400. json_object_put(GetBaseRepor);
  13401. sendGetBaseReportConfirmation(uuid);
  13402. return result;
  13403. }
  13404. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  13405. {
  13406. mtrace();
  13407. int result = FAIL;
  13408. int gun_index = -1;
  13409. json_object *GetChargingProfiles;
  13410. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  13411. GetChargingProfiles = json_tokener_parse(payload);
  13412. if(!is_error(GetChargingProfiles))
  13413. {
  13414. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  13415. {
  13416. 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;
  13417. }
  13418. if(gun_index >-1)
  13419. {
  13420. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  13421. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  13422. // Required data
  13423. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  13424. {
  13425. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  13426. }
  13427. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  13428. {
  13429. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  13430. {
  13431. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  13432. }
  13433. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  13434. {
  13435. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  13436. }
  13437. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  13438. {
  13439. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  13440. {
  13441. 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)));
  13442. }
  13443. }
  13444. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  13445. {
  13446. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  13447. {
  13448. 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));
  13449. }
  13450. }
  13451. }
  13452. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  13453. }
  13454. else
  13455. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  13456. }
  13457. json_object_put(GetChargingProfiles);
  13458. sendGetChargingProfilesConfirmation(uuid, gun_index);
  13459. return result;
  13460. }
  13461. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  13462. {
  13463. mtrace();
  13464. int result = FAIL;
  13465. int evseIdInt, durationInt;
  13466. char chargingRateUnitStr[4]={0};
  13467. char comfirmstr[20];
  13468. int confirmPeriods = 0;
  13469. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  13470. json_object *GetCompositeSchedule;
  13471. GetCompositeSchedule = json_tokener_parse(payload);
  13472. if(!is_error(GetCompositeSchedule))
  13473. {
  13474. // Required data
  13475. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  13476. evseIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  13477. else
  13478. evseIdInt = -1;
  13479. if(json_object_object_get(GetCompositeSchedule, "duration"))
  13480. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  13481. else
  13482. durationInt = 86400;
  13483. // Optional data
  13484. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  13485. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  13486. }
  13487. json_object_put(GetCompositeSchedule);
  13488. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  13489. if((evseIdInt == 0) ||
  13490. ((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber)))
  13491. {
  13492. int gun_index = (evseIdInt==0?0:evseIdInt-1);
  13493. struct ChargingProfileType tmpProfile[1];
  13494. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  13495. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  13496. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  13497. {
  13498. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  13499. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, FALSE);
  13500. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  13501. }
  13502. else
  13503. {
  13504. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  13505. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, TRUE);
  13506. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  13507. }
  13508. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13509. {
  13510. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  13511. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  13512. }
  13513. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct ChargingScheduleType));
  13514. strcpy((char *)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.startDateTime, (char *)tmpProfile[0].chargingSchedule[0].startSchedule);
  13515. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13516. {
  13517. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  13518. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  13519. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  13520. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  13521. (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))
  13522. {
  13523. confirmPeriods = idx;
  13524. break;
  13525. }
  13526. }
  13527. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  13528. {
  13529. confirmPeriods += 1;
  13530. }
  13531. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13532. }
  13533. else
  13534. {
  13535. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  13536. }
  13537. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, evseIdInt, confirmPeriods);
  13538. return result;
  13539. }
  13540. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  13541. {
  13542. mtrace();
  13543. int result = FAIL;
  13544. json_object *GetDisplayMessages;
  13545. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  13546. GetDisplayMessages = json_tokener_parse(payload);
  13547. if(!is_error(GetDisplayMessages))
  13548. {
  13549. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  13550. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  13551. // Required data
  13552. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  13553. {
  13554. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  13555. }
  13556. // Optional data
  13557. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  13558. {
  13559. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  13560. }
  13561. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  13562. {
  13563. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  13564. }
  13565. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  13566. {
  13567. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  13568. {
  13569. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  13570. }
  13571. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  13572. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  13573. }
  13574. else
  13575. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  13576. }
  13577. json_object_put(GetDisplayMessages);
  13578. return result;
  13579. }
  13580. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13581. {
  13582. mtrace();
  13583. int result = FAIL;
  13584. int certCnt = 0;
  13585. unsigned char foundCertCnt = 0;
  13586. json_object *GetInstalledCertificateIds;
  13587. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13588. GetInstalledCertificateIds = json_tokener_parse(payload);
  13589. if(!is_error(GetInstalledCertificateIds))
  13590. {
  13591. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  13592. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  13593. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13594. // Optional data
  13595. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  13596. {
  13597. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  13598. {
  13599. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  13600. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13601. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "Accepted");
  13602. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  13603. // Check CSMSRootCertificate
  13604. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "CSMSRootCertificate")!= NULL)
  13605. {
  13606. if(access(ROOTCA_CS,F_OK) != -1)
  13607. {
  13608. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "CSMSRootCertificate");
  13609. char parseData[512] = {0};
  13610. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13611. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13612. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  13613. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13614. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13615. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13616. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13617. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13618. certCnt++;
  13619. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13620. }
  13621. else
  13622. {
  13623. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  13624. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13625. }
  13626. }
  13627. // Check ManufacturerRootCertificate
  13628. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "ManufacturerRootCertificate") != NULL)
  13629. {
  13630. if(access(ROOTCA_MF,F_OK) != -1)
  13631. {
  13632. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "ManufacturerRootCertificate");
  13633. char parseData[512] = {0};
  13634. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13635. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13636. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  13637. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13638. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13639. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13640. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13641. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13642. certCnt++;
  13643. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13644. }
  13645. else
  13646. {
  13647. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  13648. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13649. }
  13650. }
  13651. // Check MORootCertificate
  13652. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "MORootCertificate") != NULL)
  13653. {
  13654. if(access(ROOTCA_MO,F_OK) != -1)
  13655. {
  13656. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "MORootCertificate");
  13657. char parseData[512] = {0};
  13658. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13659. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13660. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, parseData) == PASS)
  13661. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13662. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13663. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13664. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13665. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13666. certCnt++;
  13667. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13668. }
  13669. else
  13670. {
  13671. DEBUG_INFO(">>> No MORootCertificate was found.\n");
  13672. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13673. }
  13674. }
  13675. // Check V2GRootCertificate
  13676. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GRootCertificate") != NULL)
  13677. {
  13678. if(access(ROOTCA_V2G,F_OK) != -1)
  13679. {
  13680. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GRootCertificate");
  13681. char parseData[512] = {0};
  13682. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13683. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13684. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13685. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13686. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13687. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13688. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13689. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13690. certCnt++;
  13691. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13692. }
  13693. else
  13694. {
  13695. DEBUG_INFO(">>> No V2GRootCertificate was found.\n");
  13696. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13697. }
  13698. }
  13699. // Check V2GCertificateChain
  13700. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GCertificateChain") != NULL)
  13701. {
  13702. if(access(CERTIFICATE_V2G,F_OK) != -1)
  13703. {
  13704. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GCertificateChain");
  13705. char parseData[512] = {0};
  13706. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13707. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13708. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13709. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13710. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13711. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13712. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13713. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13714. certCnt++;
  13715. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13716. }
  13717. else
  13718. {
  13719. DEBUG_INFO(">>> No V2GCertificateChain was found.\n");
  13720. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13721. }
  13722. }
  13723. else
  13724. {
  13725. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13726. }
  13727. }
  13728. }
  13729. else
  13730. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13731. }
  13732. json_object_put(GetInstalledCertificateIds);
  13733. sendGetInstalledCertificateIdsConfirmation(uuid, foundCertCnt);
  13734. return result;
  13735. }
  13736. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  13737. {
  13738. mtrace();
  13739. int result = FAIL;
  13740. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  13741. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  13742. {
  13743. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  13744. localversion = 0;
  13745. }
  13746. else
  13747. {
  13748. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  13749. localversion = 0;
  13750. DB_getListVerion();
  13751. }
  13752. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  13753. sendGetLocalListVersionConfirmation(uuid);
  13754. return result;
  13755. }
  13756. static char fnamePlusPath[100]={0};
  13757. static char fnamePWithNoPath[60]={0};
  13758. void checkUploadLog(void)
  13759. {
  13760. FILE *fp;
  13761. /* Open the command for reading. */
  13762. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  13763. if (fp == NULL) {
  13764. printf("Failed to run command\n" );
  13765. exit(1);
  13766. }
  13767. int ftppathlen = 0;
  13768. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  13769. int i = 0;
  13770. /* Read the output a line at a time - output it. */
  13771. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  13772. if(i==0)
  13773. {
  13774. ftppathlen = strlen(fnamePlusPath);
  13775. printf("%s\n", fnamePlusPath);
  13776. fnamePlusPath[ftppathlen]='\0';
  13777. break;
  13778. }
  13779. i= i+1;
  13780. }
  13781. /* close */
  13782. pclose(fp);
  13783. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  13784. {
  13785. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  13786. {
  13787. fnamePlusPath[k]='\0';
  13788. }
  13789. }
  13790. i=1;
  13791. //char fname[60]={0};
  13792. while(i < ftppathlen)
  13793. {
  13794. int len=ftppathlen-i;
  13795. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  13796. {
  13797. printf("compare '/' all right\n");
  13798. break;
  13799. }
  13800. i=i+1;
  13801. }
  13802. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  13803. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  13804. fnamePWithNoPath[i+1] = '\0';
  13805. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  13806. {
  13807. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  13808. {
  13809. fnamePWithNoPath[j]='\0';
  13810. }
  13811. }
  13812. FILE* fp1 = fopen(fnamePlusPath, "r");
  13813. if (fp1)
  13814. {
  13815. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  13816. // file exists
  13817. fclose(fp1);
  13818. }
  13819. else
  13820. {
  13821. // file doesn't exist
  13822. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  13823. }
  13824. }
  13825. void* GetLogProcess(void* data)
  13826. {
  13827. th_GetLog = pthread_self();
  13828. pthread_detach(pthread_self());
  13829. mtrace();
  13830. int requestId, retriesInt=0, retryIntervalInt=0;
  13831. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  13832. 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};
  13833. int port=0;
  13834. int isSuccess = FALSE;
  13835. char ftpbuf[1024]={0};
  13836. char cmdBuf[2048];
  13837. struct tm *tmNow;
  13838. time_t CurrentTime;
  13839. struct tm tmStart;
  13840. struct tm tmStop;
  13841. CurrentTime = time(NULL);
  13842. tmNow=localtime(&CurrentTime);
  13843. uint16_t targetYear, targetMonth;
  13844. json_object *GetLog;
  13845. DEBUG_INFO("GetGetProcess...\n");
  13846. GetLog = json_tokener_parse(data);
  13847. if(!is_error(GetLog))
  13848. {
  13849. // Required data
  13850. if(json_object_object_get(GetLog, "requestId") != NULL)
  13851. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13852. if(json_object_object_get(GetLog, "logType") != NULL)
  13853. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13854. if(json_object_object_get(GetLog, "log") != NULL)
  13855. {
  13856. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  13857. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13858. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13859. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13860. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13861. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13862. }
  13863. // Optional data
  13864. if(json_object_object_get(GetLog, "retries") != NULL)
  13865. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13866. else
  13867. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  13868. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13869. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13870. else
  13871. retryIntervalInt = 30;
  13872. }
  13873. json_object_put(GetLog);
  13874. ShmOCPP20Data->GetLog.requestId = requestId;
  13875. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  13876. {
  13877. /*
  13878. * TODO:
  13879. * 1. Pack security log
  13880. */
  13881. }
  13882. else
  13883. {
  13884. // Pack log to compress file
  13885. 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) &&
  13886. (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))
  13887. {
  13888. // Pack system log
  13889. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13890. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13891. targetYear = tmStart.tm_year;
  13892. targetMonth = tmStart.tm_mon;
  13893. do
  13894. {
  13895. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13896. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13897. if(targetMonth+1>=13)
  13898. {
  13899. targetYear += 1;
  13900. targetMonth = 1;
  13901. }
  13902. else
  13903. {
  13904. targetMonth += 1;
  13905. }
  13906. }while((targetYear < (tmNow->tm_year+1900)) ||
  13907. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13908. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13909. system(cmdBuf);
  13910. // Pack charging & event log
  13911. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13912. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13913. targetYear = tmStart.tm_year;
  13914. targetMonth = tmStart.tm_mon;
  13915. do
  13916. {
  13917. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13918. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  13919. if(targetMonth+1>=13)
  13920. {
  13921. targetYear += 1;
  13922. targetMonth = 1;
  13923. }
  13924. else
  13925. {
  13926. targetMonth += 1;
  13927. }
  13928. }while((targetYear < (tmNow->tm_year+1900)) ||
  13929. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13930. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13931. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13932. system(cmdBuf);
  13933. // Combine log file
  13934. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13935. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13936. }
  13937. else
  13938. {
  13939. system("exec /root/logPackTools 'log' 6");
  13940. }
  13941. }
  13942. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13943. system(cmdBuf);
  13944. checkUploadLog();
  13945. //****************location*******************/
  13946. if(strcmp(remoteLocation,"")==0)
  13947. {
  13948. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13949. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13950. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13951. goto end;
  13952. }
  13953. memset(protocol, 0, ARRAY_SIZE(protocol));
  13954. memset(user, 0, ARRAY_SIZE(user) );
  13955. memset(password, 0, ARRAY_SIZE(password));
  13956. memset(host, 0, ARRAY_SIZE(host));
  13957. memset(path, 0, ARRAY_SIZE(path));
  13958. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13959. memset(host1, 0, ARRAY_SIZE(host1));
  13960. memset(path1, 0, ARRAY_SIZE(path1));
  13961. /*location: ftp://user:password@host:port/path*/
  13962. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13963. if((access(fnamePlusPath,F_OK))!=-1)
  13964. {
  13965. DEBUG_INFO("fnamePlusPath exist.\n");
  13966. }
  13967. else
  13968. {
  13969. DEBUG_INFO("fnamePlusPath not exist!\n");
  13970. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13971. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13972. goto end;
  13973. }
  13974. if(strchr(remoteLocation,'@')==NULL)
  13975. {
  13976. sscanf(remoteLocation,
  13977. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13978. protocol, host, &port, path);
  13979. strcpy(user,"anonymous");
  13980. strcpy(password,"");
  13981. }
  13982. else
  13983. {
  13984. //DEBUG_INFO("pch=%s\n", pch);
  13985. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13986. protocol, user, password, host, &port, path);
  13987. }
  13988. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13989. {
  13990. DEBUG_INFO("protocol is not ftp/http ! \n");
  13991. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13992. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13993. goto end;
  13994. }
  13995. if(strncmp(remoteLocation,"http", 4) == 0)
  13996. {
  13997. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13998. sprintf(ftppath,"/%s", path);
  13999. do
  14000. {
  14001. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  14002. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14003. sleep(3);
  14004. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  14005. if(!isSuccess)
  14006. {
  14007. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  14008. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  14009. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14010. sleep(retryIntervalInt);
  14011. }
  14012. else
  14013. {
  14014. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  14015. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  14016. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14017. }
  14018. retriesInt--;
  14019. }while((isSuccess == 0)&&(retriesInt >= 0));
  14020. }
  14021. else
  14022. {
  14023. sscanf(host,"%[^/]%s",host1, path1);
  14024. if(strlen(path) > 0)
  14025. sprintf(ftppath,"/%s", path);
  14026. else
  14027. sprintf(ftppath,"/%s", path1);
  14028. int ftppathlen=strlen(ftppath);
  14029. int i=1;
  14030. char filenametemp[50];
  14031. while(i < ftppathlen)
  14032. {
  14033. int len=ftppathlen-i;
  14034. if(ftppath[len]== 47) // '/' ascll code: 47
  14035. {
  14036. DEBUG_INFO("find '/' all right\n");
  14037. break;
  14038. }
  14039. i=i+1;
  14040. }
  14041. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14042. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14043. filenametemp[i+1] = 0;
  14044. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14045. if(port == 0)
  14046. port = 21;
  14047. do
  14048. {
  14049. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  14050. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14051. sleep(3);
  14052. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14053. if(!isSuccess)
  14054. {
  14055. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  14056. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  14057. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14058. sleep(retryIntervalInt);
  14059. }
  14060. else
  14061. {
  14062. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  14063. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  14064. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14065. }
  14066. retriesInt--;
  14067. }while((!isSuccess)&&(retriesInt >= 0));
  14068. }
  14069. end:
  14070. system("rm -f /mnt/*");
  14071. sleep(5);
  14072. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  14073. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14074. interLock.isGetLogGoing = OFF;
  14075. pthread_exit(NULL);
  14076. }
  14077. int handleGetLogRequest(char *uuid, char *payload)
  14078. {
  14079. mtrace();
  14080. int result = FAIL;
  14081. char fName[258];
  14082. time_t CurrentTime;
  14083. struct tm *tm;
  14084. pthread_t th_Status;
  14085. DEBUG_INFO("handleGetLogRequest...\n");
  14086. CurrentTime = time(NULL);
  14087. tm = localtime(&CurrentTime);
  14088. 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);
  14089. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  14090. if(interLock.isGetLogGoing)
  14091. {
  14092. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  14093. isCancelUploadLog = TRUE;
  14094. pthread_cancel(th_GetLog);
  14095. interLock.isGetLogGoing = OFF;
  14096. sleep(1);
  14097. isCancelUploadLog = OFF;
  14098. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_AcceptedCanceled]);
  14099. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14100. sleep(1);
  14101. }
  14102. else
  14103. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  14104. sendGetLogConfirmation(uuid);
  14105. if(!interLock.isGetLogGoing)
  14106. {
  14107. interLock.isGetLogGoing = ON;
  14108. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14109. sleep(1);
  14110. }
  14111. else
  14112. {
  14113. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14114. }
  14115. return result;
  14116. }
  14117. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  14118. {
  14119. mtrace();
  14120. int result = FAIL;
  14121. uint8_t cntCriteria = 0;
  14122. int cntComponentVariable = 0;
  14123. uint8_t cntFoundMonitoringVariable = 0;
  14124. json_object *GetMonitoringReport;
  14125. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  14126. GetMonitoringReport = json_tokener_parse(payload);
  14127. if(!is_error(GetMonitoringReport))
  14128. {
  14129. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  14130. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  14131. // Required data
  14132. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  14133. {
  14134. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  14135. }
  14136. // Optional data
  14137. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  14138. {
  14139. cntCriteria = json_object_array_length(json_object_object_get(GetMonitoringReport, "monitoringCriteria"));
  14140. for(int idx=0; idx<cntCriteria; idx++)
  14141. {
  14142. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx], "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  14143. }
  14144. }
  14145. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  14146. {
  14147. cntComponentVariable = json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));
  14148. if(cntComponentVariable <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  14149. {
  14150. for(int idx=0;idx<cntComponentVariable;idx++)
  14151. {
  14152. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  14153. {
  14154. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  14155. {
  14156. 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")));
  14157. }
  14158. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  14159. {
  14160. 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")));
  14161. }
  14162. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14163. {
  14164. 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)
  14165. {
  14166. 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"));
  14167. }
  14168. 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)
  14169. {
  14170. 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"));
  14171. }
  14172. }
  14173. }
  14174. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  14175. {
  14176. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14177. {
  14178. 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")));
  14179. }
  14180. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14181. {
  14182. 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")));
  14183. }
  14184. }
  14185. }
  14186. }
  14187. }
  14188. }
  14189. json_object_put(GetMonitoringReport);
  14190. //strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  14191. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_EmptyResultSet]);
  14192. if(cntComponentVariable>0)
  14193. {
  14194. uint8_t cntTypeSupport = 0;
  14195. for(int idx_cv=0; idx_cv < cntComponentVariable; idx_cv++)
  14196. {
  14197. cntTypeSupport = 0;
  14198. for(int idx=0; idx < 10; idx++)
  14199. {
  14200. if((strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx_cv].component.name)==0) &&
  14201. (strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx_cv].variable.name)==0))
  14202. {
  14203. if(strlen((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[0]) > 0)
  14204. {
  14205. for(int idx_cri=0; idx_cri<cntCriteria; idx_cri++)
  14206. {
  14207. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  14208. {
  14209. if(strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "Threshold") != NULL)
  14210. {
  14211. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14212. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14213. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14214. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14215. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14216. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14217. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14218. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14219. cntTypeSupport++;
  14220. break;
  14221. }
  14222. }
  14223. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  14224. {
  14225. if(strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "Delta") != NULL)
  14226. {
  14227. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14228. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14229. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14230. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14231. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14232. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14233. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14234. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14235. cntTypeSupport++;
  14236. break;
  14237. }
  14238. }
  14239. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  14240. {
  14241. if(strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "Periodic") != NULL)
  14242. {
  14243. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14244. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14245. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14246. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14247. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14248. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14249. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14250. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14251. cntTypeSupport++;
  14252. break;
  14253. }
  14254. }
  14255. }
  14256. }
  14257. else
  14258. {
  14259. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14260. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14261. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14262. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14263. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14264. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14265. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14266. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14267. cntTypeSupport++;
  14268. }
  14269. cntFoundMonitoringVariable++;
  14270. }
  14271. }
  14272. }
  14273. }
  14274. else
  14275. {
  14276. for(int idx=0; idx < 10; idx++)
  14277. {
  14278. if(strlen((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[0]) > 0)
  14279. {
  14280. if((strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name)>0) && (strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name)>0))
  14281. {
  14282. int isSameVariableFound = FALSE;
  14283. for(int idx_cri=0; idx_cri<cntCriteria; idx_cri++)
  14284. {
  14285. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  14286. {
  14287. if(strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "Threshold") != NULL)
  14288. {
  14289. for(int idx_cv=0; idx_cv < 10; idx_cv++)
  14290. {
  14291. if((strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name)>0) && (strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name)>0))
  14292. {
  14293. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name) != NULL) &&
  14294. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name) != NULL))
  14295. {
  14296. isSameVariableFound = TRUE;
  14297. for(int idx_vm=1; idx_vm < 10; idx_vm++)
  14298. {
  14299. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type) == 0)
  14300. {
  14301. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14302. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14303. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14304. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14305. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14306. }
  14307. }
  14308. break;
  14309. }
  14310. }
  14311. else
  14312. {
  14313. if(isSameVariableFound==FALSE)
  14314. {
  14315. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14316. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14317. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14318. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14319. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14320. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14321. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14322. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14323. }
  14324. break;
  14325. }
  14326. }
  14327. break;
  14328. }
  14329. }
  14330. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  14331. {
  14332. if(strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "Delta") != NULL)
  14333. {
  14334. for(int idx_cv=0; idx_cv < 10; idx_cv++)
  14335. {
  14336. if((strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name)>0) && (strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name)>0))
  14337. {
  14338. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name) != NULL) &&
  14339. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name) != NULL))
  14340. {
  14341. isSameVariableFound = TRUE;
  14342. for(int idx_vm=1; idx_vm < 10; idx_vm++)
  14343. {
  14344. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type) == 0)
  14345. {
  14346. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14347. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14348. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14349. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14350. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14351. }
  14352. }
  14353. break;
  14354. }
  14355. }
  14356. else
  14357. {
  14358. if(isSameVariableFound==FALSE)
  14359. {
  14360. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14361. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14362. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14363. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14364. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14365. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14366. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14367. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14368. }
  14369. break;
  14370. }
  14371. }
  14372. break;
  14373. }
  14374. }
  14375. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  14376. {
  14377. if(strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "Periodic") != NULL)
  14378. {
  14379. for(int idx_cv=0; idx_cv < 10; idx_cv++)
  14380. {
  14381. if((strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name)>0) && (strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name)>0))
  14382. {
  14383. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name) != NULL) &&
  14384. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name) != NULL))
  14385. {
  14386. isSameVariableFound = TRUE;
  14387. for(int idx_vm=1; idx_vm < 10; idx_vm++)
  14388. {
  14389. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type) == 0)
  14390. {
  14391. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14392. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14393. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14394. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14395. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14396. }
  14397. }
  14398. break;
  14399. }
  14400. }
  14401. else
  14402. {
  14403. if(isSameVariableFound==FALSE)
  14404. {
  14405. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14406. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14407. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14408. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14409. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14410. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14411. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14412. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14413. }
  14414. break;
  14415. }
  14416. }
  14417. break;
  14418. }
  14419. }
  14420. }
  14421. }
  14422. }
  14423. else
  14424. {
  14425. if((strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name)>0) && (strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name)>0))
  14426. {
  14427. int isSameVariableFound = FALSE;
  14428. for(int idx_cv=0; idx_cv < 10; idx_cv++)
  14429. {
  14430. if((strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name)>0) && (strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name)>0))
  14431. {
  14432. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component.name) != NULL) &&
  14433. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable.name) != NULL))
  14434. {
  14435. isSameVariableFound = TRUE;
  14436. for(int idx_vm=1; idx_vm < 10; idx_vm++)
  14437. {
  14438. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type) == 0)
  14439. {
  14440. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14441. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14442. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14443. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14444. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[idx_vm].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14445. }
  14446. }
  14447. }
  14448. }
  14449. else
  14450. {
  14451. if(isSameVariableFound==FALSE)
  14452. {
  14453. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14454. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14455. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14456. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14457. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14458. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14459. ShmOCPP20Data->NotifyMonitoringReport.monitor[idx_cv].variableMonitoring[0].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14460. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14461. }
  14462. }
  14463. }
  14464. }
  14465. }
  14466. cntFoundMonitoringVariable++;
  14467. }
  14468. }
  14469. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]) != 0)
  14470. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  14471. sendGetMonitoringReportConfirmation(uuid);
  14472. return result;
  14473. }
  14474. int handleGetReportRequest(char *uuid, char *payload)
  14475. {
  14476. mtrace();
  14477. int result = FAIL;
  14478. json_object *GetReport;
  14479. DEBUG_INFO("handleGetReportRequest...\n");
  14480. GetReport = json_tokener_parse(payload);
  14481. if(!is_error(GetReport))
  14482. {
  14483. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  14484. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  14485. // Required data
  14486. if(json_object_object_get(GetReport, "requestId") != NULL)
  14487. {
  14488. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  14489. }
  14490. // Optional data
  14491. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  14492. {
  14493. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  14494. }
  14495. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  14496. {
  14497. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  14498. {
  14499. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  14500. {
  14501. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  14502. {
  14503. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  14504. {
  14505. 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")));
  14506. }
  14507. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  14508. {
  14509. 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")));
  14510. }
  14511. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14512. {
  14513. 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)
  14514. {
  14515. 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"));
  14516. }
  14517. 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)
  14518. {
  14519. 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"));
  14520. }
  14521. }
  14522. }
  14523. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  14524. {
  14525. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14526. {
  14527. 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")));
  14528. }
  14529. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14530. {
  14531. 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")));
  14532. }
  14533. }
  14534. }
  14535. }
  14536. }
  14537. }
  14538. json_object_put(GetReport);
  14539. /*
  14540. * TODO:
  14541. * 1. Response result
  14542. */
  14543. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14544. sendGetReportConfirmation(uuid);
  14545. return result;
  14546. }
  14547. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  14548. {
  14549. mtrace();
  14550. int result = FAIL;
  14551. uint8_t tempIndex;
  14552. json_object *GetTransactionStatus;
  14553. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  14554. GetTransactionStatus = json_tokener_parse(payload);
  14555. if(!is_error(GetTransactionStatus))
  14556. {
  14557. memset(&ShmOCPP20Data->GetTransactionStatus, 0, sizeof(struct GetTransactionStatus_20));
  14558. memcpy(&ShmOCPP20Data->GetTransactionStatus.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus.guid));
  14559. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = FALSE;
  14560. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = FALSE;
  14561. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  14562. {
  14563. sprintf((char*)ShmOCPP20Data->GetTransactionStatus.transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  14564. }
  14565. if(strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId)>0)
  14566. {
  14567. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14568. {
  14569. if(strcmp((char*)ShmOCPP20Data->GetTransactionStatus.transactionId, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId)==0)
  14570. {
  14571. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14572. {
  14573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14574. tempIndex = ((gun_index==2) ? 1: 0);
  14575. else
  14576. tempIndex = gun_index;
  14577. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14578. {
  14579. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) &&
  14580. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14581. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14582. }
  14583. }
  14584. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14585. {
  14586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14587. tempIndex = ((gun_index==2) ? 1: 0);
  14588. else
  14589. tempIndex = gun_index;
  14590. for (int index = 0; index < CCS_QUANTITY; index++)
  14591. {
  14592. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) &&
  14593. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14594. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14595. }
  14596. }
  14597. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14598. {
  14599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14600. tempIndex = ((gun_index==2) ? 1: 0);
  14601. else
  14602. tempIndex = gun_index;
  14603. for (int index = 0; index < GB_QUANTITY; index++)
  14604. {
  14605. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) &&
  14606. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14607. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14608. }
  14609. }
  14610. else if(gunType[gun_index] == GUN_TYPE_DO)
  14611. {
  14612. tempIndex = gun_index;
  14613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14614. {
  14615. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) &&
  14616. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)))
  14617. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14618. }
  14619. }
  14620. else
  14621. {
  14622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14623. tempIndex = 2;
  14624. else
  14625. tempIndex = gun_index;
  14626. for (int index = 0; index < AC_QUANTITY; index++)
  14627. {
  14628. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) &&
  14629. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14630. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14631. }
  14632. }
  14633. }
  14634. }
  14635. }
  14636. char rmFileCmd[100]={0};
  14637. int TransactionQueueNum = 0;
  14638. struct stat stats;
  14639. stat("/Storage/OCPP", &stats);
  14640. // Check for directory existence
  14641. if (S_ISDIR(stats.st_mode) == 1)
  14642. {
  14643. //DEBUG_INFO("\n OCPP directory exist \n");
  14644. }
  14645. else
  14646. {
  14647. //DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  14648. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  14649. system(rmFileCmd);
  14650. }
  14651. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  14652. if((access("/Storage/OCPP/TransactionRelatedQueue20",F_OK))!=-1)
  14653. {
  14654. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14655. }
  14656. else
  14657. {
  14658. FILE *fp = fopen("/Storage/OCPP/TransactionRelatedQueue20", "r");
  14659. char line[QUEUE_MESSAGE_LENGTH]={0};
  14660. if (fp == NULL) {
  14661. DEBUG_INFO("cannot open file TransactionRelatedQueue!");
  14662. }
  14663. TransactionQueueNum = 0; // the number of packets in queue
  14664. while(fgets(line, sizeof line, fp) != NULL) {
  14665. if(strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId)>0)
  14666. {
  14667. if(strstr(line, (char*)ShmOCPP20Data->GetTransactionStatus.transactionId) != NULL)
  14668. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = TRUE;
  14669. }
  14670. TransactionQueueNum += 1; //the number of packets in queue
  14671. }
  14672. fclose(fp);
  14673. }
  14674. if((strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId) == 0) && (TransactionQueueNum>0))
  14675. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = TRUE;
  14676. }
  14677. json_object_put(GetTransactionStatus);
  14678. sendGetTransactionStatusConfirmation(uuid);
  14679. return result;
  14680. }
  14681. int handleGetVariablesRequest(char *uuid, char *payload)
  14682. {
  14683. mtrace();
  14684. int result = FAIL;
  14685. int isUnknownComponent = TRUE;
  14686. json_object *GetVariables;
  14687. DEBUG_INFO("handleGetVariablesRequest...\n");
  14688. GetVariables = json_tokener_parse(payload);
  14689. if(!is_error(GetVariables))
  14690. {
  14691. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  14692. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  14693. // Required data
  14694. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  14695. {
  14696. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  14697. {
  14698. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  14699. {
  14700. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  14701. {
  14702. 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")));
  14703. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  14704. }
  14705. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  14706. {
  14707. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  14708. }*/
  14709. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  14710. {
  14711. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  14712. {
  14713. 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")));
  14714. }
  14715. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  14716. {
  14717. 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")));
  14718. }
  14719. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  14720. {
  14721. 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)
  14722. {
  14723. 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"));
  14724. }
  14725. 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)
  14726. {
  14727. 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"));
  14728. }
  14729. }
  14730. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  14731. }
  14732. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  14733. {
  14734. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  14735. {
  14736. 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")));
  14737. }
  14738. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  14739. {
  14740. 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")));
  14741. }
  14742. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  14743. }
  14744. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  14745. {
  14746. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  14747. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  14748. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  14749. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  14750. {
  14751. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  14752. isUnknownComponent = FALSE;
  14753. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  14754. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  14755. {
  14756. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  14757. break;
  14758. }
  14759. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14760. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  14761. {
  14762. struct sysinfo s_info;
  14763. int error = sysinfo(&s_info);
  14764. if(error != 0)
  14765. {
  14766. DEBUG_WARN("System uptime get error: %d\n", error);
  14767. }
  14768. else
  14769. {
  14770. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  14771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  14772. }
  14773. }
  14774. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14775. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  14776. {
  14777. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  14778. }
  14779. else
  14780. {
  14781. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  14782. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  14783. }
  14784. break;
  14785. }
  14786. else
  14787. {
  14788. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  14789. {
  14790. isUnknownComponent = FALSE;
  14791. }
  14792. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  14793. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  14794. }
  14795. }
  14796. if(isUnknownComponent == TRUE)
  14797. {
  14798. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  14799. }
  14800. }
  14801. }
  14802. }
  14803. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  14804. }
  14805. json_object_put(GetVariables);
  14806. return result;
  14807. }
  14808. int handleInstallCertificateRequest(char *uuid, char *payload)
  14809. {
  14810. mtrace();
  14811. int result = PASS;
  14812. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14813. json_object *InstallCertificate;
  14814. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14815. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14816. InstallCertificate = json_tokener_parse(payload);
  14817. if(!is_error(InstallCertificate))
  14818. {
  14819. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  14820. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  14821. // Required data
  14822. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  14823. {
  14824. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14825. }
  14826. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  14827. {
  14828. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14829. }
  14830. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificateType);
  14831. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificate);
  14832. char temp[1024];
  14833. FILE *fp = fopen(tempCert, "w");
  14834. fprintf(fp, "%s", ShmOCPP20Data->InstallCertificate.certificate);
  14835. fclose(fp);
  14836. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14837. char strExpDate[30];
  14838. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14839. fp = popen(temp, "r");
  14840. if(fp)
  14841. {
  14842. while(fgets(temp, sizeof(temp), fp) != NULL)
  14843. {
  14844. if(strstr(temp, "notAfter=") != NULL)
  14845. {
  14846. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14847. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14848. break;
  14849. }
  14850. }
  14851. }
  14852. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14853. struct tm tmExpDate;
  14854. struct timeb tbExpDate;
  14855. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14856. tbExpDate.time = mktime(&tmExpDate);
  14857. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14858. {
  14859. DEBUG_INFO("The enddate is already expired...\n");
  14860. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14861. goto End;
  14862. }
  14863. // Verify certificate with rootCA
  14864. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14865. fp = popen(temp, "r");
  14866. if(fp)
  14867. {
  14868. while(fgets(temp, sizeof(temp), fp) != NULL)
  14869. {
  14870. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14871. {
  14872. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14873. break;
  14874. }
  14875. else
  14876. {
  14877. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14878. }
  14879. }
  14880. }
  14881. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14882. {
  14883. //=====================================================
  14884. // Verify if the certificate is valid or not. (OCSP?)
  14885. //=====================================================
  14886. /*
  14887. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14888. // Get ocsp url
  14889. char ocspUrl[512];
  14890. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14891. fp = popen(temp, "r");
  14892. if(fp)
  14893. {
  14894. while(fgets(temp, sizeof(temp), fp) != NULL)
  14895. {
  14896. if(strstr(temp, "://") != NULL)
  14897. {
  14898. strcpy(ocspUrl, temp);
  14899. break;
  14900. }
  14901. }
  14902. }
  14903. // Get certificate chain for issuer
  14904. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14905. *
  14906. // Execute OCSP
  14907. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14908. fp = popen(temp, "r");
  14909. if(fp)
  14910. {
  14911. while(fgets(temp, sizeof(temp), fp) != NULL)
  14912. {
  14913. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14914. {
  14915. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14916. break;
  14917. }
  14918. }
  14919. }
  14920. system("rm -f /Storage/OCPP/tempChain.pem");
  14921. pclose(fp);
  14922. */
  14923. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14924. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14925. {
  14926. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14927. goto End;
  14928. }
  14929. else
  14930. DEBUG_INFO("OCSP verifying...PASS.\n");
  14931. }
  14932. else
  14933. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14934. }
  14935. json_object_put(InstallCertificate);
  14936. End:
  14937. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") == 0)
  14938. {
  14939. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]) == 0)
  14940. {
  14941. if(access(ROOTCA_CS,F_OK) != -1)
  14942. {
  14943. DEBUG_INFO("Existed CSMSRootCertificate is found. Replacing...\n");
  14944. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14945. rename(tempCert, ROOTCA_CS);
  14946. }
  14947. else
  14948. {
  14949. DEBUG_INFO("No existed CSMSRootCertificate Creating...\n");
  14950. rename(tempCert, ROOTCA_CS);
  14951. }
  14952. }
  14953. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]) == 0)
  14954. {
  14955. if(access(ROOTCA_MF,F_OK) != -1)
  14956. {
  14957. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14958. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14959. rename(tempCert, ROOTCA_MF);
  14960. }
  14961. else
  14962. {
  14963. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14964. rename(tempCert, ROOTCA_MF);
  14965. }
  14966. }
  14967. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]) == 0)
  14968. {
  14969. if(access(ROOTCA_V2G,F_OK) != -1)
  14970. {
  14971. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14972. rename(ROOTCA_V2G, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14973. rename(tempCert, ROOTCA_V2G);
  14974. }
  14975. else
  14976. {
  14977. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14978. rename(tempCert, ROOTCA_V2G);
  14979. }
  14980. }
  14981. ShmOCPP20Data->MsMsg.bits.InstallCertificateReq = 1;
  14982. }
  14983. sendInstallCertificateConfirmation(uuid);
  14984. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14985. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14986. {
  14987. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14988. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  14989. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14990. }
  14991. return result;
  14992. }
  14993. int handlePublishFirmwareRequest(char *uuid, char *payload)
  14994. {
  14995. mtrace();
  14996. int result = FAIL;
  14997. json_object *PublishFirmware;
  14998. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  14999. PublishFirmware = json_tokener_parse(payload);
  15000. if(!is_error(PublishFirmware))
  15001. {
  15002. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  15003. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  15004. // Required data
  15005. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  15006. {
  15007. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  15008. }
  15009. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  15010. {
  15011. sprintf((char*)ShmOCPP20Data->PublishFirmware.checksum, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  15012. }
  15013. // Optional data
  15014. if(json_object_object_get(PublishFirmware, "location") != NULL)
  15015. {
  15016. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  15017. }
  15018. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  15019. {
  15020. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  15021. }
  15022. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  15023. {
  15024. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  15025. }
  15026. }
  15027. json_object_put(PublishFirmware);
  15028. /*
  15029. * TODO:
  15030. * 1. Publish firmware preocess and response
  15031. */
  15032. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  15033. sendPublishFirmwareConfirmation(uuid);
  15034. return result;
  15035. }
  15036. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  15037. {
  15038. mtrace();
  15039. int result = FAIL;
  15040. int8_t evseId = -1;
  15041. uint8_t tempIndex;
  15042. uint8_t isOverConnectorMax = FALSE;
  15043. uint8_t isPeriodOverMax = FALSE;
  15044. uint8_t isTxProfile = TRUE;
  15045. uint8_t isAllowStart = TRUE;
  15046. uint8_t filename[128]={0};
  15047. char cmdBuf[128];
  15048. FILE *filePtr;
  15049. json_object *RemoteStartTransaction;
  15050. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  15051. RemoteStartTransaction = json_tokener_parse(payload);
  15052. if(!is_error(RemoteStartTransaction))
  15053. {
  15054. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  15055. {
  15056. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  15057. {
  15058. evseId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  15059. }
  15060. else
  15061. {
  15062. isOverConnectorMax = TRUE;
  15063. DEBUG_WARN("Evse id shall not equal 0 and should be less than gunTotalNumber.\n");
  15064. }
  15065. }
  15066. else
  15067. {
  15068. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15069. {
  15070. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  15071. {
  15072. evseId = (idx+1);
  15073. DEBUG_INFO("Remote start without evseId but detect connector of evse-%02d connected ready to start.\n", evseId);
  15074. break;
  15075. }
  15076. }
  15077. }
  15078. if(isOverConnectorMax == FALSE)
  15079. {
  15080. if(evseId > 0)
  15081. {
  15082. DEBUG_INFO("Requested evseId id: %d\n", evseId);
  15083. memset(&ShmOCPP20Data->RequestStartTransaction[evseId-1], 0, sizeof(struct RequestStartTransaction_20));
  15084. memcpy(&ShmOCPP20Data->RequestStartTransaction[evseId-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[evseId-1].guid));
  15085. // Required data
  15086. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  15087. {
  15088. ShmOCPP20Data->RequestStartTransaction[evseId-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  15089. }
  15090. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  15091. {
  15092. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  15093. {
  15094. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  15095. }
  15096. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  15097. {
  15098. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  15099. }
  15100. }
  15101. // Optional data
  15102. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  15103. {
  15104. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  15105. {
  15106. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  15107. }
  15108. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  15109. {
  15110. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  15111. }
  15112. }
  15113. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  15114. {
  15115. // Check periods is over max configuration
  15116. 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))
  15117. {
  15118. isPeriodOverMax = TRUE;
  15119. }
  15120. // Check profile purpose is TxProfile
  15121. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15122. {
  15123. ShmOCPP20Data->RequestStartTransaction[evseId-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  15124. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  15125. }
  15126. else
  15127. {
  15128. isTxProfile = FALSE;
  15129. }
  15130. }
  15131. //check Transaction active
  15132. if(gunType[evseId-1] == GUN_TYPE_CHAdeMO)
  15133. {
  15134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15135. {
  15136. tempIndex = ((evseId-1) == 2) ? 1: 0;
  15137. }
  15138. else
  15139. {
  15140. tempIndex = (evseId-1);
  15141. }
  15142. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15143. {
  15144. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  15145. {
  15146. 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))
  15147. {
  15148. //Reserved
  15149. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  15150. }
  15151. 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))
  15152. {
  15153. //Reserved
  15154. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  15155. isAllowStart = FALSE;
  15156. }
  15157. else
  15158. {
  15159. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15160. {
  15161. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  15162. isAllowStart = FALSE;
  15163. }
  15164. }//END FOR ELSE
  15165. }
  15166. }// END FOR CHAdeMO_QUANTITY
  15167. }
  15168. else if(gunType[evseId-1] == GUN_TYPE_CCS)
  15169. {
  15170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15171. {
  15172. tempIndex = ((evseId-1) == 2) ? 1: 0;
  15173. }
  15174. else
  15175. {
  15176. tempIndex = (evseId-1);
  15177. }
  15178. for (int index = 0; index < CCS_QUANTITY; index++)
  15179. {
  15180. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15181. {
  15182. 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))
  15183. {
  15184. //Reserved
  15185. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  15186. }
  15187. 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))
  15188. {
  15189. //Reserved
  15190. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  15191. isAllowStart = FALSE;
  15192. }
  15193. else
  15194. {
  15195. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15196. {
  15197. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  15198. isAllowStart = FALSE;
  15199. }
  15200. }// END FOR ELSE
  15201. }
  15202. }// END FOR CCS_QUANTITY
  15203. }
  15204. else if(gunType[evseId-1] == GUN_TYPE_GBT)
  15205. {
  15206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15207. {
  15208. tempIndex = ((evseId-1) == 2) ? 1: 0;
  15209. }
  15210. else
  15211. {
  15212. tempIndex = (evseId-1);
  15213. }
  15214. for (int index = 0; index < GB_QUANTITY; index++)
  15215. {
  15216. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  15217. {
  15218. 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))
  15219. {
  15220. //Reserved
  15221. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  15222. }
  15223. 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))
  15224. {
  15225. //Reserved
  15226. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  15227. isAllowStart = FALSE;
  15228. }
  15229. else
  15230. {
  15231. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15232. {
  15233. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  15234. isAllowStart = FALSE;
  15235. }
  15236. }// END FOR ELSE
  15237. }
  15238. } // END FOR GB_QUANTITY
  15239. }
  15240. else if(gunType[evseId-1] == GUN_TYPE_DO)
  15241. {
  15242. tempIndex = (evseId-1);
  15243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15244. {
  15245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  15246. {
  15247. 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))
  15248. {
  15249. //Reserved
  15250. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  15251. }
  15252. 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))
  15253. {
  15254. //Reserved
  15255. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  15256. isAllowStart = FALSE;
  15257. }
  15258. else
  15259. {
  15260. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15261. {
  15262. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  15263. isAllowStart = FALSE;
  15264. }
  15265. }// END FOR ELSE
  15266. }
  15267. } // END FOR GB_QUANTITY
  15268. }
  15269. else
  15270. {
  15271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15272. {
  15273. tempIndex = 2;
  15274. }
  15275. else
  15276. {
  15277. tempIndex = (evseId-1);
  15278. }
  15279. for (int index = 0; index < AC_QUANTITY; index++)
  15280. {
  15281. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  15282. {
  15283. 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))
  15284. {
  15285. //Reserved
  15286. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  15287. }
  15288. 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))
  15289. {
  15290. //Reserved
  15291. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  15292. isAllowStart = FALSE;
  15293. }
  15294. else
  15295. {
  15296. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15297. {
  15298. DEBUG_WARN("AC connector not allow start cause busy.\n");
  15299. isAllowStart = FALSE;
  15300. }
  15301. }//END FOR ELSE
  15302. }
  15303. }// END FOR AC_QUANTITY
  15304. }
  15305. }
  15306. else
  15307. {
  15308. DEBUG_INFO("Connector id does not specific.\n");
  15309. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15310. {
  15311. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  15312. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  15313. // Required data
  15314. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  15315. {
  15316. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  15317. }
  15318. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  15319. {
  15320. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  15321. {
  15322. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  15323. }
  15324. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  15325. {
  15326. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  15327. }
  15328. }
  15329. // Optional data
  15330. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  15331. {
  15332. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  15333. {
  15334. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  15335. }
  15336. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  15337. {
  15338. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  15339. }
  15340. }
  15341. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  15342. {
  15343. // Check periods is over max configuration
  15344. 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))
  15345. {
  15346. isPeriodOverMax = TRUE;
  15347. }
  15348. // Check profile purpose is TxProfile
  15349. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15350. {
  15351. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  15352. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  15353. }
  15354. else
  15355. {
  15356. isTxProfile = FALSE;
  15357. }
  15358. }
  15359. }
  15360. }
  15361. }
  15362. // Profile replace or add info
  15363. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  15364. {
  15365. if(evseId != -1)
  15366. {
  15367. if(strlen((char*)filename) > 0)
  15368. {
  15369. // Save profile to file
  15370. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  15371. system(cmdBuf);
  15372. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", evseId);
  15373. filePtr = fopen((char*)filename, "w");
  15374. 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));
  15375. fclose(filePtr);
  15376. }
  15377. ShmOCPP20Data->CsMsg.bits[evseId-1].RequestStartTransactionReq = ON;
  15378. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15379. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_transactionId);
  15380. result = PASS;
  15381. }
  15382. else
  15383. {
  15384. uint8_t isHasIdleConnector = FALSE;
  15385. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15386. {
  15387. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  15388. {
  15389. isHasIdleConnector = TRUE;
  15390. break;
  15391. }
  15392. }
  15393. if((isHasIdleConnector == TRUE) && !ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15394. {
  15395. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  15396. if(strlen((char*)filename) > 0)
  15397. {
  15398. // Save profile to file
  15399. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  15400. system(cmdBuf);
  15401. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  15402. filePtr = fopen((char*)filename, "w");
  15403. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  15404. fclose(filePtr);
  15405. }
  15406. refreshStartTimer(&clientTime.RemoteStartWait);
  15407. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  15408. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15409. {
  15410. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15411. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  15412. }
  15413. result = PASS;
  15414. }
  15415. else
  15416. {
  15417. DEBUG_INFO("There is not any connector is idle.\n");
  15418. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15419. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15420. }
  15421. }
  15422. }
  15423. else
  15424. {
  15425. if(isOverConnectorMax != FALSE)
  15426. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  15427. if(isPeriodOverMax)
  15428. DEBUG_WARN("Profile periods quantity is over spec.\n");
  15429. if(!isTxProfile)
  15430. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  15431. if(!isAllowStart)
  15432. DEBUG_WARN("Target connector does not allow start.\n");
  15433. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((evseId-1)<0?0:(evseId-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  15434. }
  15435. }
  15436. json_object_put(RemoteStartTransaction);
  15437. sendRemoteStartTransactionConfirmation(uuid, ((evseId-1)<0?0:(evseId-1)));
  15438. return result;
  15439. }
  15440. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  15441. {
  15442. mtrace();
  15443. int result = FAIL;
  15444. int match = FALSE;
  15445. int GunNO = 0;
  15446. int tempIndex = 0;
  15447. char transactionIdStr[37];
  15448. int transactionIdIsNULL= TRUE;
  15449. json_object *RemoteStopTransaction;
  15450. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  15451. if(server_pending == TRUE)
  15452. {
  15453. return 0;
  15454. }
  15455. RemoteStopTransaction = json_tokener_parse(payload);
  15456. if(!is_error(RemoteStopTransaction))
  15457. {
  15458. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  15459. {
  15460. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  15461. transactionIdIsNULL = FALSE;
  15462. }
  15463. }
  15464. json_object_put(RemoteStopTransaction);
  15465. if(transactionIdIsNULL == FALSE)
  15466. {
  15467. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  15468. {
  15469. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  15470. {
  15471. //check Transaction active
  15472. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15473. {
  15474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15475. {
  15476. tempIndex = ((gun_index==2) ? 1: 0);
  15477. }
  15478. else
  15479. {
  15480. tempIndex = gun_index;
  15481. }
  15482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15483. {
  15484. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15485. {
  15486. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15487. {
  15488. match = TRUE;
  15489. GunNO = gun_index;
  15490. }
  15491. }
  15492. }// END FOR CHAdeMO_QUANTITY
  15493. }
  15494. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15495. {
  15496. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15497. {
  15498. tempIndex = ((gun_index==2) ? 1: 0);
  15499. }
  15500. else
  15501. {
  15502. tempIndex = gun_index;
  15503. }
  15504. for (int index = 0; index < CCS_QUANTITY; index++)
  15505. {
  15506. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15507. {
  15508. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15509. {
  15510. match = TRUE;
  15511. GunNO = gun_index;
  15512. }
  15513. }
  15514. }// END FOR CCS_QUANTITY
  15515. }
  15516. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15517. {
  15518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15519. {
  15520. tempIndex = ((gun_index==2) ? 1: 0);
  15521. }
  15522. else
  15523. {
  15524. tempIndex = gun_index;
  15525. }
  15526. for (int index = 0; index < GB_QUANTITY; index++)
  15527. {
  15528. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15529. {
  15530. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15531. {
  15532. match = TRUE;
  15533. GunNO = gun_index;
  15534. }
  15535. }
  15536. }// END FOR GB_QUANTITY
  15537. }
  15538. else if(gunType[gun_index] == GUN_TYPE_DO)
  15539. {
  15540. tempIndex = gun_index;
  15541. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15542. {
  15543. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15544. {
  15545. 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
  15546. {
  15547. match = TRUE;
  15548. GunNO = gun_index;
  15549. }
  15550. }
  15551. }// END FOR GB_QUANTITY
  15552. }
  15553. else
  15554. {
  15555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15556. {
  15557. tempIndex = 2;
  15558. }
  15559. else
  15560. {
  15561. tempIndex = gun_index;
  15562. }
  15563. for (int index = 0; index < AC_QUANTITY; index++)
  15564. {
  15565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15566. {
  15567. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15568. {
  15569. match = TRUE;
  15570. GunNO = gun_index;
  15571. }
  15572. }
  15573. }// END FOR CHAdeMO_QUANTITY
  15574. } // END FOR AC ELSE
  15575. }// CHECK IF ResponseTransactionId == transactionIdInt
  15576. }//END FOR
  15577. if( match == TRUE)
  15578. {
  15579. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  15580. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15581. }
  15582. else
  15583. {
  15584. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15585. }
  15586. }
  15587. else
  15588. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15589. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  15590. return result;
  15591. }
  15592. int handleReserveNowRequest(char *uuid, char *payload)
  15593. {
  15594. mtrace();
  15595. int result = FAIL;
  15596. int evseIdInt=0, reservationIdInt=0;
  15597. int tempIndex = 0;
  15598. json_object *ReserveNow;
  15599. DEBUG_INFO("handleReserveNowRequest ...\n");
  15600. ReserveNow = json_tokener_parse(payload);
  15601. if(!is_error(ReserveNow))
  15602. {
  15603. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  15604. {
  15605. evseIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15606. evseIdInt = (evseIdInt==0)?1:evseIdInt;
  15607. memset(&ShmOCPP20Data->ReserveNow[evseIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  15608. ShmOCPP20Data->ReserveNow[evseIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15609. }
  15610. // Required data
  15611. if(json_object_object_get(ReserveNow, "id") != NULL)
  15612. ShmOCPP20Data->ReserveNow[evseIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "id"));
  15613. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  15614. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  15615. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  15616. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  15617. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  15618. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  15619. // Optional data
  15620. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  15621. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  15622. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  15623. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  15624. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  15625. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  15626. result = PASS;
  15627. }
  15628. json_object_put(ReserveNow);
  15629. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15630. if((evseIdInt > 0) && ((evseIdInt -1) <= gunTotalNumber))
  15631. {
  15632. //check Transaction active
  15633. if(gunType[evseIdInt -1] == GUN_TYPE_CHAdeMO)
  15634. {
  15635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15636. {
  15637. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15638. }
  15639. else
  15640. {
  15641. tempIndex = evseIdInt -1;
  15642. }
  15643. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15644. {
  15645. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15646. {
  15647. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15648. {
  15649. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15650. {
  15651. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15652. {
  15653. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  15654. {
  15655. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15656. }
  15657. else
  15658. {
  15659. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15660. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15661. }
  15662. }
  15663. 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'))
  15664. {
  15665. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15666. }
  15667. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15668. {
  15669. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15670. }
  15671. else
  15672. {
  15673. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15674. }
  15675. }
  15676. 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
  15677. {
  15678. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15679. }
  15680. }
  15681. else
  15682. {
  15683. //replace reservation
  15684. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15685. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15686. }
  15687. }
  15688. } // END FOR CHAdeMO_QUANTITY
  15689. }
  15690. else if(gunType[evseIdInt -1] == GUN_TYPE_CCS)
  15691. {
  15692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15693. {
  15694. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15695. }
  15696. else
  15697. {
  15698. tempIndex = evseIdInt -1;
  15699. }
  15700. for (int index = 0; index < CCS_QUANTITY; index++)
  15701. {
  15702. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15703. {
  15704. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15705. {
  15706. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15707. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15708. {
  15709. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15710. {
  15711. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  15712. {
  15713. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15714. }
  15715. else
  15716. {
  15717. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15718. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15719. }
  15720. }
  15721. 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'))
  15722. {
  15723. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15724. }
  15725. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  15726. {
  15727. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15728. }
  15729. else
  15730. {
  15731. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15732. }
  15733. }
  15734. 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
  15735. {
  15736. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15737. }
  15738. }
  15739. else
  15740. {
  15741. //replace reservation
  15742. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15743. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15744. }
  15745. }
  15746. } // END FOR CCS_QUANTITY
  15747. }
  15748. else if(gunType[evseIdInt -1] == GUN_TYPE_GBT)
  15749. {
  15750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15751. {
  15752. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15753. }
  15754. else
  15755. {
  15756. tempIndex = evseIdInt -1;
  15757. }
  15758. for (int index = 0; index < GB_QUANTITY; index++)
  15759. {
  15760. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15761. {
  15762. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15763. {
  15764. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15765. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15766. {
  15767. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15768. {
  15769. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  15770. {
  15771. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15772. }
  15773. else
  15774. {
  15775. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15776. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15777. }
  15778. }
  15779. 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'))
  15780. {
  15781. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15782. }
  15783. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15784. {
  15785. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15786. }
  15787. else
  15788. {
  15789. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15790. }
  15791. }
  15792. 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
  15793. {
  15794. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15795. }
  15796. }
  15797. else
  15798. {
  15799. //replace reservation
  15800. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15801. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15802. }
  15803. }
  15804. }// END FOR GB_QUANTITY
  15805. }
  15806. else if(gunType[evseIdInt -1] == GUN_TYPE_DO)
  15807. {
  15808. tempIndex = evseIdInt -1;
  15809. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15810. {
  15811. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15812. {
  15813. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  15814. {
  15815. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15816. 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
  15817. {
  15818. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15819. {
  15820. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  15821. {
  15822. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15823. }
  15824. else
  15825. {
  15826. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15827. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15828. }
  15829. }
  15830. 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'))
  15831. {
  15832. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15833. }
  15834. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15835. {
  15836. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15837. }
  15838. else
  15839. {
  15840. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15841. }
  15842. }
  15843. 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
  15844. {
  15845. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15846. }
  15847. }
  15848. else
  15849. {
  15850. //replace reservation
  15851. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15852. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15853. }
  15854. }
  15855. }// END FOR DO_QUANTITY
  15856. }
  15857. else
  15858. {
  15859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15860. {
  15861. tempIndex = 2;
  15862. }
  15863. else
  15864. {
  15865. tempIndex = (evseIdInt -1);
  15866. }
  15867. for (int index = 0; index < AC_QUANTITY; index++)
  15868. {
  15869. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15870. {
  15871. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15872. {
  15873. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15874. {
  15875. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15876. {
  15877. 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))
  15878. {
  15879. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15880. }
  15881. else
  15882. {
  15883. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15884. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15885. }
  15886. }
  15887. 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'))
  15888. {
  15889. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15890. }
  15891. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15892. {
  15893. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15894. }
  15895. else
  15896. {
  15897. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15898. }
  15899. }
  15900. 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
  15901. {
  15902. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15903. }
  15904. }
  15905. else
  15906. {
  15907. //replace reservation
  15908. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15909. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15910. }
  15911. }
  15912. } // END FOR AC_QUANTITY
  15913. }
  15914. }
  15915. else if(evseIdInt == 0)
  15916. {
  15917. //check Transaction active
  15918. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15919. {
  15920. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15921. {
  15922. 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'))
  15923. {
  15924. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15925. goto end;
  15926. }
  15927. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15928. {
  15929. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15930. goto end;
  15931. }
  15932. 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
  15933. {
  15934. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15935. goto end;
  15936. }
  15937. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15938. {
  15939. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15940. goto end;
  15941. }
  15942. }
  15943. }// END FOR CHAdeMO_QUANTITY
  15944. for (int index = 0; index < CCS_QUANTITY; index++)
  15945. {
  15946. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15947. {
  15948. 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'))
  15949. {
  15950. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15951. goto end;
  15952. }
  15953. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  15954. {
  15955. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15956. goto end;
  15957. }
  15958. 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
  15959. {
  15960. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15961. goto end;
  15962. }
  15963. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15964. {
  15965. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15966. goto end;
  15967. }
  15968. }
  15969. } // END FOR CCS_QUANTITY
  15970. for (int index = 0; index < GB_QUANTITY; index++)
  15971. {
  15972. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15973. {
  15974. 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'))
  15975. {
  15976. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15977. goto end;
  15978. }
  15979. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15980. {
  15981. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15982. goto end;
  15983. }
  15984. 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
  15985. {
  15986. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15987. goto end;
  15988. }
  15989. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15990. {
  15991. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15992. goto end;
  15993. }
  15994. }
  15995. } // END FOR GB_QUANTITY
  15996. for (int index = 0; index < AC_QUANTITY; index++)
  15997. {
  15998. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15999. {
  16000. 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'))
  16001. {
  16002. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  16003. goto end;
  16004. }
  16005. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  16006. {
  16007. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  16008. goto end;
  16009. }
  16010. 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
  16011. {
  16012. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  16013. goto end;
  16014. }
  16015. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  16016. {
  16017. 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))
  16018. {
  16019. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  16020. goto end;
  16021. }
  16022. }
  16023. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  16024. {
  16025. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  16026. goto end;
  16027. }
  16028. }
  16029. }// END FOR AC_QUANTITY
  16030. //The connectorId is 0
  16031. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  16032. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  16033. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  16034. result = TRUE;
  16035. return result;
  16036. }
  16037. else
  16038. {
  16039. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  16040. }
  16041. if(strcmp((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  16042. {
  16043. strcpy((char *)ShmOCPP20Data->ReserveNow[evseIdInt-1].guid, uuid);
  16044. result = TRUE;
  16045. return result;
  16046. }
  16047. end:
  16048. sendReserveNowConfirmation(uuid, (evseIdInt==0?evseIdInt:evseIdInt-1));
  16049. return result;
  16050. }
  16051. int handleResetRequest(char *uuid, char *payload)
  16052. {
  16053. mtrace();
  16054. int result = FAIL;
  16055. json_object *Reset = json_object_new_object();
  16056. DEBUG_INFO("handleResetRequest...\n");
  16057. Reset = json_tokener_parse(payload);
  16058. ShmOCPP20Data->Reset.evseId = 0;
  16059. if(!is_error(Reset))
  16060. {
  16061. // Required data
  16062. if(json_object_object_get(Reset, "type") != NULL)
  16063. {
  16064. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  16065. }
  16066. if(json_object_object_get(Reset, "evseId") != NULL)
  16067. {
  16068. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  16069. }
  16070. }
  16071. json_object_put(Reset);
  16072. if((ShmOCPP20Data->Reset.evseId == 0) && ((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0)))
  16073. {
  16074. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  16075. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  16076. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  16077. result = PASS;
  16078. }
  16079. else
  16080. {
  16081. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  16082. }
  16083. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  16084. sendResetConfirmation(uuid);
  16085. return result;
  16086. }
  16087. int handleSendLocalListRequest(char *uuid, char *payload)
  16088. {
  16089. mtrace();
  16090. int result = FAIL;
  16091. int checkState_Faulted = FALSE;
  16092. json_object *SendLocalList;
  16093. DEBUG_INFO("handleSendLocalListRequest...\n");
  16094. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  16095. {
  16096. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  16097. goto end;
  16098. }
  16099. SendLocalList = json_tokener_parse(payload);
  16100. if(!is_error(SendLocalList))
  16101. {
  16102. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  16103. // Required data
  16104. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  16105. {
  16106. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  16107. }
  16108. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  16109. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  16110. // Optional data
  16111. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  16112. {
  16113. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  16114. {
  16115. // Required data
  16116. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  16117. {
  16118. 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")));
  16119. 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"))));
  16120. }
  16121. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  16122. {
  16123. 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"))));
  16124. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  16125. 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")));
  16126. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  16127. 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"));
  16128. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  16129. {
  16130. 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")));
  16131. 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")));
  16132. }
  16133. }
  16134. }
  16135. }
  16136. }
  16137. json_object_put(SendLocalList);
  16138. //check Charge Point state
  16139. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16140. {
  16141. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  16142. {
  16143. checkState_Faulted = TRUE; //OCPP Status: Faulted
  16144. }
  16145. }
  16146. for (int index = 0; index < CCS_QUANTITY; index++)
  16147. {
  16148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  16149. {
  16150. checkState_Faulted = TRUE; //OCPP Status
  16151. }
  16152. }
  16153. for (int index = 0; index < GB_QUANTITY; index++)
  16154. {
  16155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  16156. {
  16157. checkState_Faulted = TRUE; //OCPP Status: Faulted
  16158. }
  16159. }
  16160. for (int index = 0; index < AC_QUANTITY; index++)
  16161. {
  16162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  16163. {
  16164. checkState_Faulted = TRUE; //OCPP Status: Faulted
  16165. }
  16166. }
  16167. if(checkState_Faulted == TRUE)
  16168. {
  16169. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  16170. goto end;
  16171. }
  16172. // Check update type
  16173. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  16174. {
  16175. //Local list full update
  16176. DEBUG_INFO("Local list full update.\n");
  16177. DB_getListVerion();
  16178. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  16179. {
  16180. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  16181. goto end;
  16182. }*/
  16183. DB_cleanLocalList();
  16184. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  16185. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  16186. }
  16187. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  16188. {
  16189. //Local list different update
  16190. DEBUG_INFO("Local list different update.\n");
  16191. DB_getListVerion();
  16192. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  16193. {
  16194. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  16195. goto end;
  16196. }
  16197. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  16198. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  16199. }
  16200. else
  16201. {
  16202. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  16203. goto end;
  16204. }
  16205. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  16206. end:
  16207. sendSendLocalListConfirmation(uuid);
  16208. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16209. return result;
  16210. }
  16211. int handleSetChargingProfileRequest(char *uuid, char *payload)
  16212. {
  16213. mtrace();
  16214. int result = FAIL;
  16215. struct SetChargingProfile_20 SetProfileReq = {0};
  16216. uint8_t isLostEvseId = FALSE;
  16217. uint8_t isPeriodOverMax = FALSE;
  16218. uint8_t isStackOverMax = FALSE;
  16219. uint8_t isProfileOverMax = FALSE;
  16220. uint8_t isEvseMismatch = FALSE;
  16221. uint8_t isTransactiodIdMismatch = FALSE;
  16222. uint8_t isInvalidLimit = FALSE;
  16223. uint8_t isWrongFormat = FALSE;
  16224. uint8_t replaceableProfileCnt = 0;
  16225. uint8_t existProfileQuantity = 0;
  16226. uint8_t filename[128]={0};
  16227. uint8_t dataLine[4096]={0};
  16228. FILE *filePtr;
  16229. json_object *SetChargingProfile;
  16230. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  16231. SetChargingProfile = json_tokener_parse(payload);
  16232. if(!is_error(SetChargingProfile))
  16233. {
  16234. // Required data
  16235. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  16236. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  16237. else
  16238. isLostEvseId = TRUE;
  16239. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  16240. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  16241. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  16242. {
  16243. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  16244. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  16245. {
  16246. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  16247. }
  16248. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  16249. {
  16250. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  16251. }
  16252. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  16253. {
  16254. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  16255. }
  16256. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  16257. {
  16258. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  16259. }
  16260. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  16261. {
  16262. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  16263. }
  16264. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  16265. {
  16266. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  16267. }
  16268. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  16269. {
  16270. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  16271. }
  16272. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  16273. {
  16274. int chargingScheduleCount = 0;
  16275. int chargingSchedulePeriodCount = 0;
  16276. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  16277. {
  16278. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  16279. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  16280. {
  16281. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  16282. {
  16283. 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")));
  16284. }
  16285. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  16286. {
  16287. 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"));
  16288. }
  16289. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  16290. {
  16291. 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"));
  16292. }
  16293. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  16294. {
  16295. 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")));
  16296. }
  16297. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  16298. {
  16299. 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"));
  16300. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  16301. {
  16302. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  16303. {
  16304. 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)
  16305. {
  16306. 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"));
  16307. }
  16308. 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)
  16309. {
  16310. 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"));
  16311. }
  16312. 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)
  16313. {
  16314. 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"));
  16315. }
  16316. 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)
  16317. {
  16318. 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"));
  16319. }
  16320. // Check invalid limit
  16321. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  16322. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  16323. {
  16324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  16325. {
  16326. 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)))) ||
  16327. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  16328. {
  16329. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  16330. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  16331. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  16332. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  16333. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  16334. isInvalidLimit = TRUE;
  16335. }
  16336. }
  16337. else
  16338. {
  16339. 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) ||
  16340. (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)))
  16341. {
  16342. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  16343. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  16344. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  16345. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  16346. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  16347. isInvalidLimit = TRUE;
  16348. }
  16349. }
  16350. }
  16351. }
  16352. }
  16353. else
  16354. {
  16355. isPeriodOverMax = TRUE;
  16356. }
  16357. }
  16358. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff") != NULL)
  16359. {
  16360. 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)
  16361. {
  16362. 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"));
  16363. }
  16364. 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)
  16365. {
  16366. 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")));
  16367. }
  16368. 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)
  16369. {
  16370. 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"));
  16371. }
  16372. 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)
  16373. {
  16374. 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"));
  16375. if(cntEntry<=1024)
  16376. {
  16377. for(int idxEntry=0; idxEntry<cntEntry; idxEntry++)
  16378. {
  16379. 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)
  16380. {
  16381. 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"));
  16382. }
  16383. 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)
  16384. {
  16385. 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)
  16386. 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"));
  16387. 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)
  16388. 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"));
  16389. }
  16390. 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)
  16391. {
  16392. 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"));
  16393. if(cntConCost<=3)
  16394. {
  16395. for(uint8_t idxConCost=0; idxConCost<cntConCost; idxConCost++)
  16396. {
  16397. 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)
  16398. 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"));
  16399. 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)
  16400. {
  16401. 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"));
  16402. if(cntConCost<=3)
  16403. {
  16404. for(uint8_t idxCost=0; idxCost<cntCost; idxCost++)
  16405. {
  16406. 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)
  16407. 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")));
  16408. 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)
  16409. 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"));
  16410. 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)
  16411. 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"));
  16412. }
  16413. }
  16414. }
  16415. }
  16416. }
  16417. 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"));
  16418. }
  16419. }
  16420. }
  16421. }
  16422. }
  16423. }
  16424. }
  16425. else
  16426. {
  16427. isWrongFormat = TRUE;
  16428. }
  16429. }
  16430. // Check periods is over max configuration
  16431. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  16432. {
  16433. if(SetProfileReq.evseId == 0)
  16434. {
  16435. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  16436. filePtr = fopen((char*)filename, "r");
  16437. if (!filePtr)
  16438. {
  16439. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  16440. filePtr = fopen((char*)filename, "w+");
  16441. }
  16442. else
  16443. {
  16444. //Check Charging Profile Count
  16445. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16446. char *line = NULL;
  16447. size_t len = 0;
  16448. while(getline(&line, &len, filePtr) != -1)
  16449. {
  16450. json_object *obj = NULL;
  16451. obj = json_tokener_parse(line);
  16452. if(is_error(obj))
  16453. {
  16454. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  16455. }
  16456. else
  16457. {
  16458. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16459. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16460. {
  16461. existProfileQuantity += 1;
  16462. }
  16463. else
  16464. replaceableProfileCnt += 1;
  16465. }
  16466. //DEBUG_INFO("word=%s\n",word);
  16467. /*if(strstr((char*)dataLine, "id")!= NULL)
  16468. {
  16469. existProfileQuantity += 1;
  16470. }*/
  16471. }
  16472. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16473. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16474. {
  16475. isStackOverMax = TRUE;
  16476. }
  16477. }
  16478. fclose(filePtr);
  16479. }
  16480. else
  16481. isEvseMismatch = TRUE;
  16482. }
  16483. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  16484. {
  16485. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  16486. isEvseMismatch = TRUE;
  16487. if(!isEvseMismatch)
  16488. {
  16489. if(SetProfileReq.evseId == 0)
  16490. {
  16491. int tmpExistProfileQuantity;
  16492. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  16493. {
  16494. tmpExistProfileQuantity = 0;
  16495. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16496. filePtr = fopen((char*)filename, "r");
  16497. if (!filePtr)
  16498. {
  16499. DEBUG_INFO("%s not exist, create it.\n", filename);
  16500. filePtr = fopen((char*)filename, "w+");
  16501. }
  16502. else
  16503. {
  16504. //Check Charging Profile Count
  16505. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16506. char *line = NULL;
  16507. size_t len = 0;
  16508. while(getline(&line, &len, filePtr) != -1)
  16509. {
  16510. json_object *obj = NULL;
  16511. obj = json_tokener_parse(line);
  16512. if(is_error(obj))
  16513. {
  16514. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  16515. }
  16516. else
  16517. {
  16518. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16519. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16520. {
  16521. tmpExistProfileQuantity += 1;
  16522. }
  16523. else
  16524. replaceableProfileCnt += 1;
  16525. }
  16526. //DEBUG_INFO("word=%s\n",word);
  16527. /*if(strstr((char*)dataLine, "id")!= NULL)
  16528. {
  16529. tmpExistProfileQuantity += 1;
  16530. }*/
  16531. }
  16532. }
  16533. fclose(filePtr);
  16534. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16535. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16536. {
  16537. isStackOverMax = TRUE;
  16538. }
  16539. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  16540. }
  16541. }
  16542. else
  16543. {
  16544. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16545. filePtr = fopen((char*)filename, "r");
  16546. if (!filePtr)
  16547. {
  16548. DEBUG_INFO("%s not exist, create it.\n", filename);
  16549. filePtr = fopen((char*)filename, "w+");
  16550. }
  16551. else
  16552. {
  16553. //Check Charging Profile Count
  16554. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16555. char *line = NULL;
  16556. size_t len = 0;
  16557. while(getline(&line, &len, filePtr) != -1)
  16558. {
  16559. json_object *obj = NULL;
  16560. obj = json_tokener_parse(line);
  16561. if(is_error(obj))
  16562. {
  16563. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  16564. }
  16565. else
  16566. {
  16567. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16568. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16569. {
  16570. existProfileQuantity += 1;
  16571. }
  16572. else
  16573. replaceableProfileCnt += 1;
  16574. }
  16575. //DEBUG_INFO("word=%s\n",word);
  16576. /*if(strstr((char*)dataLine, "id")!= NULL)
  16577. {
  16578. existProfileQuantity += 1;
  16579. }*/
  16580. }
  16581. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16582. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16583. {
  16584. isStackOverMax = TRUE;
  16585. }
  16586. }
  16587. fclose(filePtr);
  16588. }
  16589. }
  16590. }
  16591. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  16592. {
  16593. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  16594. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16595. else
  16596. isEvseMismatch = TRUE;
  16597. if(!isEvseMismatch)
  16598. {
  16599. filePtr = fopen((char*)filename, "r");
  16600. if (!filePtr)
  16601. {
  16602. DEBUG_INFO("%s not exist, create it.\n", filename);
  16603. filePtr = fopen((char*)filename, "w+");
  16604. }
  16605. else
  16606. {
  16607. //Check Charging Profile Count
  16608. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16609. char *line = NULL;
  16610. size_t len = 0;
  16611. while(getline(&line, &len, filePtr) != -1)
  16612. {
  16613. json_object *obj = NULL;
  16614. obj = json_tokener_parse(line);
  16615. if(is_error(obj))
  16616. {
  16617. DEBUG_ERROR("Parse TxProfile from file error.\n");
  16618. }
  16619. else
  16620. {
  16621. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16622. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16623. {
  16624. existProfileQuantity += 1;
  16625. }
  16626. else
  16627. replaceableProfileCnt += 1;
  16628. }
  16629. //DEBUG_INFO("word=%s\n",word);
  16630. /*if(strstr((char*)dataLine, "id")!= NULL)
  16631. {
  16632. existProfileQuantity += 1;
  16633. }*/
  16634. }
  16635. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16636. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16637. {
  16638. isStackOverMax = TRUE;
  16639. }
  16640. }
  16641. fclose(filePtr);
  16642. if(strcmp((char*)SetProfileReq.chargingProfile.transactionId, (char*)ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId) != 0)
  16643. isTransactiodIdMismatch = TRUE;
  16644. }
  16645. }
  16646. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  16647. {
  16648. /*
  16649. * TODO:
  16650. *
  16651. */
  16652. }
  16653. else
  16654. {}
  16655. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  16656. {
  16657. FILE *fp;
  16658. char dataLine[4096]={0};
  16659. char fnametemp[128]={0};
  16660. int tmpProfileQuantity;
  16661. //Check ChargePointMaxProfile.json exit
  16662. existProfileQuantity = 0;
  16663. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  16664. {
  16665. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  16666. //Check Charging Profile Count
  16667. tmpProfileQuantity = 0;
  16668. while(fscanf(fp, "%s", dataLine) != EOF)
  16669. {
  16670. if(strstr(dataLine, "id")!= NULL)
  16671. {
  16672. existProfileQuantity += 1;
  16673. tmpProfileQuantity += 1;
  16674. }
  16675. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16676. }
  16677. fclose(fp);
  16678. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  16679. }
  16680. //Check TxDefaultProfile_%d.json
  16681. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16682. {
  16683. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16684. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16685. if((access(fnametemp,F_OK))!=-1)
  16686. {
  16687. fp = fopen(fnametemp, "r");
  16688. //Check Charging Profile Count
  16689. tmpProfileQuantity = 0;
  16690. while(fscanf(fp, "%s", dataLine) != EOF)
  16691. {
  16692. //DEBUG_INFO("word=%s\n",word);
  16693. if(strstr(dataLine, "id")!= NULL)
  16694. {
  16695. existProfileQuantity += 1;
  16696. tmpProfileQuantity += 1;
  16697. }
  16698. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16699. }
  16700. fclose(fp);
  16701. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16702. }
  16703. }
  16704. //Check TxProfile_%d.json
  16705. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16706. {
  16707. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16708. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  16709. if((access(fnametemp,F_OK))!=-1)
  16710. {
  16711. fp = fopen(fnametemp, "r");
  16712. //Check Charging Profile Count
  16713. tmpProfileQuantity = 0;
  16714. while(fscanf(fp, "%s", dataLine) != EOF)
  16715. {
  16716. if(strstr(dataLine, "id")!= NULL)
  16717. {
  16718. existProfileQuantity += 1;
  16719. tmpProfileQuantity += 1;
  16720. }
  16721. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16722. }
  16723. fclose(fp);
  16724. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16725. }
  16726. }
  16727. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  16728. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  16729. // To check total Profile quantity
  16730. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  16731. {
  16732. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16733. isProfileOverMax = TRUE;
  16734. }
  16735. else
  16736. {
  16737. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16738. isProfileOverMax = TRUE;
  16739. }
  16740. }
  16741. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  16742. }
  16743. // Profile replace or add info
  16744. if(!isLostEvseId && !isPeriodOverMax && !isProfileOverMax && !isEvseMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  16745. {
  16746. FILE *infile;
  16747. FILE *outfile;
  16748. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  16749. char rmFileCmd[128];
  16750. int tempchargingProfileIdInt;
  16751. int tempchargingProfileStackLevelInt;
  16752. int chkChar;
  16753. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  16754. {
  16755. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  16756. {
  16757. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  16758. }
  16759. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  16760. {
  16761. if(SetProfileReq.evseId==0)
  16762. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16763. else
  16764. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16765. }
  16766. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  16767. {
  16768. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16769. }
  16770. else
  16771. {
  16772. /*
  16773. * TODO:
  16774. *
  16775. */
  16776. }
  16777. infile = fopen ((char*)filename, "r");
  16778. outfile = fopen ((char*)tmpProfileName, "w");
  16779. chkChar = fgetc(infile);
  16780. rewind(infile);
  16781. if(chkChar == EOF)
  16782. {
  16783. // Profile is empty
  16784. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16785. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16786. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16787. fclose(infile);
  16788. fclose(outfile);
  16789. sprintf(rmFileCmd,"rm -f %s",filename);
  16790. system(rmFileCmd);
  16791. rename((char*)tmpProfileName, (char*)filename);
  16792. }
  16793. else
  16794. {
  16795. // Profile is not empty
  16796. int ChargingProfileAdded = FALSE;
  16797. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  16798. {
  16799. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  16800. json_object *tmpChargingProfile;
  16801. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  16802. if(!is_error(tmpChargingProfile))
  16803. {
  16804. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  16805. {
  16806. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  16807. {
  16808. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  16809. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  16810. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  16811. }
  16812. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  16813. {
  16814. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  16815. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  16816. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  16817. }
  16818. }
  16819. }
  16820. json_object_put(tmpChargingProfile);
  16821. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  16822. {
  16823. if(ChargingProfileAdded == FALSE)
  16824. {
  16825. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16826. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16827. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16828. ChargingProfileAdded = TRUE;
  16829. }
  16830. }
  16831. else
  16832. {
  16833. fprintf(outfile,"%s\n",dataLine);
  16834. if(ChargingProfileAdded == FALSE)
  16835. {
  16836. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16837. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16838. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16839. ChargingProfileAdded = TRUE;
  16840. }
  16841. }
  16842. } // end of while loop
  16843. fclose(infile);
  16844. fclose(outfile);
  16845. sprintf(rmFileCmd,"rm -f %s",filename);
  16846. system(rmFileCmd);
  16847. rename((char*)tmpProfileName, (char*)filename);
  16848. }
  16849. }
  16850. sleep(1);
  16851. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  16852. result = PASS;
  16853. }
  16854. else
  16855. {
  16856. if(isLostEvseId)
  16857. DEBUG_WARN("Connector id is wrong.\n");
  16858. if(isEvseMismatch)
  16859. DEBUG_WARN("Connector id is mismatch.\n");
  16860. if(isPeriodOverMax)
  16861. DEBUG_WARN("Profile periods quantity is over spec.\n");
  16862. if(isProfileOverMax)
  16863. DEBUG_WARN("Profile quantity is over spec.\n");
  16864. if(isTransactiodIdMismatch)
  16865. DEBUG_WARN("Transaction id is mismatch.\n");
  16866. if(isInvalidLimit)
  16867. DEBUG_WARN("Limit value is invalid.\n");
  16868. if(isStackOverMax)
  16869. DEBUG_WARN("Profile stack is over spec.\n");
  16870. if(isWrongFormat)
  16871. DEBUG_WARN("Profile format is wrong.\n");
  16872. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  16873. }
  16874. }
  16875. json_object_put(SetChargingProfile);
  16876. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  16877. {
  16878. if(SetProfileReq.evseId == 0)
  16879. {
  16880. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  16881. {
  16882. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  16883. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16884. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  16885. }
  16886. }
  16887. else
  16888. {
  16889. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  16890. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16891. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  16892. }
  16893. }
  16894. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  16895. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16896. return result;
  16897. }
  16898. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  16899. {
  16900. mtrace();
  16901. int result = FAIL;
  16902. json_object *SetDisplayMessage;
  16903. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  16904. SetDisplayMessage = json_tokener_parse(payload);
  16905. if(!is_error(SetDisplayMessage))
  16906. {
  16907. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  16908. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  16909. // Required data
  16910. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  16911. {
  16912. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  16913. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  16914. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  16915. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  16916. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  16917. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  16918. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  16919. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  16920. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  16921. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  16922. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  16923. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  16924. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  16925. {
  16926. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  16927. 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")));
  16928. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  16929. 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")));
  16930. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  16931. 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")));
  16932. }
  16933. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  16934. {
  16935. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  16936. 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")));
  16937. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  16938. 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")));
  16939. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  16940. {
  16941. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  16942. 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"));
  16943. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  16944. 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"));
  16945. }
  16946. }
  16947. }
  16948. }
  16949. json_object_put(SetDisplayMessage);
  16950. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  16951. sendSetDisplayMessagesConfirmation(uuid);
  16952. // Announce CSU there is display request come from server
  16953. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  16954. return result;
  16955. }
  16956. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  16957. {
  16958. mtrace();
  16959. int result = FAIL;
  16960. json_object *SetMonitoringBase;
  16961. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  16962. SetMonitoringBase = json_tokener_parse(payload);
  16963. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  16964. if(!is_error(SetMonitoringBase))
  16965. {
  16966. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  16967. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  16968. // Required data
  16969. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  16970. {
  16971. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  16972. sprintf((char*)ShmOCPP20Data->MonitoringBase, "%s", (char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase);
  16973. FILE *outfile;
  16974. outfile = fopen("/Storage/OCPP/MonitorSetting" , "w+");
  16975. if(outfile == NULL)
  16976. {
  16977. DEBUG_INFO("Error opening file");
  16978. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  16979. }
  16980. fprintf(outfile,"{\"severity\":\"%d\",\"monitoringBase\":\"%s\"}\n", ShmOCPP20Data->MonitoringLevel, (char*)ShmOCPP20Data->MonitoringBase);
  16981. fclose(outfile);
  16982. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16983. }
  16984. else
  16985. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Rejected]);
  16986. }
  16987. json_object_put(SetMonitoringBase);
  16988. sendSetMonitoringBaseConfirmation(uuid);
  16989. return result;
  16990. }
  16991. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  16992. {
  16993. mtrace();
  16994. int result = FAIL;
  16995. json_object *SetMonitoringLevel;
  16996. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  16997. SetMonitoringLevel = json_tokener_parse(payload);
  16998. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  16999. if(!is_error(SetMonitoringLevel))
  17000. {
  17001. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  17002. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  17003. // Required data
  17004. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  17005. {
  17006. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  17007. ShmOCPP20Data->MonitoringLevel = ShmOCPP20Data->SetMonitoringLevel.severity;
  17008. FILE *outfile;
  17009. outfile = fopen("/Storage/OCPP/MonitorSetting" , "w+");
  17010. if(outfile == NULL)
  17011. {
  17012. DEBUG_INFO("Error opening file");
  17013. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  17014. }
  17015. fprintf(outfile,"{\"severity\":\"%d\",\"monitoringBase\":\"%s\"}\n", ShmOCPP20Data->MonitoringLevel, (char*)ShmOCPP20Data->MonitoringBase);
  17016. fclose(outfile);
  17017. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17018. }
  17019. else
  17020. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  17021. }
  17022. json_object_put(SetMonitoringLevel);
  17023. sendSetMonitoringLevelConfirmation(uuid);
  17024. return result;
  17025. }
  17026. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  17027. {
  17028. mtrace();
  17029. int result = FAIL;
  17030. json_object *SetNetworkProfile;
  17031. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  17032. SetNetworkProfile = json_tokener_parse(payload);
  17033. if(!is_error(SetNetworkProfile))
  17034. {
  17035. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  17036. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  17037. // Required data
  17038. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  17039. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  17040. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  17041. {
  17042. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  17043. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  17044. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  17045. {
  17046. if(strcmp(json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")), "JSON") == 0)
  17047. {
  17048. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  17049. }
  17050. else
  17051. {
  17052. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  17053. goto end;
  17054. }
  17055. }
  17056. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  17057. {
  17058. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  17059. if((strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"wss", 3) == 0) || (strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"ws", 2) == 0))
  17060. {
  17061. char protocol[10], host[128], path[512], port[10];
  17062. int check = sscanf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"%[^:]:%*2[/]%[^:]:%[^/]/%199[^\n]", protocol, host, port, path);
  17063. if(check >= 3)
  17064. {
  17065. DEBUG_INFO("URL: %s\n", ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl);
  17066. DEBUG_INFO("protocol: %s\n",protocol);
  17067. DEBUG_INFO("host: %s\n",host);
  17068. DEBUG_INFO("port: %s\n",port);
  17069. DEBUG_INFO("path: %s\n",path);
  17070. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  17071. }
  17072. else
  17073. {
  17074. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  17075. goto end;
  17076. }
  17077. }
  17078. else
  17079. {
  17080. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  17081. goto end;
  17082. }
  17083. }
  17084. else
  17085. {
  17086. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  17087. goto end;
  17088. }
  17089. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  17090. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  17091. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  17092. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  17093. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  17094. {
  17095. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  17096. 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")));
  17097. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  17098. 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")));
  17099. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  17100. 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")));
  17101. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  17102. 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")));
  17103. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  17104. 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")));
  17105. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  17106. 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")));
  17107. }
  17108. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  17109. {
  17110. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  17111. {
  17112. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  17113. 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")));
  17114. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  17115. }
  17116. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  17117. {
  17118. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  17119. 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")));
  17120. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  17121. }
  17122. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  17123. {
  17124. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  17125. 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")));
  17126. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  17127. }
  17128. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  17129. 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"));
  17130. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  17131. 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")));
  17132. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  17133. 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"));
  17134. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  17135. 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")));
  17136. }
  17137. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  17138. }
  17139. }
  17140. json_object_put(SetNetworkProfile);
  17141. /*
  17142. * TODO:
  17143. * 1. Process network configuration and response
  17144. */
  17145. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  17146. {
  17147. }
  17148. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  17149. {
  17150. }
  17151. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  17152. {
  17153. }
  17154. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  17155. {
  17156. }
  17157. else
  17158. {
  17159. }
  17160. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  17161. {
  17162. }
  17163. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  17164. {
  17165. }
  17166. else
  17167. {
  17168. }
  17169. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  17170. {
  17171. }
  17172. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  17173. {
  17174. }
  17175. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  17176. {
  17177. }
  17178. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  17179. {
  17180. }
  17181. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  17182. {
  17183. }
  17184. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  17185. {
  17186. }
  17187. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  17188. {
  17189. }
  17190. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  17191. {
  17192. }
  17193. else
  17194. {
  17195. }
  17196. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  17197. {
  17198. }
  17199. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  17200. {
  17201. }
  17202. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  17203. {
  17204. }
  17205. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  17206. {
  17207. }
  17208. else
  17209. {
  17210. }
  17211. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  17212. {
  17213. }
  17214. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  17215. {
  17216. }
  17217. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  17218. {
  17219. }
  17220. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  17221. {
  17222. }
  17223. else
  17224. {
  17225. }
  17226. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  17227. end:
  17228. sendSetNetworkProfileConfirmation(uuid);
  17229. return result;
  17230. }
  17231. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  17232. {
  17233. mtrace();
  17234. int result = FAIL;
  17235. json_object *SetVariableMonitoring;
  17236. uint8_t variableQuantity = 0;
  17237. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  17238. SetVariableMonitoring = json_tokener_parse(payload);
  17239. if(!is_error(SetVariableMonitoring))
  17240. {
  17241. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  17242. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  17243. // Required data
  17244. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  17245. {
  17246. variableQuantity++;
  17247. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  17248. {
  17249. 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"));
  17250. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  17251. }
  17252. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  17253. {
  17254. 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"));
  17255. }
  17256. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  17257. {
  17258. 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")));
  17259. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  17260. }
  17261. else
  17262. {
  17263. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  17264. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  17265. }
  17266. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  17267. {
  17268. 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"));
  17269. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  17270. }
  17271. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  17272. {
  17273. 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"));
  17274. }
  17275. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  17276. {
  17277. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  17278. {
  17279. 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")));
  17280. }
  17281. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  17282. {
  17283. 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")));
  17284. }
  17285. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  17286. {
  17287. 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)
  17288. {
  17289. 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"));
  17290. }
  17291. 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)
  17292. {
  17293. 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"));
  17294. }
  17295. }
  17296. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  17297. }
  17298. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  17299. {
  17300. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  17301. {
  17302. 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")));
  17303. }
  17304. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  17305. {
  17306. 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")));
  17307. }
  17308. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  17309. }
  17310. uint8_t isDuplicate = FALSE;
  17311. for(uint8_t idx_vm=0;idx_vm<10;idx_vm++)
  17312. {
  17313. if((strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx_vm].component.name, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.name) != NULL) &&
  17314. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx_vm].variable.name, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable.name) != NULL) &&
  17315. (strstr((char*)ShmOCPP20Data->MonitoringComponentVariable[idx_vm].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type) != NULL) &&
  17316. (ShmOCPP20Data->MonitoringComponentVariable[idx_vm].severity == ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity))
  17317. {
  17318. isDuplicate = TRUE;
  17319. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  17320. {
  17321. if(ShmOCPP20Data->MonitoringComponentVariable[idx_vm].id == ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id)
  17322. {
  17323. VariableMonitoringReplace((idx_vm+1), &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx]);
  17324. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  17325. }
  17326. else
  17327. {
  17328. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Duplicate]);
  17329. }
  17330. }
  17331. else
  17332. {
  17333. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Duplicate]);
  17334. }
  17335. break;
  17336. }
  17337. else
  17338. {
  17339. // Do nothing
  17340. }
  17341. }
  17342. if(isDuplicate == FALSE)
  17343. {
  17344. if(variableMonitoringQuantity() >= 10)
  17345. {
  17346. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Rejected]);
  17347. }
  17348. else
  17349. {
  17350. DB_variableMonitoringSaveToDb(&ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx]);
  17351. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  17352. }
  17353. }
  17354. }
  17355. }
  17356. json_object_put(SetVariableMonitoring);
  17357. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  17358. return result;
  17359. }
  17360. int handleSetVariablesRequest(char *uuid, char *payload)
  17361. {
  17362. mtrace();
  17363. uint8_t result = FAIL;
  17364. uint8_t isUnknownComponent = TRUE;
  17365. uint8_t isNeedReconnect = FALSE;
  17366. json_object *SetVariables;
  17367. DEBUG_INFO("handleSetVariablesRequest...\n");
  17368. SetVariables = json_tokener_parse(payload);
  17369. if(!is_error(SetVariables))
  17370. {
  17371. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  17372. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  17373. // Required data
  17374. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  17375. {
  17376. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  17377. {
  17378. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  17379. {
  17380. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  17381. {
  17382. 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")));
  17383. }
  17384. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  17385. {
  17386. 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")));
  17387. }
  17388. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  17389. {
  17390. 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)
  17391. {
  17392. 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"));
  17393. }
  17394. 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)
  17395. {
  17396. 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"));
  17397. }
  17398. }
  17399. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  17400. }
  17401. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  17402. {
  17403. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  17404. {
  17405. 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")));
  17406. }
  17407. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  17408. {
  17409. 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")));
  17410. }
  17411. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  17412. }
  17413. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  17414. {
  17415. 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")));
  17416. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  17417. }
  17418. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  17419. {
  17420. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  17421. }
  17422. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  17423. {
  17424. 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")));
  17425. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  17426. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  17427. {
  17428. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  17429. (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) &&
  17430. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  17431. (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))
  17432. {
  17433. isUnknownComponent = FALSE;
  17434. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17435. //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);
  17436. if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_decimal]) == 0)
  17437. {
  17438. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,TRUE)!=YES)
  17439. {
  17440. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17441. break;
  17442. }
  17443. }
  17444. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_integer]) == 0)
  17445. {
  17446. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, FALSE)!=YES)
  17447. {
  17448. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17449. break;
  17450. }
  17451. }
  17452. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_dateTime]) == 0)
  17453. {
  17454. if(isMatchTimeFormat(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)!=YES)
  17455. {
  17456. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17457. break;
  17458. }
  17459. }
  17460. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_boolean]) == 0)
  17461. {
  17462. // To make sure all boolean value is in uppercase
  17463. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true") != NULL) ||
  17464. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"True") != NULL) ||
  17465. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"TRUE") != NULL))
  17466. {
  17467. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true");
  17468. }
  17469. else if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false") != NULL) ||
  17470. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"False") != NULL) ||
  17471. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"FALSE") != NULL))
  17472. {
  17473. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false");
  17474. }
  17475. else
  17476. {
  17477. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17478. break;
  17479. }
  17480. }
  17481. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  17482. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  17483. {
  17484. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  17485. break;
  17486. }
  17487. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  17488. {
  17489. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17490. break;
  17491. }
  17492. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AuthCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Enabled") != NULL))
  17493. {
  17494. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17495. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17496. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17497. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17498. {
  17499. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17500. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17501. if(strstr((char*)tmp, "true") != NULL)
  17502. {
  17503. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
  17504. }
  17505. else
  17506. {
  17507. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
  17508. }
  17509. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17510. }
  17511. else
  17512. {
  17513. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17514. break;
  17515. }
  17516. }
  17517. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  17518. {
  17519. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  17520. }
  17521. else
  17522. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17523. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  17524. {
  17525. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  17526. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17527. else
  17528. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17529. }
  17530. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  17531. {
  17532. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17533. {
  17534. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17535. }
  17536. else
  17537. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17538. }
  17539. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  17540. {
  17541. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17542. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17543. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17544. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17545. {
  17546. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17547. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17548. }
  17549. else
  17550. {
  17551. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17552. break;
  17553. }
  17554. }
  17555. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  17556. {
  17557. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17558. {
  17559. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17560. }
  17561. else
  17562. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17563. }
  17564. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "CharingProfileRefreshInterval") != NULL))
  17565. {
  17566. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17567. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17568. else
  17569. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17570. }
  17571. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "MessageAttempts") != NULL))
  17572. {
  17573. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17574. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17575. else
  17576. {
  17577. TransactionMessageAttemptsValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17578. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17579. }
  17580. }
  17581. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "MessageAttemptInterval") != NULL))
  17582. {
  17583. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17584. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17585. else
  17586. {
  17587. TransactionMessageRetryIntervalValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17588. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17589. }
  17590. }
  17591. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "RfidEndianType") != NULL))
  17592. {
  17593. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17594. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17595. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17596. if((strstr((char*)tmp, "big") != NULL) || (strstr((char*)tmp, "little") != NULL))
  17597. {
  17598. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "big") != NULL)? "big" : "little");
  17599. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strstr((char*)tmp, "big") != NULL)?1:0;
  17600. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17601. }
  17602. else
  17603. {
  17604. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17605. break;
  17606. }
  17607. }
  17608. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "AuthorizeTimeout") != NULL))
  17609. {
  17610. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) <=0) ||
  17611. (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) ||
  17612. (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.maxLimit))
  17613. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17614. else
  17615. {
  17616. TransactionMessageRetryIntervalValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17617. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17618. }
  17619. }
  17620. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "EnableAcCcs") != NULL))
  17621. {
  17622. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17623. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17624. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17625. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17626. {
  17627. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17628. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17629. }
  17630. else
  17631. {
  17632. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17633. break;
  17634. }
  17635. }
  17636. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  17637. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  17638. {
  17639. isNeedReconnect = TRUE;
  17640. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17641. //SetOcppConnStatus(FALSE);
  17642. }
  17643. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  17644. {
  17645. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17646. {
  17647. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17648. }
  17649. else
  17650. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17651. }
  17652. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SendDuringIdle") != NULL))
  17653. {
  17654. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17655. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17656. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17657. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17658. {
  17659. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17660. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17661. }
  17662. else
  17663. {
  17664. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17665. break;
  17666. }
  17667. }
  17668. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SignReadings") != NULL))
  17669. {
  17670. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17671. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17672. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17673. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17674. {
  17675. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17676. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17677. }
  17678. else
  17679. {
  17680. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17681. break;
  17682. }
  17683. }
  17684. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  17685. {
  17686. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17687. {
  17688. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17689. }
  17690. else
  17691. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17692. }
  17693. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  17694. {
  17695. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17696. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17697. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17698. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17699. {
  17700. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17701. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  17702. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17703. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17704. }
  17705. }
  17706. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  17707. {
  17708. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  17709. {
  17710. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17711. }
  17712. else
  17713. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17714. }
  17715. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "OffLineMaxChargingPower") != NULL))
  17716. {
  17717. if(atoi((const char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > modelnameInfo.ratedPower)
  17718. {
  17719. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17720. }
  17721. else
  17722. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17723. }
  17724. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  17725. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  17726. {
  17727. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17728. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  17729. }
  17730. break;
  17731. }
  17732. else
  17733. {
  17734. // When there is no matched variable, check the component name again
  17735. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  17736. {
  17737. isUnknownComponent = FALSE;
  17738. }
  17739. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  17740. }
  17741. }
  17742. if(isUnknownComponent == TRUE)
  17743. {
  17744. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  17745. }
  17746. }
  17747. }
  17748. }
  17749. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17750. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  17751. if(isNeedReconnect)
  17752. {
  17753. SetOcppConnStatus(FALSE);
  17754. }
  17755. }
  17756. json_object_put(SetVariables);
  17757. return result;
  17758. }
  17759. int handleTriggerMessageRequest(char *uuid, char *payload)
  17760. {
  17761. mtrace();
  17762. int result = FAIL;
  17763. int evseIdIsNULL = FALSE;
  17764. //int connectorIdIsNULL = FALSE;
  17765. int evseIdInt =0;
  17766. //int connectorIdInt =0;
  17767. json_object *TriggerMessage;
  17768. DEBUG_INFO("handleTriggerMessageRequest\n");
  17769. TriggerMessage = json_tokener_parse(payload);
  17770. if(!is_error(TriggerMessage))
  17771. {
  17772. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  17773. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  17774. // Required data
  17775. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  17776. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  17777. // Optional data
  17778. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  17779. {
  17780. // Required data
  17781. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  17782. {
  17783. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  17784. evseIdInt = ShmOCPP20Data->TriggerMessage.evse.id;
  17785. }
  17786. else
  17787. evseIdIsNULL = TRUE;
  17788. // Optional data
  17789. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  17790. {
  17791. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  17792. //connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  17793. }
  17794. //else
  17795. //connectorIdIsNULL = TRUE;
  17796. }
  17797. else
  17798. evseIdIsNULL = TRUE;
  17799. }
  17800. json_object_put(TriggerMessage);
  17801. if((evseIdIsNULL == TRUE) || ((evseIdIsNULL == FALSE) && ((evseIdInt > 0) && (evseIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  17802. {
  17803. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  17804. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  17805. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  17806. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  17807. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  17808. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  17809. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  17810. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  17811. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  17812. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  17813. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  17814. {
  17815. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  17816. sendTriggerMessageConfirmation(uuid);
  17817. return TRUE;
  17818. }
  17819. else
  17820. {
  17821. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  17822. sendTriggerMessageConfirmation(uuid);
  17823. }
  17824. }
  17825. else if(evseIdIsNULL == FALSE && ((evseIdInt <= 0) || (evseIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  17826. {
  17827. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17828. sendTriggerMessageConfirmation(uuid);
  17829. return TRUE;
  17830. }
  17831. //==========================
  17832. // Trigger message
  17833. //==========================
  17834. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  17835. {
  17836. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  17837. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  17838. {
  17839. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  17840. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17841. }
  17842. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17843. }
  17844. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  17845. {
  17846. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  17847. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  17848. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  17849. }
  17850. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  17851. {
  17852. if(server_sign)
  17853. {
  17854. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17855. sendTriggerMessageConfirmation(uuid);
  17856. return TRUE;
  17857. }
  17858. else
  17859. {
  17860. if(DB_updateBootType(BootReasonEnumType_Triggered))
  17861. server_sign = FALSE;
  17862. }
  17863. }
  17864. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  17865. {
  17866. refreshStartTimer(&clientTime.Heartbeat);
  17867. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  17868. }
  17869. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  17870. {
  17871. if(evseIdIsNULL == FALSE)
  17872. {
  17873. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17874. {
  17875. cpinitateMsg.bits[evseIdInt-1].TriggerMeterValueReq = ON;
  17876. }
  17877. }
  17878. else
  17879. {
  17880. for(int idx=0;idx< gunTotalNumber;idx++)
  17881. {
  17882. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  17883. }
  17884. }
  17885. }
  17886. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  17887. {
  17888. if(evseIdIsNULL == FALSE)
  17889. {
  17890. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17891. {
  17892. cpinitateMsg.bits[evseIdInt-1].TriggerStatusNotificationReq = ON;
  17893. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  17894. }
  17895. }
  17896. else
  17897. {
  17898. for(int idx=0;idx< gunTotalNumber;idx++)
  17899. {
  17900. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  17901. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  17902. }
  17903. }
  17904. }
  17905. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  17906. {
  17907. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17908. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17909. {
  17910. 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\" &");
  17911. }
  17912. }
  17913. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  17914. {
  17915. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17916. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17917. {
  17918. 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\" &");
  17919. }
  17920. }
  17921. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  17922. {
  17923. if(evseIdIsNULL == FALSE)
  17924. {
  17925. if((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber))
  17926. {
  17927. //ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  17928. cpinitateMsg.bits[evseIdInt -1].TriggerTransactionEventReq = ON;
  17929. }
  17930. }
  17931. else
  17932. {
  17933. for(int idx=0;idx< gunTotalNumber;idx++)
  17934. {
  17935. //ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  17936. cpinitateMsg.bits[idx].TriggerTransactionEventReq = ON;
  17937. }
  17938. }
  17939. }
  17940. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  17941. {
  17942. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17943. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17944. {
  17945. 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\" &");
  17946. }
  17947. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17948. {
  17949. 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\" &");
  17950. }
  17951. }
  17952. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  17953. {
  17954. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  17955. }
  17956. return result;
  17957. }
  17958. int handleUnlockConnectorRequest(char *uuid, char *payload)
  17959. {
  17960. mtrace();
  17961. int result = FAIL;
  17962. int evseIdInt =0;
  17963. int tempIndex = 0;
  17964. json_object *UnlockConnector;
  17965. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  17966. UnlockConnector = json_tokener_parse(payload);
  17967. if(!is_error(UnlockConnector))
  17968. {
  17969. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  17970. {
  17971. evseIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  17972. ShmOCPP20Data->UnlockConnector[(evseIdInt>0?evseIdInt-1:0)].evseId = evseIdInt;
  17973. //it should not be array!!
  17974. }
  17975. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  17976. {
  17977. if(json_object_get_int(json_object_object_get(UnlockConnector, "connectorId")) != 1)
  17978. {
  17979. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17980. goto end;
  17981. }
  17982. }
  17983. }
  17984. json_object_put(UnlockConnector);
  17985. DEBUG_INFO("Unlock evseIdInt = %d\n",evseIdInt);
  17986. if(gunTotalNumber == 0)
  17987. {
  17988. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17989. goto end;
  17990. }
  17991. else if((evseIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (evseIdInt <= 0))
  17992. {
  17993. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17994. goto end;
  17995. }
  17996. else
  17997. {
  17998. memset(&ShmOCPP20Data->UnlockConnector[evseIdInt-1], 0, sizeof(struct UnlockConnector_20));
  17999. memcpy(&ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid));
  18000. //check Transaction active
  18001. if(gunType[evseIdInt-1] == GUN_TYPE_CHAdeMO)
  18002. {
  18003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18004. {
  18005. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  18006. }
  18007. else
  18008. {
  18009. tempIndex = evseIdInt -1;
  18010. }
  18011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18012. {
  18013. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  18014. {
  18015. //stop Transaction
  18016. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  18017. }
  18018. }
  18019. }
  18020. else if(gunType[evseIdInt-1] == GUN_TYPE_CCS)
  18021. {
  18022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18023. {
  18024. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  18025. }
  18026. else
  18027. {
  18028. tempIndex = evseIdInt -1;
  18029. }
  18030. for (int index = 0; index < CCS_QUANTITY; index++)
  18031. {
  18032. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  18033. {
  18034. //stop Transaction
  18035. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  18036. }
  18037. }
  18038. }
  18039. else if(gunType[evseIdInt-1] == GUN_TYPE_GBT)
  18040. {
  18041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18042. {
  18043. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  18044. }
  18045. else
  18046. {
  18047. tempIndex = evseIdInt -1;
  18048. }
  18049. for (int index = 0; index < GB_QUANTITY; index++)
  18050. {
  18051. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  18052. {
  18053. //stop Transaction
  18054. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  18055. }
  18056. }
  18057. }
  18058. else if(gunType[evseIdInt-1] == GUN_TYPE_DO)
  18059. {
  18060. tempIndex = evseIdInt -1;
  18061. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18062. {
  18063. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  18064. {
  18065. //stop Transaction
  18066. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  18067. }
  18068. }
  18069. }
  18070. else
  18071. {
  18072. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18073. {
  18074. tempIndex = 2;
  18075. }
  18076. else
  18077. {
  18078. tempIndex = evseIdInt-1;
  18079. }
  18080. for (int index = 0; index < AC_QUANTITY; index++)
  18081. {
  18082. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  18083. {
  18084. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  18085. }
  18086. }
  18087. }
  18088. ShmOCPP20Data->UnlockConnector[evseIdInt-1].connectorId = evseIdInt;
  18089. strcpy((char *)ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid);
  18090. result = TRUE;
  18091. return result;
  18092. }
  18093. end:
  18094. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorConf = ON;
  18095. return result;
  18096. }
  18097. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  18098. {
  18099. mtrace();
  18100. int result = FAIL;
  18101. json_object *UnpublishFirmware;
  18102. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  18103. UnpublishFirmware = json_tokener_parse(payload);
  18104. if(!is_error(UnpublishFirmware))
  18105. {
  18106. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  18107. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  18108. // Required data
  18109. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  18110. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  18111. }
  18112. json_object_put(UnpublishFirmware);
  18113. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  18114. /*
  18115. * TODO:
  18116. * 1. Check unpublished status
  18117. */
  18118. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  18119. sendUnpublishFirmwareConfirmation(uuid);
  18120. return result;
  18121. }
  18122. static char UpdateFirmwarepayloadData[512]={0};
  18123. void *UpdateFirmwareProcess(void *data)
  18124. {
  18125. pthread_detach(pthread_self());
  18126. mtrace();
  18127. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  18128. int port=0;
  18129. int isSuccess = 0;
  18130. char ftpbuf[1024];
  18131. char temp[1024];
  18132. char * pch;
  18133. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  18134. json_object *UpdateFirmware;
  18135. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  18136. if(!is_error(UpdateFirmware))
  18137. {
  18138. // Required data
  18139. if(json_object_object_get(UpdateFirmware, "requestId"))
  18140. {
  18141. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  18142. }
  18143. if(json_object_object_get(UpdateFirmware, "firmware"))
  18144. {
  18145. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  18146. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  18147. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  18148. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  18149. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  18150. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  18151. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  18152. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  18153. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  18154. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  18155. }
  18156. // Optional data
  18157. if(json_object_object_get(UpdateFirmware, "retries"))
  18158. {
  18159. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  18160. }
  18161. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  18162. {
  18163. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  18164. }
  18165. }
  18166. json_object_put(UpdateFirmware);
  18167. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  18168. memset(path, 0, ARRAY_SIZE(path));
  18169. // Wait retrieveData
  18170. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  18171. {
  18172. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18173. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  18174. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18175. do
  18176. {
  18177. sleep(1);
  18178. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  18179. }
  18180. system("rm -f /mnt/*");
  18181. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  18182. {
  18183. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  18184. sprintf(ftppath,"/%s", path);
  18185. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  18186. DEBUG_INFO("protocol: %s\n",protocol);
  18187. DEBUG_INFO("host: %s\n",host);
  18188. DEBUG_INFO("path: %s\n",path);
  18189. DEBUG_INFO("ftppath: %s\n",ftppath);
  18190. int ftppathlen=strlen(ftppath);
  18191. int i=1;
  18192. char filenametemp[50];
  18193. while(i < ftppathlen)
  18194. {
  18195. int len=ftppathlen-i;
  18196. if(ftppath[len]== 47) // '/' ascll code: 47
  18197. {
  18198. DEBUG_INFO("compare '/' all right\n");
  18199. break;
  18200. }
  18201. i=i+1;
  18202. }
  18203. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  18204. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  18205. filenametemp[i+1] = 0;
  18206. do
  18207. {
  18208. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18209. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  18210. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18211. sleep(3);
  18212. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  18213. if(!isSuccess)
  18214. {
  18215. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18216. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  18217. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18218. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  18219. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18220. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  18221. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18222. }
  18223. else
  18224. {
  18225. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18226. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  18227. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18228. }
  18229. ShmOCPP20Data->UpdateFirmware.retries--;
  18230. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  18231. }
  18232. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  18233. {
  18234. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18235. memset(temp, 0, ARRAY_SIZE(temp));
  18236. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  18237. int ftppathlen=strlen(ftpbuf);
  18238. int i=1;
  18239. char filenametemp[50];
  18240. while(i < ftppathlen)
  18241. {
  18242. int len=ftppathlen-i;
  18243. if(ftpbuf[len]== 47) // '/' ascll code: 47
  18244. {
  18245. DEBUG_INFO(" compare '/' all right\n");
  18246. break;
  18247. }
  18248. i=i+1;
  18249. }
  18250. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  18251. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  18252. filenametemp[i+1] = 0;
  18253. strncpy(temp, ftpbuf, ftppathlen-i+1);
  18254. pch=strchr(temp,'@');
  18255. if(pch==NULL)
  18256. {
  18257. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  18258. protocol, host, &port, path);
  18259. strcpy(user,"anonymous");
  18260. strcpy(password,"");
  18261. }
  18262. else
  18263. {
  18264. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  18265. protocol, user, password, host, &port, path);
  18266. }
  18267. sscanf(host,"%[^/]%s",host1, path1);
  18268. sprintf(ftppath,"%s", path1);
  18269. if(port == 0)
  18270. {
  18271. port = 21;
  18272. }
  18273. do
  18274. {
  18275. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18276. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  18277. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18278. sleep(3);
  18279. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  18280. if(!isSuccess)
  18281. {
  18282. //BulldogUtil.sleepMs(interval*1000);
  18283. DEBUG_INFO("Update firmware request and download file fail.\n");
  18284. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18285. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  18286. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18287. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  18288. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18289. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  18290. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18291. }
  18292. else
  18293. {
  18294. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18295. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  18296. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18297. }
  18298. ShmOCPP20Data->UpdateFirmware.retries--;
  18299. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  18300. }
  18301. else
  18302. {
  18303. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18304. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  18305. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18306. sleep(1);
  18307. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18308. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  18309. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18310. }
  18311. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  18312. interLock.isUpdateFirmwareGoing = OFF;
  18313. pthread_exit(NULL);
  18314. }
  18315. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  18316. {
  18317. mtrace();
  18318. int result = FAIL;
  18319. pthread_t t;
  18320. sendUpdateFirmwareConfirmation(uuid);
  18321. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  18322. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  18323. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  18324. if(!interLock.isUpdateFirmwareGoing)
  18325. {
  18326. interLock.isUpdateFirmwareGoing = ON;
  18327. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  18328. sleep(1);
  18329. }
  18330. else
  18331. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  18332. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  18333. return result;
  18334. }
  18335. int handleUnknownRequest(char *uuid, char *payload)
  18336. {
  18337. mtrace();
  18338. int result = FAIL;
  18339. DEBUG_INFO("handleUnknownRequest...\n");
  18340. sendUnknownConfirmation(uuid);
  18341. result = PASS;
  18342. return result;
  18343. }
  18344. //==========================================
  18345. // Handle server response routine
  18346. //==========================================
  18347. void handleAuthorizeResponse(char *payload, int gun_index)
  18348. {
  18349. mtrace();
  18350. DEBUG_INFO("handleAuthorizeResponse...\n");
  18351. json_object *Authorize;
  18352. Authorize = json_tokener_parse(payload);
  18353. if(!is_error(Authorize))
  18354. {
  18355. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  18356. {
  18357. // Required data
  18358. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  18359. // Optional data
  18360. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  18361. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  18362. else
  18363. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  18364. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority") != NULL)
  18365. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  18366. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1") != NULL)
  18367. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  18368. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "evseId") != NULL)
  18369. {
  18370. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTokenInfo"), "evseId"));idx++)
  18371. {
  18372. 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));
  18373. }
  18374. }
  18375. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2") != NULL)
  18376. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  18377. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken") != NULL)
  18378. {
  18379. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  18380. 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")));
  18381. else
  18382. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  18383. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  18384. 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")));
  18385. }
  18386. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage") != NULL)
  18387. {
  18388. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  18389. 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")));
  18390. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  18391. 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")));
  18392. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  18393. 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")));
  18394. }
  18395. }
  18396. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  18397. {
  18398. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  18399. }
  18400. }
  18401. json_object_put(Authorize);
  18402. //Update idTag information to authorization cache if supported
  18403. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  18404. /*(strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  18405. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&*/
  18406. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  18407. {
  18408. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  18409. }
  18410. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  18411. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  18412. authorizeRetryTimes = 0;
  18413. }
  18414. void handleBootNotificationResponse(char *payload, int gun_index)
  18415. {
  18416. mtrace();
  18417. char statusStr[12]={0};
  18418. char currentTimeStr[30]={0};
  18419. int intervalInt = 0;
  18420. DEBUG_INFO("handleBootNotificationResponse...\n");
  18421. json_object *BootNotification;
  18422. BootNotification = json_tokener_parse(payload);
  18423. if(!is_error(BootNotification))
  18424. {
  18425. // Required data
  18426. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  18427. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  18428. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  18429. }
  18430. json_object_put(BootNotification);
  18431. DEBUG_INFO("statusStr: %s\n", statusStr);
  18432. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  18433. BootNotificationInterval = intervalInt;
  18434. //write back to ShmOCPP20Data->BootNotification
  18435. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  18436. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  18437. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  18438. {
  18439. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  18440. {
  18441. //Do nothing because the value is out of range.
  18442. }
  18443. else
  18444. {
  18445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  18446. HeartBeatWaitTime = intervalInt;
  18447. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  18448. }
  18449. server_sign = TRUE;
  18450. server_pending =FALSE;
  18451. DB_updateBootType(BootReasonEnumType_PowerUp);
  18452. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  18453. }
  18454. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  18455. {
  18456. server_pending = TRUE;
  18457. }
  18458. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  18459. srand(time(NULL));
  18460. refreshStartTimer(&clientTime.Heartbeat);
  18461. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  18462. SetOcppConnStatus(TRUE);
  18463. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  18464. }
  18465. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  18466. {
  18467. mtrace();
  18468. json_object *ClearedChargingLimit;
  18469. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  18470. ClearedChargingLimit = json_tokener_parse(payload);
  18471. if(!is_error(ClearedChargingLimit))
  18472. {
  18473. // Required data
  18474. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  18475. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  18476. }
  18477. json_object_put(ClearedChargingLimit);
  18478. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  18479. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  18480. }
  18481. void handleDataTransferResponse(char *payload, int gun_index)
  18482. {
  18483. mtrace();
  18484. json_object *DataTrans;
  18485. DEBUG_INFO("handleDataTransferResponse...\n");
  18486. DataTrans = json_tokener_parse(payload);
  18487. if(!is_error(DataTrans))
  18488. {
  18489. // Required data
  18490. if(json_object_object_get(DataTrans,"status") != NULL)
  18491. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  18492. // Optional data
  18493. if(json_object_object_get(DataTrans,"data") != NULL)
  18494. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  18495. }
  18496. json_object_put(DataTrans);
  18497. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  18498. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  18499. }
  18500. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  18501. {
  18502. mtrace();
  18503. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  18504. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  18505. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  18506. }
  18507. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  18508. {
  18509. mtrace();
  18510. json_object *Get15118EVCertificate;
  18511. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  18512. Get15118EVCertificate = json_tokener_parse(payload);
  18513. if(!is_error(Get15118EVCertificate))
  18514. {
  18515. // Required data
  18516. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  18517. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  18518. // Optional data
  18519. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  18520. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  18521. }
  18522. json_object_put(Get15118EVCertificate);
  18523. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  18524. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  18525. }
  18526. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  18527. {
  18528. mtrace();
  18529. json_object *GetCertificateStatus;
  18530. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  18531. GetCertificateStatus = json_tokener_parse(payload);
  18532. if(!is_error(GetCertificateStatus))
  18533. {
  18534. // Required data
  18535. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  18536. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  18537. // Optional data
  18538. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  18539. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  18540. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  18541. {
  18542. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  18543. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  18544. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  18545. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  18546. }
  18547. }
  18548. json_object_put(GetCertificateStatus);
  18549. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  18550. {
  18551. /*
  18552. * TODO:
  18553. * 1. If get certificate response accepted process something here
  18554. */
  18555. }
  18556. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  18557. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  18558. }
  18559. void handleHeartbeatResponse(char *payload, int gun_index)
  18560. {
  18561. mtrace();
  18562. DEBUG_INFO("handleHeartbeatResponse...\n");
  18563. json_object *Heartbeat;
  18564. Heartbeat = json_tokener_parse(payload);
  18565. if(!is_error(Heartbeat))
  18566. {
  18567. // Required data
  18568. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  18569. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  18570. }
  18571. json_object_put(Heartbeat);
  18572. if(FirstHeartBeat == OFF)
  18573. {
  18574. FirstHeartBeat = ON;
  18575. DEBUG_INFO("FirstHeartBeat \n");
  18576. }
  18577. HeartBeatWithNOResponse = 0;
  18578. refreshStartTimer(&clientTime.Heartbeat);
  18579. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  18580. }
  18581. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  18582. {
  18583. mtrace();
  18584. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  18585. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  18586. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  18587. }
  18588. void handleMeterValuesResponse(char *payload, int gun_index)
  18589. {
  18590. mtrace();
  18591. DEBUG_INFO("handleMeterValuesResponse...\n");
  18592. isQueueSendable = ON;
  18593. }
  18594. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  18595. {
  18596. mtrace();
  18597. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  18598. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  18599. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  18600. }
  18601. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  18602. {
  18603. mtrace();
  18604. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  18605. }
  18606. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  18607. {
  18608. mtrace();
  18609. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  18610. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  18611. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  18612. }
  18613. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  18614. {
  18615. mtrace();
  18616. json_object *NotifyEVChargingNeeds;
  18617. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  18618. NotifyEVChargingNeeds = json_tokener_parse(payload);
  18619. if(!is_error(NotifyEVChargingNeeds))
  18620. {
  18621. // Required data
  18622. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  18623. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  18624. }
  18625. json_object_put(NotifyEVChargingNeeds);
  18626. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  18627. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  18628. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  18629. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsConf = ON;
  18630. }
  18631. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  18632. {
  18633. mtrace();
  18634. json_object *NotifyEVChargingSchedule;
  18635. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  18636. NotifyEVChargingSchedule = json_tokener_parse(payload);
  18637. if(!is_error(NotifyEVChargingSchedule))
  18638. {
  18639. // Required data
  18640. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  18641. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  18642. }
  18643. json_object_put(NotifyEVChargingSchedule);
  18644. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  18645. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleConf = ON;
  18646. }
  18647. void handleNotifyEventResponse(char *payload, int gun_index)
  18648. {
  18649. mtrace();
  18650. DEBUG_INFO("handleNotifyEventResponse...\n");
  18651. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  18652. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  18653. }
  18654. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  18655. {
  18656. mtrace();
  18657. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  18658. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  18659. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  18660. }
  18661. void handleNotifyReportResponse(char *payload, int gun_index)
  18662. {
  18663. mtrace();
  18664. DEBUG_INFO("handleNotifyReportResponse...\n");
  18665. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  18666. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  18667. }
  18668. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  18669. {
  18670. mtrace();
  18671. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  18672. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  18673. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  18674. }
  18675. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  18676. {
  18677. mtrace();
  18678. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  18679. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  18680. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  18681. }
  18682. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  18683. {
  18684. mtrace();
  18685. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  18686. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  18687. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  18688. }
  18689. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  18690. {
  18691. mtrace();
  18692. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  18693. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  18694. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  18695. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  18696. }
  18697. void handleSignCertificateResponse(char *payload, int gun_index)
  18698. {
  18699. mtrace();
  18700. json_object *SignCertificate;
  18701. DEBUG_INFO("handleSignCertificateResponse...\n");
  18702. SignCertificate = json_tokener_parse(payload);
  18703. if(!is_error(SignCertificate))
  18704. {
  18705. // Required data
  18706. if(json_object_object_get(SignCertificate,"status") != NULL)
  18707. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  18708. // Optional data
  18709. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  18710. {
  18711. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  18712. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  18713. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  18714. }
  18715. }
  18716. json_object_put(SignCertificate);
  18717. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  18718. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  18719. }
  18720. void handleStatusNotificationResponse(char *payload, int gun_index)
  18721. {
  18722. mtrace();
  18723. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  18724. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  18725. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  18726. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  18727. }
  18728. void handleTransactionEventResponse(char *payload, int gun_index)
  18729. {
  18730. mtrace();
  18731. json_object *TransactionEven;
  18732. DEBUG_INFO("handleTransactionEventResponse...\n");
  18733. TransactionEven = json_tokener_parse(payload);
  18734. if(!is_error(TransactionEven))
  18735. {
  18736. // Required data
  18737. // Optional data
  18738. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  18739. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  18740. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  18741. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  18742. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  18743. {
  18744. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  18745. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  18746. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  18747. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  18748. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  18749. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  18750. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  18751. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  18752. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  18753. {
  18754. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  18755. 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")));
  18756. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  18757. 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")));
  18758. }
  18759. }
  18760. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  18761. {
  18762. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  18763. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  18764. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  18765. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  18766. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  18767. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  18768. }
  18769. }
  18770. json_object_put(TransactionEven);
  18771. isQueueSendable = ON;
  18772. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  18773. }
  18774. //==========================================
  18775. // Handle Error routine
  18776. //==========================================
  18777. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  18778. {
  18779. mtrace();
  18780. #ifdef SystemLogMessage
  18781. DEBUG_INFO("errorCode: %s\n", errorCode);
  18782. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  18783. DEBUG_INFO("errorDetails: %s\n", payload);
  18784. #endif
  18785. }
  18786. //===============================================
  18787. // Common routine
  18788. //===============================================
  18789. int initialConfigurationTable(void)
  18790. {
  18791. DEBUG_INFO("initialConfigurationTable...\n");
  18792. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  18793. DB_variableIsCreate();
  18794. DB_variableLoadFromDb();
  18795. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  18796. {
  18797. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  18798. DB_variableClear();
  18799. DB_variableIsCreate();
  18800. DB_variableLoadFromDb();
  18801. }
  18802. DB_getNetworkProfileFromDb();
  18803. DB_variableMonitoringLoadFromDb();
  18804. for(uint8_t idx_vm=0;idx_vm<10;idx_vm++)
  18805. {
  18806. DEBUG_INFO("---------------------------------------------------------------------------------\n");
  18807. DEBUG_INFO("MonitoringComponentVariable[%d].id = %d\n", idx_vm, ShmOCPP20Data->MonitoringComponentVariable[idx_vm].id);
  18808. DEBUG_INFO("MonitoringComponentVariable[%d].value = %.2f\n", idx_vm, ShmOCPP20Data->MonitoringComponentVariable[idx_vm].value);
  18809. DEBUG_INFO("MonitoringComponentVariable[%d].type = %s\n", idx_vm, ShmOCPP20Data->MonitoringComponentVariable[idx_vm].type);
  18810. DEBUG_INFO("MonitoringComponentVariable[%d].severity = %d\n", idx_vm, ShmOCPP20Data->MonitoringComponentVariable[idx_vm].severity);
  18811. DEBUG_INFO("MonitoringComponentVariable[%d].component.name = %s\n", idx_vm, ShmOCPP20Data->MonitoringComponentVariable[idx_vm].component.name);
  18812. DEBUG_INFO("MonitoringComponentVariable[%d].variable.name = %s\n", idx_vm, ShmOCPP20Data->MonitoringComponentVariable[idx_vm].variable.name);
  18813. DEBUG_INFO("---------------------------------------------------------------------------------\n");
  18814. }
  18815. return 0;
  18816. }
  18817. int TransactionMessageAttemptsGet(void)
  18818. {
  18819. return TransactionMessageAttemptsValue;
  18820. }
  18821. int FirstHeartBeatResponse(void)
  18822. {
  18823. return FirstHeartBeat;
  18824. }
  18825. int TransactionMessageRetryIntervalGet(void)
  18826. {
  18827. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18828. }
  18829. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18830. {
  18831. int result = TRUE;
  18832. char rmFileCmd[100]={0};
  18833. char FilePath[100]={0};
  18834. char ftpbuf[200];
  18835. int systemresult;
  18836. sprintf(FilePath,"/mnt/%s",filename);
  18837. system("ping 8.8.8.8 &");
  18838. if((access(FilePath,F_OK))!=-1)
  18839. {
  18840. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18841. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18842. system(rmFileCmd);
  18843. }
  18844. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18845. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18846. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18847. systemresult = system(ftpbuf);
  18848. if(systemresult != 0)
  18849. {
  18850. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  18851. result = FALSE;
  18852. }
  18853. system("pkill ping");
  18854. return result;
  18855. }
  18856. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18857. {
  18858. int result = TRUE;
  18859. char rmFileCmd[100]={0};
  18860. char FilePath[100]={0};
  18861. char ftpbuf[200];
  18862. int systemresult;
  18863. sprintf(FilePath,"/mnt/%s",filename);
  18864. system("ping 8.8.8.8 &");
  18865. if((access(FilePath,F_OK))!=-1)
  18866. {
  18867. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18868. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18869. system(rmFileCmd);
  18870. }
  18871. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18872. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18873. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18874. systemresult = system(ftpbuf);
  18875. if(systemresult != 0)
  18876. {
  18877. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18878. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18879. systemresult = system(ftpbuf);
  18880. if(systemresult != 0)
  18881. {
  18882. DEBUG_WARN("FTP download fail!\n");
  18883. result = FALSE;
  18884. }
  18885. }
  18886. system("pkill ping");
  18887. return result;
  18888. }
  18889. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18890. {
  18891. char rmFileCmd[100]={0};
  18892. char FilePath[100]={0};
  18893. char buf[512];
  18894. int systemresult = 0;
  18895. //DEBUG_INFO("filename=%s\n",filename);
  18896. //DEBUG_INFO("url=%s\n",url);
  18897. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18898. if((access(FilePath,F_OK))!=-1)
  18899. {
  18900. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18901. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18902. system(rmFileCmd);
  18903. }
  18904. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18905. if(fp == NULL)
  18906. {
  18907. DEBUG_INFO("log is NULL\n");
  18908. return FALSE;
  18909. }
  18910. else
  18911. {
  18912. fprintf(fp, "%s\n", url);
  18913. fprintf(fp, "%s\n", filename);
  18914. fclose(fp);
  18915. }
  18916. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18917. if(phpFP == NULL)
  18918. {
  18919. DEBUG_INFO("PHP upload fail.\n");
  18920. return FALSE;
  18921. }
  18922. else
  18923. {
  18924. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18925. {
  18926. if(strstr(buf, "result") != NULL)
  18927. {
  18928. sscanf(buf, "result: %d", &systemresult);
  18929. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18930. }
  18931. }
  18932. pclose(phpFP);
  18933. }
  18934. if(systemresult != 1)
  18935. {
  18936. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18937. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18938. if(phpFP == NULL)
  18939. {
  18940. DEBUG_WARN("PHP PUT upload fail.\n");
  18941. return FALSE;
  18942. }
  18943. else
  18944. {
  18945. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18946. {
  18947. if(strstr(buf, "result") != NULL)
  18948. {
  18949. sscanf(buf, "result: %d", &systemresult);
  18950. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18951. }
  18952. }
  18953. pclose(phpFP);
  18954. }
  18955. }
  18956. if(systemresult != 1)
  18957. {
  18958. DEBUG_WARN("PHP PUT upload fail.\n");
  18959. return FALSE;
  18960. }
  18961. return TRUE;
  18962. }
  18963. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18964. {
  18965. int result = FALSE;
  18966. char ftpbuf[200];
  18967. int systemresult;
  18968. /*
  18969. // Domaind name transfer to IP address
  18970. struct hostent* server;
  18971. char *IPbuffer;
  18972. server = gethostbyname(location);
  18973. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18974. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18975. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18976. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18977. systemresult = system(ftpbuf);
  18978. if(systemresult != 0)
  18979. {
  18980. DEBUG_INFO("ftpput error!\n");
  18981. }
  18982. else
  18983. {
  18984. result = TRUE;
  18985. DEBUG_INFO("ftpput OK!\n");
  18986. }
  18987. return result;
  18988. }
  18989. //=========================================
  18990. // Routine
  18991. //=========================================
  18992. int GetOcppServerURL()
  18993. {
  18994. int result = FALSE;
  18995. struct yuarel url;
  18996. char urlStr[512];
  18997. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18998. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18999. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19000. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  19001. {
  19002. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  19003. if(yuarel_parse(&url, urlStr) != -1)
  19004. {
  19005. sprintf(OcppProtocol, "%s", url.scheme);
  19006. sprintf(OcppHost, "%s", url.host);
  19007. if(url.path == NULL)
  19008. OcppTempPath[0] = '\0';
  19009. else
  19010. sprintf(OcppTempPath, "%s", url.path);
  19011. if(url.port == 0)
  19012. {
  19013. if(strcmp(OcppProtocol, "wss") == 0)
  19014. OcppPort = 443;
  19015. else
  19016. OcppPort = 80;
  19017. }
  19018. else
  19019. OcppPort = url.port;
  19020. result = TRUE;
  19021. }
  19022. }
  19023. else
  19024. {
  19025. strcpy(OcppHost,"");
  19026. }
  19027. return result;
  19028. }
  19029. int GetOcppPath()
  19030. {
  19031. int result = FALSE;
  19032. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19033. {
  19034. if(OcppTempPath == NULL)
  19035. {
  19036. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19037. }
  19038. else
  19039. {
  19040. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19041. }
  19042. result = TRUE;
  19043. }
  19044. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  19045. {
  19046. if(OcppTempPath == NULL)
  19047. {
  19048. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  19049. }
  19050. else
  19051. {
  19052. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  19053. }
  19054. result = TRUE;
  19055. }
  19056. else
  19057. {
  19058. strcpy(OcppPath,"");
  19059. }
  19060. return result;
  19061. }
  19062. int GetOcppPort()
  19063. {
  19064. return OcppPort;
  19065. }
  19066. int GetOcppConnStatus(void)
  19067. {
  19068. return ShmOCPP20Data->OcppConnStatus;
  19069. }
  19070. void SetOcppConnStatus(uint8_t status)
  19071. {
  19072. ShmOCPP20Data->OcppConnStatus = status;
  19073. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19074. }
  19075. int GetHeartBeatWithNOResponse(void)
  19076. {
  19077. return HeartBeatWithNOResponse;
  19078. }
  19079. void SetHeartBeatWithNOResponse(void)
  19080. {
  19081. HeartBeatWithNOResponse = 0;
  19082. }
  19083. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19084. void storeTempStopTransaction(int gun_index)
  19085. {
  19086. char TempStopTransaction[256];
  19087. //char message[1024*20]={0};
  19088. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  19089. char guid[37]={0};
  19090. json_object *TransactionEvent = json_object_new_object();
  19091. json_object *transactionInfo = json_object_new_object();
  19092. json_object *idToken = json_object_new_object();
  19093. json_object *evse = json_object_new_object();
  19094. json_object *meterValues = json_object_new_array();
  19095. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  19096. DEBUG_INFO("storeTempStopTransaction...\n");
  19097. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  19098. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  19099. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  19100. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  19101. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  19102. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  19103. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  19104. // Message
  19105. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  19106. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  19107. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  19108. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  19109. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  19110. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  19111. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  19112. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  19113. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  19114. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  19115. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  19116. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  19117. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  19118. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  19119. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  19120. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  19121. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  19122. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  19123. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  19124. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  19125. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  19126. {
  19127. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  19128. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  19129. json_object_object_add(TransactionEvent, "idToken", idToken);
  19130. }
  19131. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  19132. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  19133. json_object_object_add(TransactionEvent, "evse", evse);
  19134. meterValueBufferQuery(gun_index, meterValues);
  19135. if(json_object_array_length(meterValues) > 0)
  19136. {
  19137. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  19138. }
  19139. random_uuid(guid);
  19140. sprintf(queuedata,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  19141. , guid
  19142. , "TransactionEvent"
  19143. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  19144. json_object_put(TransactionEvent);
  19145. // open file for writing
  19146. FILE *outfile;
  19147. outfile = fopen (TempStopTransaction, "w+");
  19148. //DEBUG_INFO("data = %s\n", queuedata);
  19149. fputs(queuedata, outfile);
  19150. fputs("\n", outfile);
  19151. fclose (outfile);
  19152. }
  19153. void checkTempStopTransaction(int gun_index)
  19154. {
  19155. FILE *fptr1;
  19156. char ch;
  19157. char str[QUEUE_MESSAGE_LENGTH]={0};
  19158. char guid[37]={0};
  19159. char tempdata[65]={0};
  19160. char TempStopTransaction[256];
  19161. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  19162. fptr1 = fopen(TempStopTransaction, "r");
  19163. if (!fptr1)
  19164. {
  19165. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  19166. return ;
  19167. }
  19168. ch=fgetc(fptr1);
  19169. rewind(fptr1);
  19170. if(ch!=EOF)
  19171. {
  19172. // copy all contents to the temporary file except the specific line
  19173. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19174. {
  19175. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19176. if(str[0]=='\0')
  19177. {
  19178. break;
  19179. }
  19180. strncpy(guid, str+4, 36); //copy guid
  19181. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  19182. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19183. {
  19184. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19185. }
  19186. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19187. memset(str,0,ARRAY_SIZE(str));
  19188. }
  19189. }
  19190. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19191. fclose(fptr1);
  19192. remove(TempStopTransaction); // remove the original file
  19193. }
  19194. int GetWebSocketPingInterval(void)
  19195. {
  19196. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  19197. }
  19198. int GetServerSign(void)
  19199. {
  19200. return server_sign;
  19201. }
  19202. uint8_t GetOcppSecurityProfile()
  19203. {
  19204. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  19205. }
  19206. void MergeCertificates()
  19207. {
  19208. char cmdBuf[2048]={0};
  19209. if(access(ROOTCA_CS,F_OK) != -1)
  19210. {
  19211. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  19212. }
  19213. else
  19214. {
  19215. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  19216. }
  19217. system(cmdBuf);
  19218. }
  19219. void GetOcppChargerBoxId(uint8_t *data)
  19220. {
  19221. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19222. }
  19223. void GetOcppSecurityPassword(uint8_t *data)
  19224. {
  19225. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  19226. }
  19227. void SetServerSign(int value)
  19228. {
  19229. server_sign = value;
  19230. }
  19231. int GetBootNotificationInterval(void)
  19232. {
  19233. return BootNotificationInterval;
  19234. }
  19235. int GetInternetConn(void)
  19236. {
  19237. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19238. }
  19239. int GetBackendConnectionTimeout(void)
  19240. {
  19241. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19242. }
  19243. int isConnectorInitMode(int gun_index)
  19244. {
  19245. int tempIndex = 0;
  19246. int result = TRUE;
  19247. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19248. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19249. {
  19250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19251. {
  19252. tempIndex = ((gun_index==2) ? 1: 0);
  19253. }
  19254. else
  19255. {
  19256. tempIndex = gun_index;
  19257. }
  19258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19259. {
  19260. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  19261. {
  19262. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19263. } //end of the same index
  19264. }//end of for CHAdeMO_QUANTITY
  19265. }
  19266. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19267. {
  19268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19269. {
  19270. tempIndex = ((gun_index==2) ? 1: 0);
  19271. }
  19272. else
  19273. {
  19274. tempIndex = gun_index;
  19275. }
  19276. for (int index = 0; index < CCS_QUANTITY; index++)
  19277. {
  19278. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19279. {
  19280. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19281. } //end of the same index
  19282. } // end of for CCS_QUANTITY
  19283. }
  19284. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19285. {
  19286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19287. {
  19288. tempIndex = ((gun_index==2) ? 1: 0);
  19289. }
  19290. else
  19291. {
  19292. tempIndex = gun_index;
  19293. }
  19294. for (int index = 0; index < GB_QUANTITY; index++)
  19295. {
  19296. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19297. {
  19298. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19299. } //end of the same index
  19300. } // end of for GB_QUANTITY
  19301. }
  19302. else if(gunType[gun_index] == GUN_TYPE_DO)
  19303. {
  19304. tempIndex = gun_index;
  19305. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19306. {
  19307. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19308. {
  19309. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19310. } //end of the same index
  19311. }
  19312. }
  19313. else
  19314. {
  19315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19316. {
  19317. tempIndex = 2;
  19318. }
  19319. else
  19320. {
  19321. tempIndex = gun_index;
  19322. }
  19323. for (int index = 0; index < AC_QUANTITY; index++)
  19324. {
  19325. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19326. {
  19327. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19328. }//end of the same index
  19329. }//end of for AC_QUANTITY
  19330. }
  19331. return result;
  19332. }
  19333. void refreshProcDogTimer()
  19334. {
  19335. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  19336. }
  19337. void InitialSystemValue(void)
  19338. {
  19339. localversion=0;
  19340. BootNotificationInterval = 10;
  19341. authorizeRetryTimes = 0;
  19342. GunStatusInterval = 10;
  19343. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  19344. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  19345. //Heart Beat
  19346. HeartBeatWithNOResponse = 0;
  19347. HeartBeatCountPerHour = 0;
  19348. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  19349. if(HeartBeatWaitTime == 0)
  19350. FirstHeartBeat = TRUE;
  19351. else
  19352. FirstHeartBeat = FALSE;
  19353. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  19354. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  19355. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19356. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19357. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19358. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19359. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19360. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19361. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19362. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19363. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19364. //Status && ConnectorPlugIn Setting
  19365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19366. {
  19367. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19368. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19369. }
  19370. for (int index = 0; index < CCS_QUANTITY; index++)
  19371. {
  19372. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19373. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19374. }
  19375. for (int index = 0; index < GB_QUANTITY; index++)
  19376. {
  19377. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19378. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19379. }
  19380. for (int index = 0; index < AC_QUANTITY; index++)
  19381. {
  19382. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19383. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19384. }
  19385. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19386. {
  19387. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19388. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19389. }
  19390. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19391. {
  19392. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  19393. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  19394. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  19395. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19396. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  19397. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  19398. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  19399. }
  19400. refreshStartTimer(&clientTime.Heartbeat);
  19401. sleep(1);
  19402. }
  19403. void LWS_Send(char *str)
  19404. {
  19405. //=====================================================
  19406. // Check InternetConn 0: disconnected, 1: connected
  19407. //====================================================
  19408. if(GetOcppConnStatus() == 0)
  19409. {
  19410. DEBUG_INFO("offline now !!!\n");
  19411. return;
  19412. }
  19413. // Only disable isWebsocketSendable operation initiated by charger
  19414. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19415. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19416. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  19417. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19418. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19419. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  19420. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  19421. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19422. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19423. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19424. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  19425. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  19426. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  19427. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  19428. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  19429. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  19430. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  19431. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  19432. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  19433. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  19434. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  19435. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19436. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19437. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19438. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  19439. {
  19440. isWebsocketSendable = OFF;
  19441. }
  19442. pthread_mutex_lock(&lock_send);
  19443. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19444. sprintf((char *)SendBuffer, "%s", str);
  19445. SendBufLen = strlen(str);
  19446. pthread_mutex_unlock(&lock_send);
  19447. lws_callback_on_writable(wsi_client);
  19448. //lws_service(context, 0);
  19449. //sleep(1);
  19450. }
  19451. void LWS_SendNow(char *str)
  19452. {
  19453. //=====================================================
  19454. // Check InternetConn 0: disconnected, 1: connected
  19455. //====================================================
  19456. if(GetOcppConnStatus() == 0)
  19457. {
  19458. DEBUG_INFO("offline now !!!\n");
  19459. return;
  19460. }
  19461. // Only disable isWebsocketSendable operation initiated by charger
  19462. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19463. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19464. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  19465. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19466. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19467. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  19468. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  19469. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19470. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19471. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19472. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  19473. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  19474. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  19475. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  19476. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  19477. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  19478. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  19479. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  19480. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  19481. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  19482. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  19483. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19484. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19485. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19486. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  19487. {
  19488. isWebsocketSendable = OFF;
  19489. }
  19490. pthread_mutex_lock(&lock_send);
  19491. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19492. sprintf((char *)SendBuffer, "%s", str);
  19493. SendBufLen = strlen(str);
  19494. pthread_mutex_unlock(&lock_send);
  19495. lws_callback_on_writable(wsi_client);
  19496. lws_service(context, 0);
  19497. //sleep(1);
  19498. }