MessageHandler.c 793 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938
  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. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  28. MACROSTR(Accepted),
  29. MACROSTR(SignatureError),
  30. MACROSTR(CertificateExpired),
  31. MACROSTR(CertificateRevoked),
  32. MACROSTR(NoCertificateAvailable),
  33. MACROSTR(CertChainError),
  34. MACROSTR(ContractCancelled)
  35. };
  36. static char *BootReasonEnumTypeStr[] = {
  37. MACROSTR(ApplicationReset),
  38. MACROSTR(FirmwareUpdate),
  39. MACROSTR(LocalReset),
  40. MACROSTR(PowerUp),
  41. MACROSTR(RemoteReset),
  42. MACROSTR(ScheduledReset),
  43. MACROSTR(Triggered),
  44. MACROSTR(Unknown),
  45. MACROSTR(Watchdog)
  46. };
  47. static char *CancelReservationStatusEnumTypeStr[] = {
  48. MACROSTR(Accepted),
  49. MACROSTR(Rejected)
  50. };
  51. static char *CertificateActionEnumTypeStr[] = {
  52. MACROSTR(Install),
  53. MACROSTR(Update)
  54. };
  55. static char *CertificateSignedStatusEnumTypeStr[] = {
  56. MACROSTR(Accepted),
  57. MACROSTR(Rejected)
  58. };
  59. static char *CertificateSigningUseEnumTypeStr[] = {
  60. MACROSTR(ChargingStationCertificate),
  61. MACROSTR(V2GCertificate)
  62. };
  63. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  64. MACROSTR(Accepted),
  65. MACROSTR(Rejected),
  66. MACROSTR(Scheduled)
  67. };
  68. static char *ChargingLimitSourceEnumTypeStr[] = {
  69. MACROSTR(EMS),
  70. MACROSTR(Other),
  71. MACROSTR(SO),
  72. MACROSTR(CSO)
  73. };
  74. static char *ChargingProfileKindEnumTypeStr[] = {
  75. MACROSTR(Absolute),
  76. MACROSTR(Recurring),
  77. MACROSTR(Relative)
  78. };
  79. static char *ChargingProfilePurposeEnumTypeStr[] = {
  80. MACROSTR(ChargingStationExternalConstraints),
  81. MACROSTR(ChargingStationMaxProfile),
  82. MACROSTR(TxDefaultProfile),
  83. MACROSTR(TxProfile)
  84. };
  85. static char *ChargingProfileStatusEnumTypeStr[] = {
  86. MACROSTR(Accepted),
  87. MACROSTR(Rejected)
  88. };
  89. static char *ChargingRateUnitEnumTypeStr[] = {
  90. MACROSTR(W),
  91. MACROSTR(A)
  92. };
  93. static char *ChargingStateEnumTypeStr[] = {
  94. MACROSTR(Charging),
  95. MACROSTR(EVConnected),
  96. MACROSTR(SuspendedEV),
  97. MACROSTR(SuspendedEVSE),
  98. MACROSTR(Idle)
  99. };
  100. static char *ClearCacheStatusEnumTypeStr[] = {
  101. MACROSTR(Accepted),
  102. MACROSTR(Rejected)
  103. };
  104. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  105. MACROSTR(Accepted),
  106. MACROSTR(Unknown)
  107. };
  108. static char *ClearMessageStatusEnumTypeStr[] = {
  109. MACROSTR(Accepted),
  110. MACROSTR(Unknown)
  111. };
  112. static char *ClearMonitoringStatusEnumTypeStr[] = {
  113. MACROSTR(Accepted),
  114. MACROSTR(Rejected),
  115. MACROSTR(NotFound)
  116. };
  117. static char *ComponentCriterionEnumTypeStr[] = {
  118. MACROSTR(Active),
  119. MACROSTR(Available),
  120. MACROSTR(Enabled),
  121. MACROSTR(Problem)
  122. };
  123. static char *ConnectorEnumTypeStr[] = {
  124. MACROSTR(cCCS1),
  125. MACROSTR(cCCS2),
  126. MACROSTR(cG105),
  127. MACROSTR(cTesla),
  128. MACROSTR(cType1),
  129. MACROSTR(cType2),
  130. MACROSTR(s309-1P-16A),
  131. MACROSTR(s309-1P-32A),
  132. MACROSTR(s309-3P-16A),
  133. MACROSTR(s309-3P-32A),
  134. MACROSTR(sBS1361),
  135. MACROSTR(sCEE-7-7),
  136. MACROSTR(sType2),
  137. MACROSTR(sType3),
  138. MACROSTR(Other1PhMax16A),
  139. MACROSTR(Other1PhOver16A),
  140. MACROSTR(Other3Ph),
  141. MACROSTR(Pan),
  142. MACROSTR(wInductive),
  143. MACROSTR(wResonant),
  144. MACROSTR(Undetermined),
  145. MACROSTR(Unknown)
  146. };
  147. static char *ConnectorStatusEnumTypeStr[] = {
  148. MACROSTR(Available),
  149. MACROSTR(Occupied),
  150. MACROSTR(Reserved),
  151. MACROSTR(Unavailable),
  152. MACROSTR(Faulted)
  153. };
  154. static char *CostKindEnumTypeStr[] = {
  155. MACROSTR(CarbonDioxideEmission),
  156. MACROSTR(RelativePricePercentage),
  157. MACROSTR(RenewableGenerationPercentage)
  158. };
  159. static char *CustomerInformationStatusEnumTypeStr[] = {
  160. MACROSTR(Accepted),
  161. MACROSTR(Rejected),
  162. MACROSTR(Invalid)
  163. };
  164. static char *DataEnumTypeStr[] = {
  165. MACROSTR(string),
  166. MACROSTR(decimal),
  167. MACROSTR(integer),
  168. MACROSTR(dateTime),
  169. MACROSTR(boolean),
  170. MACROSTR(OptionList),
  171. MACROSTR(SequenceList),
  172. MACROSTR(MemberList)
  173. };
  174. static char *DataTransferStatusEnumTypeStr[] = {
  175. MACROSTR(Accepted),
  176. MACROSTR(Rejected),
  177. MACROSTR(UnknownMessageId),
  178. MACROSTR(UnknownVendorId)
  179. };
  180. static char *DeleteCertificateStatusEnumTypeStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Failed),
  183. MACROSTR(NotFound)
  184. };
  185. static char *DisplayMessageStatusEnumTypeStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(NotSupportedMessageFormat),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupportedPriority),
  190. MACROSTR(NotSupportedState),
  191. MACROSTR(UnknownTransaction)
  192. };
  193. static char *EnergyTransferModeEnumTypeStr[] = {
  194. MACROSTR(DC),
  195. MACROSTR(AC_single_phase),
  196. MACROSTR(AC_two_phase),
  197. MACROSTR(AC_three_phase)
  198. };
  199. static char *EventNotificationEnumTypeStr[] = {
  200. MACROSTR(HardWiredNotification),
  201. MACROSTR(HardWiredMonitor),
  202. MACROSTR(PreconfiguredMonitor),
  203. MACROSTR(CustomMonitor)
  204. };
  205. static char *EventTriggerEnumTypeStr[] = {
  206. MACROSTR(Alerting),
  207. MACROSTR(Delta),
  208. MACROSTR(Periodic)
  209. };
  210. static char *FirmwareStatusEnumTypeStr[] = {
  211. MACROSTR(Downloaded),
  212. MACROSTR(DownloadFailed),
  213. MACROSTR(Downloading),
  214. MACROSTR(DownloadScheduled),
  215. MACROSTR(DownloadPaused),
  216. MACROSTR(Idle),
  217. MACROSTR(InstallationFailed),
  218. MACROSTR(Installing),
  219. MACROSTR(Installed),
  220. MACROSTR(InstallRebooting),
  221. MACROSTR(InstallScheduled),
  222. MACROSTR(InstallVerificationFailed),
  223. MACROSTR(InvalidSignature),
  224. MACROSTR(SignatureVerified)
  225. };
  226. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  227. MACROSTR(Accepted),
  228. MACROSTR(Rejected),
  229. MACROSTR(NotSupported),
  230. MACROSTR(EmptyResultSet)
  231. };
  232. static char *GenericStatusEnumTypeStr[] = {
  233. MACROSTR(Accepted),
  234. MACROSTR(Rejected)
  235. };
  236. static char *GetCertificateIdUseEnumTypeStr[] = {
  237. MACROSTR(V2GRootCertificate),
  238. MACROSTR(MORootCertificate),
  239. MACROSTR(CSMSRootCertificate),
  240. MACROSTR(V2GCertificateChain),
  241. MACROSTR(ManufacturerRootCertificate)
  242. };
  243. static char *GetCertificateStatusEnumTypeStr[] = {
  244. MACROSTR(Accepted),
  245. MACROSTR(Failed)
  246. };
  247. static char *GetChargingProfileStatusEnumTypeStr[] = {
  248. MACROSTR(Accepted),
  249. MACROSTR(NoProfiles)
  250. };
  251. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Unknown)
  254. };
  255. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  256. MACROSTR(Accepted),
  257. MACROSTR(NotFound)
  258. };
  259. static char *GetVariableStatusEnumTypeStr[] = {
  260. MACROSTR(Accepted),
  261. MACROSTR(Rejected),
  262. MACROSTR(UnknownComponent),
  263. MACROSTR(UnknownVariable),
  264. MACROSTR(NotSupportedAttributeType)
  265. };
  266. static char *HashAlgorithmEnumTypeStr[] = {
  267. MACROSTR(SHA256),
  268. MACROSTR(SHA384),
  269. MACROSTR(SHA512)
  270. };
  271. static char *IdTokenEnumTypeStr[] = {
  272. MACROSTR(Central),
  273. MACROSTR(eMAID),
  274. MACROSTR(ISO14443),
  275. MACROSTR(KeyCode),
  276. MACROSTR(Local),
  277. MACROSTR(NoAuthorization),
  278. MACROSTR(ISO15693)
  279. };
  280. static char *InstallCertificateUseEnumTypeStr[] = {
  281. MACROSTR(V2GRootCertificate),
  282. MACROSTR(MORootCertificate),
  283. MACROSTR(CSMSRootCertificate),
  284. MACROSTR(ManufacturerRootCertificate)
  285. };
  286. static char *InstallCertificateStatusEnumTypeStr[]={
  287. MACROSTR(Accepted),
  288. MACROSTR(Failed),
  289. MACROSTR(Rejected)
  290. };
  291. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  292. MACROSTR(Accepted),
  293. MACROSTR(Failed)
  294. };
  295. static char *LocationEnumTypeStr[] = {
  296. MACROSTR(Body),
  297. MACROSTR(Cable),
  298. MACROSTR(EV),
  299. MACROSTR(Inlet),
  300. MACROSTR(Outlet)
  301. };
  302. static char *LogEnumTypeStr[] = {
  303. MACROSTR(DiagnosticsLog),
  304. MACROSTR(SecurityLog)
  305. };
  306. static char *LogStatusEnumTypeStr[] = {
  307. MACROSTR(Accepted),
  308. MACROSTR(Rejected),
  309. MACROSTR(AcceptedCanceled)
  310. };
  311. static char *MeasurandEnumTypeStr[] = {
  312. MACROSTR(Current.Export),
  313. MACROSTR(Current.Import),
  314. MACROSTR(Current.Offered),
  315. MACROSTR(Energy.Active.Export.Register),
  316. MACROSTR(Energy.Active.Import.Register),
  317. MACROSTR(Energy.Reactive.Export.Register),
  318. MACROSTR(Energy.Reactive.Import.Register),
  319. MACROSTR(Energy.Active.Export.Interval),
  320. MACROSTR(Energy.Active.Import.Interval),
  321. MACROSTR(Energy.Active.Net),
  322. MACROSTR(Energy.Reactive.Export.Interval),
  323. MACROSTR(Energy.Reactive.Import.Interval),
  324. MACROSTR(Energy.Reactive.Net),
  325. MACROSTR(Energy.Apparent.Net),
  326. MACROSTR(Energy.Apparent.Import),
  327. MACROSTR(Energy.Apparent.Export),
  328. MACROSTR(Frequency),
  329. MACROSTR(Power.Active.Export),
  330. MACROSTR(Power.Active.Import),
  331. MACROSTR(Power.Factor),
  332. MACROSTR(Power.Offered),
  333. MACROSTR(Power.Reactive.Export),
  334. MACROSTR(Power.Reactive.Import),
  335. MACROSTR(SoC),
  336. MACROSTR(Voltage)
  337. };
  338. static char *MessageFormatEnumTypeStr[] = {
  339. MACROSTR(ASCII),
  340. MACROSTR(HTML),
  341. MACROSTR(URI),
  342. MACROSTR(UTF8)
  343. };
  344. static char *MessagePriorityEnumTypeStr[] = {
  345. MACROSTR(AlwaysFront),
  346. MACROSTR(InFront),
  347. MACROSTR(NormalCycle)
  348. };
  349. static char *MessageStateEnumTypeStr[] = {
  350. MACROSTR(Charging),
  351. MACROSTR(Faulted),
  352. MACROSTR(Idle),
  353. MACROSTR(Unavailable)
  354. };
  355. static char *MessageTriggerEnumTypeStr[] = {
  356. MACROSTR(BootNotification),
  357. MACROSTR(LogStatusNotification),
  358. MACROSTR(FirmwareStatusNotification),
  359. MACROSTR(Heartbeat),
  360. MACROSTR(MeterValues),
  361. MACROSTR(SignChargingStationCertificate),
  362. MACROSTR(SignV2GCertificate),
  363. MACROSTR(StatusNotification),
  364. MACROSTR(TransactionEvent),
  365. MACROSTR(SignCombinedCertificate),
  366. MACROSTR(PublishFirmwareStatusNotification)
  367. };
  368. static char *MonitorEnumTypeStr[] = {
  369. MACROSTR(UpperThreshold),
  370. MACROSTR(LowerThreshold),
  371. MACROSTR(Delta),
  372. MACROSTR(Periodic),
  373. MACROSTR(PeriodicClockAligned)
  374. };
  375. static char *MonitoringBaseEnumTypeStr[] = {
  376. MACROSTR(All),
  377. MACROSTR(FactoryDefault),
  378. MACROSTR(HardWiredOnly)
  379. };
  380. static char *MonitoringCriterionEnumTypeStr[] = {
  381. MACROSTR(ThresholdMonitoring),
  382. MACROSTR(DeltaMonitoring),
  383. MACROSTR(PeriodicMonitoring)
  384. };
  385. static char *MutabilityEnumTypeStr[] = {
  386. MACROSTR(ReadOnly),
  387. MACROSTR(WriteOnly),
  388. MACROSTR(ReadWrite)
  389. };
  390. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  391. MACROSTR(Accepted),
  392. MACROSTR(Rejected),
  393. MACROSTR(Processing)
  394. };
  395. static char *OCPPInterfaceEnumTypeStr[] = {
  396. MACROSTR(Wired0),
  397. MACROSTR(Wired1),
  398. MACROSTR(Wired2),
  399. MACROSTR(Wired3),
  400. MACROSTR(Wireless0),
  401. MACROSTR(Wireless1),
  402. MACROSTR(Wireless2),
  403. MACROSTR(Wireless3)
  404. };
  405. static char *OCPPTransportEnumTypeStr[] = {
  406. MACROSTR(JSON),
  407. MACROSTR(SOAP)
  408. };
  409. static char *OCPPVersionEnumTypeStr[] = {
  410. MACROSTR(OCPP12),
  411. MACROSTR(OCPP15),
  412. MACROSTR(OCPP16),
  413. MACROSTR(OCPP20)
  414. };
  415. static char *OperationalStatusEnumTypeStr[] = {
  416. MACROSTR(Inoperative),
  417. MACROSTR(Operative)
  418. };
  419. static char *PhaseEnumTypeStr[] = {
  420. MACROSTR(L1),
  421. MACROSTR(L2),
  422. MACROSTR(L3),
  423. MACROSTR(N),
  424. MACROSTR(L1-N),
  425. MACROSTR(L2-N),
  426. MACROSTR(L3-N),
  427. MACROSTR(L1-L2),
  428. MACROSTR(L2-L3),
  429. MACROSTR(L3-L1)
  430. };
  431. static char *PublishFirmwareStatusEnumTypeStr[] = {
  432. MACROSTR(Downloaded),
  433. MACROSTR(DownloadFailed),
  434. MACROSTR(Downloading),
  435. MACROSTR(DownloadScheduled),
  436. MACROSTR(DownloadPaused),
  437. MACROSTR(PublishFailed),
  438. MACROSTR(Published),
  439. MACROSTR(InvalidChecksum),
  440. MACROSTR(ChecksumVerified)
  441. };
  442. static char *ReadingContextEnumTypeStr[] = {
  443. MACROSTR(Interruption.Begin),
  444. MACROSTR(Interruption.End),
  445. MACROSTR(Other),
  446. MACROSTR(Sample.Clock),
  447. MACROSTR(Sample.Periodic),
  448. MACROSTR(Transaction.Begin),
  449. MACROSTR(Transaction.End),
  450. MACROSTR(Trigger)
  451. };
  452. static char *ReasonEnumTypeStr[] = {
  453. MACROSTR(DeAuthorized),
  454. MACROSTR(EmergencyStop),
  455. MACROSTR(EnergyLimitReached),
  456. MACROSTR(EVDisconnected),
  457. MACROSTR(GroundFault),
  458. MACROSTR(ImmediateReset),
  459. MACROSTR(Local),
  460. MACROSTR(LocalOutOfCredit),
  461. MACROSTR(MasterPass),
  462. MACROSTR(Other),
  463. MACROSTR(OvercurrentFault),
  464. MACROSTR(PowerLoss),
  465. MACROSTR(PowerQuality),
  466. MACROSTR(Reboot),
  467. MACROSTR(Remote),
  468. MACROSTR(SOCLimitReached),
  469. MACROSTR(StoppedByEV),
  470. MACROSTR(TimeLimitReached),
  471. MACROSTR(TimeLimitReached)
  472. };
  473. static char *RecurrencyKindEnumTypeStr[] = {
  474. MACROSTR(Daily),
  475. MACROSTR(Weekly)
  476. };
  477. static char *RegistrationStatusEnumTypeStr[] = {
  478. MACROSTR(Accepted),
  479. MACROSTR(Pending),
  480. MACROSTR(Rejected)
  481. };
  482. static char *ReportBaseEnumTypeStr[] = {
  483. MACROSTR(ConfigurationInventory),
  484. MACROSTR(FullInventory),
  485. MACROSTR(SummaryInventory)
  486. };
  487. static char *RequestStartStopStatusEnumTypeStr[] = {
  488. MACROSTR(Accepted),
  489. MACROSTR(Rejected)
  490. };
  491. static char *ReservationUpdateStatusEnumTypeStr[] = {
  492. MACROSTR(Expired),
  493. MACROSTR(Removed)
  494. };
  495. static char *ReserveNowStatusEnumTypeStr[] = {
  496. MACROSTR(Accepted),
  497. MACROSTR(Faulted),
  498. MACROSTR(Occupied),
  499. MACROSTR(Rejected),
  500. MACROSTR(Unavailable)
  501. };
  502. static char *ResetEnumTypeStr[] = {
  503. MACROSTR(Immediate),
  504. MACROSTR(OnIdle)
  505. };
  506. static char *ResetStatusEnumTypeStr[] = {
  507. MACROSTR(Accepted),
  508. MACROSTR(Rejected),
  509. MACROSTR(Scheduled)
  510. };
  511. static char *SetMonitoringStatusEnumTypeStr[] = {
  512. MACROSTR(Accepted),
  513. MACROSTR(UnknownComponent),
  514. MACROSTR(UnknownVariable),
  515. MACROSTR(UnsupportedMonitorType),
  516. MACROSTR(Rejected),
  517. MACROSTR(OutOfRange),
  518. MACROSTR(Duplicate)
  519. };
  520. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  521. MACROSTR(Accepted),
  522. MACROSTR(Rejected),
  523. MACROSTR(Failed)
  524. };
  525. static char *SetVariableStatusEnumTypeStr[] = {
  526. MACROSTR(Accepted),
  527. MACROSTR(Rejected),
  528. MACROSTR(InvalidValue),
  529. MACROSTR(UnknownComponent),
  530. MACROSTR(UnknownVariable),
  531. MACROSTR(NotSupportedAttributeType),
  532. MACROSTR(OutOfRange),
  533. MACROSTR(RebootRequired)
  534. };
  535. static char *TransactionEventEnumTypeStr[] = {
  536. MACROSTR(Ended),
  537. MACROSTR(Started),
  538. MACROSTR(Updated)
  539. };
  540. static char *TriggerMessageStatusEnumTypeStr[] = {
  541. MACROSTR(Accepted),
  542. MACROSTR(Rejected),
  543. MACROSTR(NotImplemented)
  544. };
  545. static char *TriggerReasonEnumTypeStr[] = {
  546. MACROSTR(Authorized),
  547. MACROSTR(CablePluggedIn),
  548. MACROSTR(ChargingRateChanged),
  549. MACROSTR(ChargingStateChanged),
  550. MACROSTR(Deauthorized),
  551. MACROSTR(EnergyLimitReached),
  552. MACROSTR(EVCommunicationLost),
  553. MACROSTR(EVConnectTimeout),
  554. MACROSTR(MeterValueClock),
  555. MACROSTR(MeterValuePeriodic),
  556. MACROSTR(TimeLimitReached),
  557. MACROSTR(Trigger),
  558. MACROSTR(UnlockCommand),
  559. MACROSTR(StopAuthorized),
  560. MACROSTR(EVDeparted),
  561. MACROSTR(EVDetected),
  562. MACROSTR(RemoteStop),
  563. MACROSTR(RemoteStart),
  564. MACROSTR(AbnormalCondition),
  565. MACROSTR(SignedDataReceived),
  566. MACROSTR(ResetCommand)
  567. };
  568. static char *UnlockStatusEnumTypeStr[] = {
  569. MACROSTR(Unlocked),
  570. MACROSTR(UnlockFailed),
  571. MACROSTR(OngoingAuthorizedTransaction),
  572. MACROSTR(UnknownConnector)
  573. };
  574. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  575. MACROSTR(DownloadOngoing),
  576. MACROSTR(NoFirmware),
  577. MACROSTR(Unpublished)
  578. };
  579. static char *UpdateEnumTypeStr[] = {
  580. MACROSTR(Differential),
  581. MACROSTR(Full)
  582. };
  583. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  584. MACROSTR(Accepted),
  585. MACROSTR(Rejected),
  586. MACROSTR(AcceptedCanceled),
  587. MACROSTR(InvalidCertificate),
  588. MACROSTR(RevokedCertificate)
  589. };
  590. static char *UpdateStatusEnumTypeStr[] = {
  591. MACROSTR(Accepted),
  592. MACROSTR(Failed),
  593. MACROSTR(VersionMismatch)
  594. };
  595. static char *UploadLogStatusEnumTypeStr[] = {
  596. MACROSTR(BadMessage),
  597. MACROSTR(Idle),
  598. MACROSTR(NotSupportedOperation),
  599. MACROSTR(PermissionDenied),
  600. MACROSTR(Uploaded),
  601. MACROSTR(UploadFailure),
  602. MACROSTR(Uploading)
  603. };
  604. static char *VPNEnumTypeStr[] = {
  605. MACROSTR(IKEv2),
  606. MACROSTR(IPSec),
  607. MACROSTR(L2TP),
  608. MACROSTR(PPTP)
  609. };
  610. #if 0
  611. static char *ChargePointErrorCodeEnumTypeStr[] = {
  612. MACROSTR(ConnectorLockFailure),
  613. MACROSTR(EVCommunicationError),
  614. MACROSTR(GroundFailure),
  615. MACROSTR(HighTemperature),
  616. MACROSTR(InternalError),
  617. MACROSTR(LocalListConflict),
  618. MACROSTR(NoError),
  619. MACROSTR(OtherError),
  620. MACROSTR(OverCurrentFailure),
  621. MACROSTR(OverVoltage),
  622. MACROSTR(PowerMeterFailure),
  623. MACROSTR(PowerSwitchFailure),
  624. MACROSTR(ReaderFailure),
  625. MACROSTR(ResetFailure),
  626. MACROSTR(UnderVoltage),
  627. MACROSTR(WeakSignal)
  628. };
  629. #endif
  630. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  631. MACROSTR(Accepted),
  632. MACROSTR(Rejected)
  633. };
  634. static char *RemoteStartStopStatusEnumTypeStr[] = {
  635. MACROSTR(Accepted),
  636. MACROSTR(Rejected)
  637. };
  638. static char *ReservationStatusEnumTypeStr[] = {
  639. MACROSTR(Accepted),
  640. MACROSTR(Faulted),
  641. MACROSTR(Occupied),
  642. MACROSTR(Rejected),
  643. MACROSTR(Unavailable)
  644. };
  645. #if 0
  646. static char * StopTransactionReasonEnumTypeStr[] = {
  647. MACROSTR(EmergencyStop),
  648. MACROSTR(EVDisconnected),
  649. MACROSTR(HardReset),
  650. MACROSTR(Local),
  651. MACROSTR(Other),
  652. MACROSTR(PowerLoss),
  653. MACROSTR(Reboot),
  654. MACROSTR(Remote),
  655. MACROSTR(SoftReset),
  656. MACROSTR(UnlockCommand),
  657. MACROSTR(DeAuthorized)
  658. };
  659. #endif
  660. //ChargePointMaxProfile
  661. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile_OCPP20.json"
  662. //TxDefaultProfile
  663. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  664. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  665. struct StatusCodeData *ShmStatusCodeData;
  666. struct PsuData *ShmPsuData ;
  667. struct OCPP20Data *ShmOCPP20Data;
  668. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  669. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  670. //===============================
  671. // Gun Total Numbers
  672. //===============================
  673. static int gunTotalNumber = 0;
  674. static uint8_t gunType[4] = {0};
  675. //===============================
  676. // Local List Version
  677. //===============================
  678. static int localversion=0;
  679. //===============================
  680. // OCPP sign variable
  681. //===============================
  682. static int server_sign = FALSE;
  683. int server_pending = FALSE;
  684. static int BootNotificationInterval = 10;
  685. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  686. //===============================
  687. // OCPP auth variable
  688. //===============================
  689. static int authorizeRetryTimes = 0; //number of Retry times
  690. //===============================
  691. // OCPP other variables
  692. //===============================
  693. static int HeartBeatWaitTime = 10;
  694. static int FirstHeartBeat = 0;
  695. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  696. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  697. static char CurrentChargingProfileScheduleStr[30] = {0};
  698. //========================================
  699. // OCPP status/previous related variables
  700. //========================================
  701. static int GunStatusInterval = 10;
  702. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  703. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  704. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  705. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  706. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  707. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  708. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  709. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  710. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  711. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  712. static int TransactionMessageAttemptsValue = 0;
  713. static int TransactionMessageRetryIntervalValue = 0;
  714. static int TempMeterValueInterval = 0;
  715. static struct AuthorizationData idTagQuery;
  716. //=============================================
  717. // OCPP HeartBeat Response Not Receive Counts
  718. //============================================
  719. static int HeartBeatWithNOResponse = 0;
  720. static int HeartBeatCountPerHour = 0;
  721. sqlite3 *db;
  722. int TransactionMessageAttemptsGet(void);
  723. int TransactionMessageRetryIntervalGet(void);
  724. int GetOcppConnStatus(void);
  725. void SetOcppConnStatus(uint8_t status);
  726. int setKeyValue(char *key, char *value);
  727. void OCPP_get_TableAuthlocalAllData(void);
  728. void processUnkownKey(void);
  729. struct StructOCPPMeterValue
  730. {
  731. unsigned char TimeStamp[28];
  732. struct StructSampledValue SampledValue[10];
  733. };
  734. struct ClientTime
  735. {
  736. unsigned int Heartbeat;
  737. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  738. unsigned int StartTransaction;
  739. unsigned int StopTransaction;
  740. unsigned int MeterValues[CONNECTOR_QUANTITY];
  741. }clientTime;
  742. typedef union
  743. {
  744. //Operations Initiated by Central System
  745. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  746. struct
  747. {
  748. //CsMsgValue[0]
  749. unsigned char StatusNotificationReq:1; //bit 0,
  750. unsigned char StatusNotificationConf:1; //bit 1,
  751. unsigned char TriggerMeterValueReq:1; //bit 2,
  752. unsigned char TransactionEventReq:1; //bit 3,
  753. unsigned char SampleMeterReq:1; //bit 4,
  754. unsigned char ClockAlignMeterReq:1; //bit 5,
  755. unsigned char :2;
  756. }bits[CONNECTOR_QUANTITY];
  757. }CpinitiateMsg;
  758. CpinitiateMsg cpinitateMsg;
  759. //=========================================
  760. // Date time related function
  761. //=========================================
  762. void getNowDatetime(uint8_t *data)
  763. {
  764. time_t t = time(NULL);
  765. struct tm tm = *localtime(&t);
  766. 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);
  767. }
  768. //=========================================
  769. // Sqlite3 related function
  770. //=========================================
  771. int DB_Initial()
  772. {
  773. int result = PASS;
  774. char* errMsg = NULL;
  775. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  776. "idToken text UNIQUE,"
  777. "type text,"
  778. "status text,"
  779. "cacheExpiryDateTime text,"
  780. "chargingPriority integer,"
  781. "language1 text,"
  782. "evseId text,"
  783. "language2 text,"
  784. "groupIdToken_idToken text,"
  785. "groupIdToken_type text,"
  786. "personalMessage text);";
  787. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  788. "idToken text UNIQUE,"
  789. "type text,"
  790. "status text,"
  791. "cacheExpiryDateTime text,"
  792. "chargingPriority integer,"
  793. "language1 text,"
  794. "evseId text,"
  795. "language2 text,"
  796. "groupIdToken_idToken text,"
  797. "groupIdToken_type text,"
  798. "personalMessage text,"
  799. "version text);";
  800. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  801. "componentName text NOT NULL ,"
  802. "componentInstance text, "
  803. "variableName text NOT NULL, "
  804. "variableInstance text, "
  805. "variableCharacteristicsDataType integer, "
  806. "variableCharacteristicsUnit text, "
  807. "variableCharacteristicsMaxLimit real,"
  808. "variableAttributesType text, "
  809. "variableAttributesTypeMutability text, "
  810. "variableAttributesTypeValue text, "
  811. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  812. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  813. "type text);";
  814. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  815. "slot integer UNIQUE, connectionData text);";
  816. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  817. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  818. {
  819. result = FAIL;
  820. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  821. sqlite3_close(db);
  822. }
  823. else
  824. {
  825. DEBUG_INFO( "OCPP local database open successfully.\n");
  826. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  827. {
  828. result = FAIL;
  829. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  830. }
  831. else
  832. {
  833. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  834. }
  835. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  836. {
  837. result = FAIL;
  838. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  839. }
  840. else
  841. {
  842. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  843. }
  844. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  845. {
  846. result = FAIL;
  847. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  848. }
  849. else
  850. {
  851. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  852. }
  853. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  854. {
  855. result = FAIL;
  856. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  857. }
  858. else
  859. {
  860. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  861. }
  862. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  863. {
  864. result = FAIL;
  865. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  866. }
  867. else
  868. {
  869. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  870. }
  871. //sqlite3_close(db);
  872. }
  873. return result;
  874. }
  875. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  876. {
  877. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  878. return 0;
  879. }
  880. void DB_getListVerion()
  881. {
  882. char sql[256];
  883. char* errMsg = NULL;
  884. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  885. /* Execute SQL statement */
  886. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  887. {
  888. DEBUG_INFO("SQL error: %s", errMsg);
  889. }
  890. }
  891. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  892. {
  893. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  894. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  895. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  896. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  897. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  898. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  899. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  900. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  901. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  902. return 0;
  903. }
  904. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  905. {
  906. char sql[256];
  907. char* errMsg = NULL;
  908. memset(&idTagQuery, 0, sizeof(idTagQuery));
  909. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  910. if(isQueryFromCache)
  911. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  912. else
  913. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  914. /* Execute SQL statement */
  915. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  916. {
  917. DEBUG_INFO("SQL error: %s", errMsg);
  918. }
  919. }
  920. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  921. {
  922. for (int i = 0; i < columnCount; i++)
  923. {
  924. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  925. }
  926. return 0;
  927. }
  928. void DB_get_TableAuthlocalAllData(void)
  929. {
  930. char sql[256];
  931. char* errMsg = NULL;
  932. sprintf(sql,"select * from ocpp20_auth_local;");
  933. /* Execute SQL statement */
  934. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  935. {
  936. DEBUG_INFO("SQL error: %s", errMsg);
  937. }
  938. }
  939. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  940. {
  941. for(int i = 0; i<columnCount; i++)
  942. {
  943. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  944. }
  945. return 0;
  946. }
  947. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  948. {
  949. int result = PASS;
  950. char sql[512];
  951. char* errMsg = NULL;
  952. 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;",
  953. data->idToken.idToken,
  954. data->idToken.type,
  955. data->idTokenInfo.status,
  956. data->idTokenInfo.cacheExpiryDateTime,
  957. data->idTokenInfo.chargingPriority,
  958. data->idTokenInfo.language1,
  959. data->idTokenInfo.language2,
  960. data->idTokenInfo.groupIdToken.idToken,
  961. data->idTokenInfo.groupIdToken.type,
  962. listVersion);
  963. //* Execute SQL statement */
  964. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  965. {
  966. DEBUG_INFO("SQL error: %s\n", errMsg);
  967. result = FAIL;
  968. }
  969. else
  970. {
  971. memset(sql, 0, ARRAY_SIZE(sql));
  972. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  973. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  974. {
  975. DEBUG_INFO("SQL error: %s\n", errMsg);
  976. result = FAIL;
  977. }
  978. }
  979. return result;
  980. }
  981. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  982. {
  983. int result = PASS;
  984. char sql[512];
  985. char* errMsg = NULL;
  986. 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;",
  987. idToken->idToken,
  988. idToken->type,
  989. idTokenInfo->status,
  990. idTokenInfo->cacheExpiryDateTime,
  991. idTokenInfo->chargingPriority,
  992. idTokenInfo->language1,
  993. idTokenInfo->language2,
  994. idTokenInfo->groupIdToken.idToken,
  995. idTokenInfo->groupIdToken.type);
  996. //* Execute SQL statement */
  997. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  998. {
  999. DEBUG_INFO("SQL error: %s\n", errMsg);
  1000. result = FAIL;
  1001. }
  1002. return result;
  1003. }
  1004. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1005. {
  1006. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1007. // printf("localversion=%d\n", localversion);
  1008. return 0;
  1009. }
  1010. void DB_deleteIdTag(char idTag[])
  1011. {
  1012. char sql[512];
  1013. char* errMsg = NULL;
  1014. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1015. //* Execute SQL statement */
  1016. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1017. {
  1018. DEBUG_INFO("SQL error: %s", errMsg);
  1019. }
  1020. }
  1021. int DB_cleanLocalList()
  1022. {
  1023. int result = PASS;
  1024. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1025. char *errMsg = 0;
  1026. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1027. {
  1028. DEBUG_INFO("%s\n", errMsg);
  1029. result = FAIL;
  1030. }
  1031. return result;
  1032. }
  1033. int DB_cleanLocalCache()
  1034. {
  1035. int result = PASS;
  1036. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1037. char *errMsg = 0;
  1038. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1039. {
  1040. DEBUG_INFO("%s\n", errMsg);
  1041. result = FAIL;
  1042. }
  1043. return result;
  1044. }
  1045. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1046. {
  1047. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1048. return 0;
  1049. }
  1050. void DB_getBooType()
  1051. {
  1052. char sql[256];
  1053. char* errMsg = NULL;
  1054. sprintf(sql,"select * from ocpp20_boot_type;");
  1055. /* Execute SQL statement */
  1056. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1057. {
  1058. DEBUG_INFO("SQL error: %s\n", errMsg);
  1059. }
  1060. }
  1061. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1062. {
  1063. for(int i = 0; i<columnCount; i++)
  1064. {
  1065. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1066. }
  1067. return 0;
  1068. }
  1069. int DB_updateBootType(BootReasonEnumType reason)
  1070. {
  1071. int result = PASS;
  1072. char sql[512];
  1073. char* errMsg = NULL;
  1074. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1075. //* Execute SQL statement */
  1076. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1077. {
  1078. DEBUG_INFO("SQL error: %s\n", errMsg);
  1079. result = FAIL;
  1080. }
  1081. return result;
  1082. }
  1083. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1084. {
  1085. for(int i = 0; i<columnCount; i++)
  1086. {
  1087. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1088. }
  1089. return 0;
  1090. }
  1091. int DB_variableSaveToDb(struct ReportDataType *variable)
  1092. {
  1093. int result = FAIL;
  1094. char sql[4096];
  1095. char* errMsg = NULL;
  1096. sprintf(sql,"insert or replace into ocpp20_variable (componentName, componentInstance, variableName, variableInstance, variableCharacteristicsDataType, variableCharacteristicsUnit, variableCharacteristicsMaxLimit, variableAttributesType, variableAttributesTypeMutability, variableAttributesTypeValue) VALUES('%s', '%s', '%s', '%s', '%s', '%s', %f, '%s', '%s', '%s'); SELECT * from ocpp20_variable;",
  1097. variable->component.name,
  1098. variable->component.instance,
  1099. variable->variable.name,
  1100. variable->variable.instance,
  1101. variable->variableCharacteristics.dataType,
  1102. variable->variableCharacteristics.unit,
  1103. variable->variableCharacteristics.maxLimit,
  1104. variable->variableAttribute[0].type,
  1105. variable->variableAttribute[0].mutability,
  1106. variable->variableAttribute[0].value);
  1107. //* Execute SQL statement */
  1108. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1109. {
  1110. DEBUG_INFO("SQL error: %s\n", errMsg);
  1111. result = FAIL;
  1112. }
  1113. return result;
  1114. }
  1115. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1116. {
  1117. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1118. if(atoi(columnValue[0]) == 0)
  1119. {
  1120. DB_updateBootType(BootReasonEnumType_PowerUp);
  1121. // Create variable table content
  1122. /* AlignedDataCtrlr Required item */
  1123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1129. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1136. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1142. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1144. else
  1145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1146. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1154. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "TRUE");
  1161. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1168. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1176. else
  1177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1178. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1186. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1187. /* AuthCtrlrVariable Required item */
  1188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1194. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  1196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1201. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "FALSE");
  1208. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "FALSE");
  1215. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE");
  1222. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE");
  1229. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1233. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1237. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1238. /* AuthCacheCtrlr Variable Required item*/
  1239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1245. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "TRUE");
  1252. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "TRUE");
  1260. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1264. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*100);
  1265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "TRUE");
  1268. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1275. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1276. /* ClockCtrlr Variable Required item */
  1277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1282. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1283. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1290. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1298. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1305. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1312. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1320. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1327. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1334. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1335. /* ChargingStation Required item */
  1336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "FALSE");
  1342. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1349. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1356. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1357. /* Connector Required item */
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "FALSE");
  1364. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1371. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1378. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1379. /* CustomizationCtrlr Required item */
  1380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "FALSE");
  1386. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1387. /* DeviceDataCtrlr Required item */
  1388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1395. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1403. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1411. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1419. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1422. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1427. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1430. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1435. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1443. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1451. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1452. /* DisplayMessageCtrlr Required item */
  1453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1459. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "FALSE");
  1466. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "0");
  1473. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1480. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1487. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1488. /* EVSE Required item */
  1489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "FALSE");
  1495. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1502. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1509. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1516. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1517. /* LocalAuthListCtrlr Required item */
  1518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1524. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1531. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "TRUE");
  1538. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "50");
  1546. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "2048");
  1554. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1558. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = 1024*1024;
  1559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "5000");
  1562. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1563. /* MonitoringCtrlr Required item */
  1564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1570. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "FALSE");
  1577. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1585. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1593. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1601. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1609. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1616. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1617. /* OCPPCommCtrlr Required item */
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1624. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1633. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1640. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1648. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1655. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1662. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1670. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "FALSE");
  1677. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1686. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "3");
  1695. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  1702. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1708. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1710. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1717. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1724. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1725. /* ReservationCtrlr Required item */
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1732. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "TRUE");
  1739. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "FALSE");
  1746. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  1747. /* SampledDataCtrlr Required item */
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1754. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1761. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1768. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, " ");
  1775. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1783. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  1790. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, " ");
  1797. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  1799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "0");
  1805. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  1806. /* SecurityCtrlr Required item */
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1810. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, " ");
  1814. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1818. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "Phihong Technology");
  1822. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "Phihong");
  1829. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  1836. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  1837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "0");
  1843. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  1844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "FALSE");
  1850. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  1851. /* SmartChargingCtrlr Required item */
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1858. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "TRUE");
  1865. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "FALSE");
  1872. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "0");
  1879. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  1886. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  1888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  1893. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "FALSE");
  1900. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "FALSE");
  1907. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "FALSE");
  1914. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "3");
  1921. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  1928. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  1929. /* TariffCostCtrlr Required item */
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "FALSE");
  1937. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "FALSE");
  1945. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  1948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1949. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  1953. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  1955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "FALSE");
  1961. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  1962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "FALSE");
  1969. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1973. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  1977. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1981. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  1985. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  1986. /* TxCtrlr Required item */
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  1993. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2001. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  2008. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2015. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "EVConnected,Authorized,PowerPathClosed");
  2022. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "EVConnected,Authorized,PowerPathClosed");
  2029. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "60000");
  2037. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "FALSE");
  2044. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2045. }
  2046. else
  2047. {
  2048. // Variable name init
  2049. /* AlignedDataCtrlr Required item */
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2066. /* AuthCtrlrVariable Required item */
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2081. /* AuthCacheCtrlr Variable Required item */
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2092. /* ClockCtrlr Variable Required item */
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2111. /* ChargingStation Required item */
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2118. /* Connector Required item */
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2125. /* DeviceDataCtrlr Required item */
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2148. /* DisplayMessageCtrlr Required item */
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2159. /* EVSE Required item */
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2168. /* LocalAuthListCtrlr Required item */
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2183. /* MonitoringCtrlr Required item */
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2202. /* OCPPCommCtrlr Required item */
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2234. /* ReservationCtrlr Required item */
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2241. /* SampledDataCtrlr Required item */
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2258. /* SecurityCtrlr Required item */
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2271. /* SmartChargingCtrlr Required item */
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2294. /* TariffCostCtrlr Required item */
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2313. /* TxCtrlr Required item */
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2330. }
  2331. return 0;
  2332. }
  2333. void DB_variableIsCreate()
  2334. {
  2335. char sql[512];
  2336. char* errMsg = NULL;
  2337. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2338. /* Execute SQL statement */
  2339. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2340. {
  2341. DEBUG_INFO("SQL error: %s\n", errMsg);
  2342. }
  2343. }
  2344. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2345. {
  2346. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2347. {
  2348. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) != NULL) &&
  2349. (strlen(columnValue[2])>0?(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) != NULL):TRUE) &&
  2350. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) != NULL) &&
  2351. (strlen(columnValue[4])>0?(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) != NULL):TRUE))
  2352. {
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2355. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2359. }
  2360. }
  2361. return 0;
  2362. }
  2363. void DB_variableLoadFromDb()
  2364. {
  2365. char sql[512];
  2366. char* errMsg = NULL;
  2367. sprintf(sql,"select * from ocpp20_variable;");
  2368. /* Execute SQL statement */
  2369. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2370. {
  2371. DEBUG_INFO("SQL error: %s\n", errMsg);
  2372. }
  2373. }
  2374. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2375. {
  2376. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2377. if(columnCount > 0)
  2378. {
  2379. for(int idx=0;idx<columnCount;idx++)
  2380. {
  2381. json_object *SetNetworkProfile;
  2382. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2383. if(!is_error(SetNetworkProfile))
  2384. {
  2385. // Required data
  2386. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2387. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2388. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2389. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2390. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2391. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2392. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2393. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2394. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2395. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2396. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2397. {
  2398. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2399. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2400. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2401. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2402. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2403. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2404. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2405. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2406. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2407. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2408. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2409. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2410. }
  2411. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2412. {
  2413. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2414. {
  2415. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2416. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2417. }
  2418. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2419. {
  2420. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2421. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2422. }
  2423. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2424. {
  2425. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2426. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2427. }
  2428. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2429. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2430. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2431. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2432. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2433. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2434. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2435. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2436. }
  2437. }
  2438. json_object_put(SetNetworkProfile);
  2439. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2440. }
  2441. }
  2442. return 0;
  2443. }
  2444. void DB_getNetworkProfileFromDb()
  2445. {
  2446. char sql[512];
  2447. char* errMsg = NULL;
  2448. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2449. /* Execute SQL statement */
  2450. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2451. {
  2452. DEBUG_INFO("SQL error: %s\n", errMsg);
  2453. }
  2454. }
  2455. int DB_addNetworkProfile(int slot, char *data)
  2456. {
  2457. int result = PASS;
  2458. char sql[512];
  2459. char* errMsg = NULL;
  2460. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2461. slot,
  2462. data);
  2463. //* Execute SQL statement */
  2464. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2465. {
  2466. DEBUG_INFO("SQL error: %s\n", errMsg);
  2467. result = FAIL;
  2468. }
  2469. return result;
  2470. }
  2471. int DB_deleteNetworkProfile(int slot)
  2472. {
  2473. int result = PASS;
  2474. char sql[512];
  2475. char* errMsg = NULL;
  2476. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2477. //* Execute SQL statement */
  2478. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2479. {
  2480. DEBUG_INFO("SQL error: %s", errMsg);
  2481. result = FAIL;
  2482. }
  2483. return result;
  2484. }
  2485. //==========================================
  2486. // Check time passed since today
  2487. //==========================================
  2488. long long DiffTimebWithNow(struct timeb ST)
  2489. {
  2490. //return milli-second
  2491. struct timeb ET;
  2492. long long StartTime,StopTime;
  2493. ftime(&ET);
  2494. StartTime=(long long)ST.time;
  2495. StopTime=(long long)ET.time;
  2496. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2497. }
  2498. int getTimePassSinceToday()
  2499. {
  2500. int result = -1;
  2501. time_t t;
  2502. struct tm *tmStartToday;
  2503. struct timeb tbStartToday;
  2504. t=time(NULL);
  2505. tmStartToday=localtime(&t);
  2506. tmStartToday->tm_hour = 0;
  2507. tmStartToday->tm_min = 0;
  2508. tmStartToday->tm_sec = 0;
  2509. tbStartToday.time = mktime(tmStartToday);
  2510. tbStartToday.millitm = 0;
  2511. result = DiffTimebWithNow(tbStartToday)/1000;
  2512. return result;
  2513. }
  2514. //==========================================
  2515. // GetCompositeSchedule logic related function
  2516. //==========================================
  2517. int DiffTimebSec(struct timeb ST, struct timeb ET)
  2518. {
  2519. //return milli-second
  2520. unsigned int StartTime,StopTime;
  2521. StartTime=(unsigned int)ST.time;
  2522. StopTime=(unsigned int)ET.time;
  2523. return (StopTime-StartTime);
  2524. }
  2525. int DiffTimebWithNowSec(struct timeb ST)
  2526. {
  2527. //return milli-second
  2528. struct timeb ET;
  2529. unsigned int StartTime,StopTime;
  2530. ftime(&ET);
  2531. StartTime=(unsigned int)ST.time;
  2532. StopTime=(unsigned int)ET.time;
  2533. return (StopTime-StartTime);
  2534. }
  2535. int getStartStop(uint8_t *start, uint8_t *stop)
  2536. {
  2537. int result = -1;
  2538. struct tm tmStart;
  2539. struct timeb tbStart;
  2540. struct tm tmStop;
  2541. struct timeb tbStop;
  2542. if((sscanf((char*)start, "%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) &&
  2543. (sscanf((char*)stop, "%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))
  2544. {
  2545. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  2546. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  2547. tmStart.tm_year -= 1900;
  2548. tmStart.tm_mon -= 1;
  2549. tbStart.time = mktime(&tmStart);
  2550. tbStart.millitm = 0;
  2551. tmStop.tm_year -= 1900;
  2552. tmStop.tm_mon -= 1;
  2553. tbStop.time = mktime(&tmStop);
  2554. tbStop.millitm = 0;
  2555. result = DiffTimebSec(tbStart, tbStop);
  2556. //DEBUG_INFO("getStartStop(): %d\n", result);
  2557. }
  2558. else
  2559. {
  2560. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2561. }
  2562. return result;
  2563. }
  2564. int isOvertNow(uint8_t *start)
  2565. {
  2566. int result = YES;
  2567. struct tm tmStart;
  2568. struct timeb tbStart;
  2569. if((sscanf((char*)start, "%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))
  2570. {
  2571. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  2572. tmStart.tm_year -= 1900;
  2573. tmStart.tm_mon -= 1;
  2574. tbStart.time = mktime(&tmStart);
  2575. tbStart.millitm = 0;
  2576. if(DiffTimebWithNowSec(tbStart) <= 0)
  2577. result = NO;
  2578. }
  2579. else
  2580. {
  2581. DEBUG_WARN("Start date parsing error.\r\n");
  2582. }
  2583. return result;
  2584. }
  2585. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2586. {
  2587. int result = -1;
  2588. struct tm tmStart;
  2589. struct timeb tbStart;
  2590. struct tm tmStop;
  2591. struct timeb tbStop;
  2592. if((sscanf((char*)start, "%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) &&
  2593. (sscanf((char*)stop, "%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))
  2594. {
  2595. tmStart.tm_year -= 1900;
  2596. tmStart.tm_mon -= 1;
  2597. tbStart.time = mktime(&tmStart);
  2598. tbStart.millitm = 0;
  2599. tmStop.tm_year -= 1900;
  2600. tmStop.tm_mon -= 1;
  2601. tbStop.time = mktime(&tmStop);
  2602. tbStop.millitm = 0;
  2603. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2604. }
  2605. return result;
  2606. }
  2607. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *compositeProfile)
  2608. {
  2609. FILE *fp;
  2610. char profileFileName[128];
  2611. char *line = NULL;
  2612. size_t len = 0;
  2613. time_t CurrentTime;
  2614. struct tm *tmComposite;
  2615. struct ChargingProfileType maxProfile;
  2616. struct ChargingProfileType defaultTxProfile;
  2617. struct ChargingProfileType txProfile;
  2618. struct ChargingSchedulePeriodType tmpPeriod;
  2619. uint8_t limitMax=0;
  2620. uint8_t limitDef=0;
  2621. uint8_t limitTx=0;
  2622. int compositePeriodIdx = 0;
  2623. CurrentTime = time(NULL);
  2624. tmComposite=localtime(&CurrentTime);
  2625. sprintf((char*)compositeProfile->chargingSchedule[0].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);
  2626. sprintf((char*)compositeProfile->chargingSchedule[0].chargingRateUnit, "A");
  2627. compositeProfile->chargingSchedule[0].duration = durationReq;
  2628. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  2629. {
  2630. compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2631. compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = -1;
  2632. compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2633. compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  2634. }
  2635. compositeProfile->id = 0;
  2636. compositeProfile->stackLevel = 99 ;
  2637. sprintf((char*)compositeProfile->chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  2638. maxProfile.id = -1;
  2639. defaultTxProfile.id = -1;
  2640. txProfile.id = -1;
  2641. maxProfile.chargingSchedule[0].duration = -1;
  2642. defaultTxProfile.chargingSchedule[0].duration = -1;
  2643. txProfile.chargingSchedule[0].duration = -1;
  2644. system("yes|rm /tmp/*.json");
  2645. system("cp /Storage/OCPP/*.json /tmp");
  2646. /*
  2647. * Search valid charging profile
  2648. */
  2649. //DEBUG_INFO("====================================\n");
  2650. // Search tx profile
  2651. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2652. if((access(profileFileName, F_OK))!=-1)
  2653. {
  2654. fp = fopen(profileFileName, "r");
  2655. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  2656. {
  2657. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2658. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = -1;
  2659. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2660. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  2661. }
  2662. txProfile.id = -1;
  2663. txProfile.stackLevel = -1;
  2664. while(getline(&line, &len, fp) != -1)
  2665. {
  2666. json_object *obj = NULL;
  2667. obj = json_tokener_parse(line);
  2668. if(is_error(obj))
  2669. {
  2670. DEBUG_ERROR("Parse txProfile from file error.\n");
  2671. }
  2672. else
  2673. {
  2674. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.id) &&
  2675. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.stackLevel)
  2676. )
  2677. {
  2678. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2679. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2680. )
  2681. {
  2682. struct tm tmFrom, tmTo;
  2683. struct timeb tbFrom, tbTo;
  2684. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "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) &&
  2685. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "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))
  2686. {
  2687. tmFrom.tm_year -= 1900;
  2688. tmFrom.tm_mon -= 1;
  2689. tbFrom.time = mktime(&tmFrom);
  2690. tmTo.tm_year -= 1900;
  2691. tmTo.tm_mon -= 1;
  2692. tbTo.time = mktime(&tmTo);
  2693. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2694. {
  2695. if(txProfile.id == -1)
  2696. DEBUG_INFO("TxProfile found.\n");
  2697. else
  2698. DEBUG_INFO("TxProfile updated.\n");
  2699. // Required item
  2700. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2701. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2702. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2703. sprintf((char*)txProfile.chargingSchedule[0].chargingRateUnit, "A");
  2704. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2705. {
  2706. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2707. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2708. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2709. 3:
  2710. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2711. }
  2712. // Optional item
  2713. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2714. {
  2715. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2716. }
  2717. else
  2718. {
  2719. sprintf((char*)txProfile.validFrom, " ");
  2720. }
  2721. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2722. {
  2723. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2724. }
  2725. else
  2726. {
  2727. sprintf((char*)txProfile.validTo, " ");
  2728. }
  2729. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2730. {
  2731. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2732. }
  2733. else
  2734. {
  2735. sprintf((char*)txProfile.recurrencyKind, " ");
  2736. }
  2737. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2738. {
  2739. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  2740. }
  2741. else
  2742. {
  2743. sprintf((char*)txProfile.transactionId, " ");
  2744. }
  2745. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2746. {
  2747. txProfile.chargingSchedule[0].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2748. }
  2749. else
  2750. {
  2751. txProfile.chargingSchedule[0].duration = 86400;
  2752. }
  2753. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2754. {
  2755. sprintf((char*)txProfile.chargingSchedule[0].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2756. }
  2757. else
  2758. {
  2759. sprintf((char*)txProfile.chargingSchedule[0].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[0].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  2760. }
  2761. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2762. {
  2763. txProfile.chargingSchedule[0].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2764. }
  2765. else
  2766. {
  2767. txProfile.chargingSchedule[0].minChargingRate = -1;
  2768. }
  2769. }
  2770. }
  2771. }
  2772. else
  2773. {
  2774. if(txProfile.id == -1)
  2775. DEBUG_INFO("TxProfile found.\n");
  2776. else
  2777. DEBUG_INFO("TxProfile updated.\n");
  2778. // Required item
  2779. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2780. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2781. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2782. sprintf((char*)txProfile.chargingSchedule[0].chargingRateUnit, "A");
  2783. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2784. {
  2785. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2786. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2787. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2788. 3:
  2789. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2790. }
  2791. // Optional item
  2792. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2793. {
  2794. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2795. }
  2796. else
  2797. {
  2798. sprintf((char*)txProfile.validFrom, " ");
  2799. }
  2800. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2801. {
  2802. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2803. }
  2804. else
  2805. {
  2806. sprintf((char*)txProfile.validTo, " ");
  2807. }
  2808. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2809. {
  2810. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2811. }
  2812. else
  2813. {
  2814. sprintf((char*)txProfile.recurrencyKind, " ");
  2815. }
  2816. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2817. {
  2818. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  2819. }
  2820. else
  2821. {
  2822. sprintf((char*)txProfile.transactionId, " ");
  2823. }
  2824. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2825. {
  2826. txProfile.chargingSchedule[0].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2827. }
  2828. else
  2829. {
  2830. txProfile.chargingSchedule[0].duration = 86400;
  2831. }
  2832. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2833. {
  2834. sprintf((char*)txProfile.chargingSchedule[0].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2835. }
  2836. else
  2837. {
  2838. sprintf((char*)txProfile.chargingSchedule[0].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[0].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  2839. }
  2840. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2841. {
  2842. txProfile.chargingSchedule[0].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2843. }
  2844. else
  2845. {
  2846. txProfile.chargingSchedule[0].minChargingRate = -1;
  2847. }
  2848. }
  2849. }
  2850. }
  2851. json_object_put(obj);
  2852. }
  2853. fclose(fp);
  2854. /*
  2855. if(txProfile.ChargingProfileId != -1)
  2856. {
  2857. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2858. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2859. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2860. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2861. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2862. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2863. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2864. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[0].StartSchedule);
  2865. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[0].Duration);
  2866. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[0].ChargingRateUnit);
  2867. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[0].MinChargingRate);
  2868. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[0].ChargingSchedulePeriod);idxPeriod++)
  2869. {
  2870. if(txProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2871. {
  2872. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2873. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].Limit);
  2874. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2875. }
  2876. }
  2877. }
  2878. else
  2879. DEBUG_INFO("TxProfile not found.\n");*/
  2880. }
  2881. // Search default tx profile
  2882. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2883. if((access(profileFileName, F_OK))==-1)
  2884. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2885. if((access(profileFileName, F_OK))!=-1)
  2886. {
  2887. fp = fopen(profileFileName, "r");
  2888. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  2889. {
  2890. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2891. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = -1;
  2892. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2893. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  2894. }
  2895. defaultTxProfile.id = -1;
  2896. defaultTxProfile.stackLevel = -1;
  2897. while(getline(&line, &len, fp) != -1)
  2898. {
  2899. json_object *obj = NULL;
  2900. obj = json_tokener_parse(line);
  2901. if(is_error(obj))
  2902. {
  2903. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2904. }
  2905. else
  2906. {
  2907. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.id) &&
  2908. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.stackLevel)
  2909. )
  2910. {
  2911. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2912. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2913. )
  2914. {
  2915. struct tm tmFrom, tmTo;
  2916. struct timeb tbFrom, tbTo;
  2917. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "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) &&
  2918. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "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))
  2919. {
  2920. tmFrom.tm_year -= 1900;
  2921. tmFrom.tm_mon -= 1;
  2922. tbFrom.time = mktime(&tmFrom);
  2923. tmTo.tm_year -= 1900;
  2924. tmTo.tm_mon -= 1;
  2925. tbTo.time = mktime(&tmTo);
  2926. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2927. {
  2928. if(defaultTxProfile.id == -1)
  2929. DEBUG_INFO("TxDefaultProfile found.\n");
  2930. else
  2931. DEBUG_INFO("TxDefaultProfile updated.\n");
  2932. // Required item
  2933. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2934. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2935. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2936. sprintf((char*)defaultTxProfile.chargingSchedule[0].chargingRateUnit, "A");
  2937. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2938. {
  2939. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2940. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2941. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2942. 3:
  2943. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2944. }
  2945. // Optional item
  2946. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2947. {
  2948. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2949. }
  2950. else
  2951. {
  2952. sprintf((char*)defaultTxProfile.validFrom, " ");
  2953. }
  2954. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2955. {
  2956. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2957. }
  2958. else
  2959. {
  2960. sprintf((char*)defaultTxProfile.validTo, " ");
  2961. }
  2962. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2963. {
  2964. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2965. }
  2966. else
  2967. {
  2968. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  2969. }
  2970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2971. {
  2972. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  2973. }
  2974. else
  2975. {
  2976. sprintf((char*)defaultTxProfile.transactionId, " ");
  2977. }
  2978. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2979. {
  2980. defaultTxProfile.chargingSchedule[0].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2981. }
  2982. else
  2983. {
  2984. defaultTxProfile.chargingSchedule[0].duration = 86400;
  2985. }
  2986. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2987. {
  2988. sprintf((char*)defaultTxProfile.chargingSchedule[0].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2989. }
  2990. else
  2991. {
  2992. sprintf((char*)defaultTxProfile.chargingSchedule[0].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[0].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  2993. }
  2994. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2995. {
  2996. defaultTxProfile.chargingSchedule[0].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2997. }
  2998. else
  2999. {
  3000. defaultTxProfile.chargingSchedule[0].minChargingRate = -1;
  3001. }
  3002. }
  3003. }
  3004. }
  3005. else
  3006. {
  3007. if(defaultTxProfile.id == -1)
  3008. DEBUG_INFO("TxDefaultProfile found.\n");
  3009. else
  3010. DEBUG_INFO("TxDefaultProfile updated.\n");
  3011. // Required item
  3012. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3013. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3014. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3015. sprintf((char*)defaultTxProfile.chargingSchedule[0].chargingRateUnit, "A");
  3016. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3017. {
  3018. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3019. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3020. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3021. 3:
  3022. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3023. }
  3024. // Optional item
  3025. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3026. {
  3027. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3028. }
  3029. else
  3030. {
  3031. sprintf((char*)defaultTxProfile.validFrom, " ");
  3032. }
  3033. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3034. {
  3035. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3036. }
  3037. else
  3038. {
  3039. sprintf((char*)defaultTxProfile.validTo, " ");
  3040. }
  3041. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3042. {
  3043. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3044. }
  3045. else
  3046. {
  3047. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3048. }
  3049. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3050. {
  3051. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3052. }
  3053. else
  3054. {
  3055. sprintf((char*)defaultTxProfile.transactionId, " ");
  3056. }
  3057. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3058. {
  3059. defaultTxProfile.chargingSchedule[0].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3060. }
  3061. else
  3062. {
  3063. defaultTxProfile.chargingSchedule[0].duration = 86400;
  3064. }
  3065. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3066. {
  3067. sprintf((char*)defaultTxProfile.chargingSchedule[0].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3068. }
  3069. else
  3070. {
  3071. sprintf((char*)defaultTxProfile.chargingSchedule[0].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[0].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3072. }
  3073. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3074. {
  3075. defaultTxProfile.chargingSchedule[0].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3076. }
  3077. else
  3078. {
  3079. defaultTxProfile.chargingSchedule[0].minChargingRate = -1;
  3080. }
  3081. }
  3082. }
  3083. }
  3084. json_object_put(obj);
  3085. }
  3086. fclose(fp);
  3087. /*
  3088. if(defaultTxProfile.ChargingProfileId != -1)
  3089. {
  3090. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3091. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3092. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3093. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3094. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3095. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3096. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3097. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[0].StartSchedule);
  3098. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[0].Duration);
  3099. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[0].ChargingRateUnit);
  3100. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[0].MinChargingRate);
  3101. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod);idxPeriod++)
  3102. {
  3103. if(defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3104. {
  3105. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3106. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].Limit);
  3107. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3108. }
  3109. }
  3110. }
  3111. else
  3112. DEBUG_INFO("TxDefaultProfile not found.\n");
  3113. DEBUG_INFO("------------------------------------\n");*/
  3114. }
  3115. // Search max profile
  3116. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3117. if((access(profileFileName, F_OK))!=-1)
  3118. {
  3119. fp = fopen(profileFileName, "r");
  3120. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3121. {
  3122. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3123. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = -1;
  3124. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3125. }
  3126. maxProfile.id = -1;
  3127. maxProfile.stackLevel = -1;
  3128. while(getline(&line, &len, fp) != -1)
  3129. {
  3130. json_object *obj = NULL;
  3131. obj = json_tokener_parse(line);
  3132. if(is_error(obj))
  3133. {
  3134. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3135. }
  3136. else
  3137. {
  3138. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.id) &&
  3139. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.stackLevel)
  3140. )
  3141. {
  3142. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3143. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3144. )
  3145. {
  3146. struct tm tmFrom, tmTo;
  3147. struct timeb tbFrom, tbTo;
  3148. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "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) &&
  3149. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "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))
  3150. {
  3151. tmFrom.tm_year -= 1900;
  3152. tmFrom.tm_mon -= 1;
  3153. tbFrom.time = mktime(&tmFrom);
  3154. tmTo.tm_year -= 1900;
  3155. tmTo.tm_mon -= 1;
  3156. tbTo.time = mktime(&tmTo);
  3157. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3158. {
  3159. if(maxProfile.id == -1)
  3160. DEBUG_INFO("MaxProfile found.\n");
  3161. else
  3162. DEBUG_INFO("MaxProfile updated.\n");
  3163. // Required item
  3164. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3165. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3166. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3167. sprintf((char*)maxProfile.chargingSchedule[0].chargingRateUnit, "A");
  3168. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3169. {
  3170. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3171. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3172. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3173. 3:
  3174. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3175. }
  3176. // Optional item
  3177. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3178. {
  3179. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3180. }
  3181. else
  3182. {
  3183. sprintf((char*)maxProfile.validFrom, " ");
  3184. }
  3185. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3186. {
  3187. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3188. }
  3189. else
  3190. {
  3191. sprintf((char*)maxProfile.validTo, " ");
  3192. }
  3193. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3194. {
  3195. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3196. }
  3197. else
  3198. {
  3199. sprintf((char*)maxProfile.recurrencyKind, " ");
  3200. }
  3201. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3202. {
  3203. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3204. }
  3205. else
  3206. {
  3207. sprintf((char*)maxProfile.transactionId, " ");
  3208. }
  3209. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3210. {
  3211. maxProfile.chargingSchedule[0].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3212. }
  3213. else
  3214. {
  3215. maxProfile.chargingSchedule[0].duration = 86400;
  3216. }
  3217. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3218. {
  3219. sprintf((char*)maxProfile.chargingSchedule[0].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3220. }
  3221. else
  3222. {
  3223. sprintf((char*)maxProfile.chargingSchedule[0].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[0].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3224. }
  3225. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3226. {
  3227. maxProfile.chargingSchedule[0].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3228. }
  3229. else
  3230. {
  3231. maxProfile.chargingSchedule[0].minChargingRate = -1;
  3232. }
  3233. }
  3234. }
  3235. }
  3236. else
  3237. {
  3238. if(maxProfile.id == -1)
  3239. DEBUG_INFO("MaxProfile found.\n");
  3240. else
  3241. DEBUG_INFO("MaxProfile updated.\n");
  3242. // Required item
  3243. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3244. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3245. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3246. sprintf((char*)maxProfile.chargingSchedule[0].chargingRateUnit, "A");
  3247. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3248. {
  3249. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3250. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3251. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3252. 3:
  3253. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3254. }
  3255. // Optional item
  3256. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3257. {
  3258. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3259. }
  3260. else
  3261. {
  3262. sprintf((char*)maxProfile.validFrom, " ");
  3263. }
  3264. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3265. {
  3266. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3267. }
  3268. else
  3269. {
  3270. sprintf((char*)maxProfile.validTo, " ");
  3271. }
  3272. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3273. {
  3274. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3275. }
  3276. else
  3277. {
  3278. sprintf((char*)maxProfile.recurrencyKind, " ");
  3279. }
  3280. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3281. {
  3282. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3283. }
  3284. else
  3285. {
  3286. sprintf((char*)maxProfile.transactionId, " ");
  3287. }
  3288. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3289. {
  3290. maxProfile.chargingSchedule[0].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3291. }
  3292. else
  3293. {
  3294. maxProfile.chargingSchedule[0].duration = 86400;
  3295. }
  3296. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3297. {
  3298. sprintf((char*)maxProfile.chargingSchedule[0].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3299. }
  3300. else
  3301. {
  3302. sprintf((char*)maxProfile.chargingSchedule[0].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[0].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3303. }
  3304. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3305. {
  3306. maxProfile.chargingSchedule[0].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3307. }
  3308. else
  3309. {
  3310. maxProfile.chargingSchedule[0].minChargingRate = -1;
  3311. }
  3312. }
  3313. }
  3314. }
  3315. json_object_put(obj);
  3316. }
  3317. fclose(fp);
  3318. /*
  3319. if(maxProfile.ChargingProfileId !=-1)
  3320. {
  3321. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3322. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3323. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3324. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3325. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3326. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3327. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3328. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[0].StartSchedule);
  3329. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[0].Duration);
  3330. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[0].ChargingRateUnit);
  3331. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[0].MinChargingRate);
  3332. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[0].ChargingSchedulePeriod);idxPeriod++)
  3333. {
  3334. if(maxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3335. {
  3336. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3337. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].Limit);
  3338. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3339. }
  3340. }
  3341. }
  3342. else
  3343. DEBUG_INFO("MaxProfile not found.\n");
  3344. DEBUG_INFO("------------------------------------\n");*/
  3345. }
  3346. /*
  3347. * Align found profile start schedule & periods
  3348. */
  3349. //DEBUG_INFO("====================================\n");
  3350. /*
  3351. // For local test usage, force modify found profile start schedule info
  3352. sprintf((char*)maxProfile.chargingSchedule[0].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);
  3353. sprintf((char*)defaultTxProfile.chargingSchedule[0].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);
  3354. sprintf((char*)txProfile.chargingSchedule[0].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);
  3355. */
  3356. if(txProfile.id != -1)
  3357. {
  3358. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3359. {
  3360. if(txProfile.chargingSchedule[0].duration != -1)
  3361. {
  3362. txProfile.chargingSchedule[0].duration = ((txProfile.chargingSchedule[0].duration-getStartStop(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3363. 0:
  3364. (txProfile.chargingSchedule[0].duration-getStartStop(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule)));
  3365. }
  3366. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3367. {
  3368. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3369. {
  3370. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3371. 0:
  3372. (txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule)));
  3373. if(idxPeriod > 0)
  3374. {
  3375. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3376. {
  3377. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3378. }
  3379. }
  3380. }
  3381. }
  3382. }
  3383. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3384. {
  3385. if(txProfile.chargingSchedule[0].duration != -1)
  3386. {
  3387. txProfile.chargingSchedule[0].duration = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?txProfile.chargingSchedule[0].duration:((txProfile.chargingSchedule[0].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3388. 0:
  3389. (txProfile.chargingSchedule[0].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule)));
  3390. }
  3391. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3392. {
  3393. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3394. {
  3395. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod:((txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3396. 0:
  3397. (txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule)));
  3398. if(idxPeriod > 0)
  3399. {
  3400. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3401. {
  3402. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. else
  3409. {
  3410. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3411. {
  3412. if(txProfile.chargingSchedule[0].duration != -1)
  3413. {
  3414. txProfile.chargingSchedule[0].duration = ((txProfile.chargingSchedule[0].duration-getStartSinceRecurring(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE))<0?
  3415. 0:
  3416. (txProfile.chargingSchedule[0].duration-getStartSinceRecurring(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE)));
  3417. }
  3418. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3419. {
  3420. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3421. {
  3422. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE))<0?
  3423. 0:
  3424. (txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE)));
  3425. if(idxPeriod > 0)
  3426. {
  3427. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3428. {
  3429. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3430. }
  3431. }
  3432. }
  3433. }
  3434. }
  3435. else
  3436. {
  3437. if(txProfile.chargingSchedule[0].duration != -1)
  3438. {
  3439. txProfile.chargingSchedule[0].duration = ((txProfile.chargingSchedule[0].duration-getStartSinceRecurring(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE))<0?
  3440. 0:
  3441. (txProfile.chargingSchedule[0].duration-getStartSinceRecurring(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE)));
  3442. }
  3443. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3444. {
  3445. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3446. {
  3447. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE))<0?
  3448. 0:
  3449. (txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE)));
  3450. if(idxPeriod > 0)
  3451. {
  3452. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3453. {
  3454. txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3455. }
  3456. }
  3457. }
  3458. }
  3459. }
  3460. }
  3461. /*
  3462. DEBUG_INFO("txProfile after align.\n");
  3463. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3464. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3465. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3466. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3467. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3468. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3469. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  3470. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3471. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[0].Duration);
  3472. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[0].ChargingRateUnit);
  3473. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[0].MinChargingRate);
  3474. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[0].ChargingSchedulePeriod);idxPeriod++)
  3475. {
  3476. if(txProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3477. {
  3478. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3479. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].Limit);
  3480. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3481. }
  3482. }*/
  3483. }
  3484. if(defaultTxProfile.id != -1)
  3485. {
  3486. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3487. {
  3488. if(defaultTxProfile.chargingSchedule[0].duration != -1)
  3489. {
  3490. defaultTxProfile.chargingSchedule[0].duration = ((defaultTxProfile.chargingSchedule[0].duration-getStartStop(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3491. 0:
  3492. (defaultTxProfile.chargingSchedule[0].duration-getStartStop(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule)));
  3493. }
  3494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3495. {
  3496. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3497. {
  3498. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3499. 0:
  3500. (defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule)));
  3501. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[0].duration)
  3502. {
  3503. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[0].duration-defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod);
  3504. }
  3505. if(idxPeriod > 0)
  3506. {
  3507. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3508. {
  3509. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3510. }
  3511. }
  3512. }
  3513. }
  3514. }
  3515. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3516. {
  3517. if(defaultTxProfile.chargingSchedule[0].duration != -1)
  3518. {
  3519. defaultTxProfile.chargingSchedule[0].duration = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?defaultTxProfile.chargingSchedule[0].duration:((defaultTxProfile.chargingSchedule[0].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3520. 0:
  3521. (defaultTxProfile.chargingSchedule[0].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule)));
  3522. }
  3523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3524. {
  3525. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3526. {
  3527. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod:((defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3528. 0:
  3529. (defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule)));
  3530. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[0].duration)
  3531. {
  3532. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[0].duration-defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod);
  3533. }
  3534. if(idxPeriod > 0)
  3535. {
  3536. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3537. {
  3538. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3539. }
  3540. }
  3541. }
  3542. }
  3543. }
  3544. else
  3545. {
  3546. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3547. {
  3548. if(defaultTxProfile.chargingSchedule[0].duration != -1)
  3549. {
  3550. defaultTxProfile.chargingSchedule[0].duration = ((defaultTxProfile.chargingSchedule[0].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE))<0?
  3551. 0:
  3552. (defaultTxProfile.chargingSchedule[0].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE)));
  3553. }
  3554. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3555. {
  3556. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3557. {
  3558. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE))<0?
  3559. 0:
  3560. (defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE)));
  3561. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[0].duration)
  3562. {
  3563. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[0].duration-defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod);
  3564. }
  3565. if(idxPeriod > 0)
  3566. {
  3567. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3568. {
  3569. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3570. }
  3571. }
  3572. }
  3573. }
  3574. }
  3575. else
  3576. {
  3577. if(defaultTxProfile.chargingSchedule[0].duration != -1)
  3578. {
  3579. defaultTxProfile.chargingSchedule[0].duration = ((defaultTxProfile.chargingSchedule[0].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE))<0?
  3580. 0:
  3581. (defaultTxProfile.chargingSchedule[0].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE)));
  3582. }
  3583. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3584. {
  3585. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3586. {
  3587. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE))<0?
  3588. 0:
  3589. (defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE)));
  3590. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[0].duration)
  3591. {
  3592. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[0].duration-defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod);
  3593. }
  3594. if(idxPeriod > 0)
  3595. {
  3596. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3597. {
  3598. defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3599. }
  3600. }
  3601. }
  3602. }
  3603. }
  3604. }
  3605. /*
  3606. DEBUG_INFO("defaultTxProfile after align.\n");
  3607. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3608. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3609. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3610. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3611. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3612. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3613. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3614. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3615. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[0].Duration);
  3616. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[0].ChargingRateUnit);
  3617. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[0].MinChargingRate);
  3618. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod);idxPeriod++)
  3619. {
  3620. if(defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3621. {
  3622. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3623. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].Limit);
  3624. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3625. }
  3626. }
  3627. DEBUG_INFO("------------------------------------\n");*/
  3628. }
  3629. if(maxProfile.id != -1)
  3630. {
  3631. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3632. {
  3633. if(maxProfile.chargingSchedule[0].duration != -1)
  3634. {
  3635. maxProfile.chargingSchedule[0].duration = ((maxProfile.chargingSchedule[0].duration-getStartStop(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3636. 0:
  3637. (maxProfile.chargingSchedule[0].duration-getStartStop(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule)));
  3638. }
  3639. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3640. {
  3641. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3642. {
  3643. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3644. 0:
  3645. (maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule)));
  3646. if(idxPeriod > 0)
  3647. {
  3648. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3649. {
  3650. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3651. }
  3652. }
  3653. }
  3654. }
  3655. }
  3656. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3657. {
  3658. if(maxProfile.chargingSchedule[0].duration != -1)
  3659. {
  3660. maxProfile.chargingSchedule[0].duration = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?maxProfile.chargingSchedule[0].duration:((maxProfile.chargingSchedule[0].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3661. 0:
  3662. (maxProfile.chargingSchedule[0].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[9].startSchedule)));
  3663. }
  3664. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3665. {
  3666. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3667. {
  3668. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod:((maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule))<0?
  3669. 0:
  3670. (maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[0].startSchedule)));
  3671. if(idxPeriod > 0)
  3672. {
  3673. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3674. {
  3675. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3676. }
  3677. }
  3678. }
  3679. }
  3680. }
  3681. else
  3682. {
  3683. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3684. {
  3685. if(maxProfile.chargingSchedule[0].duration != -1)
  3686. {
  3687. maxProfile.chargingSchedule[0].duration = ((maxProfile.chargingSchedule[0].duration-getStartSinceRecurring(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE))<0?
  3688. 0:
  3689. (maxProfile.chargingSchedule[0].duration-getStartSinceRecurring(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE)));
  3690. }
  3691. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3692. {
  3693. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3694. {
  3695. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE))<0?
  3696. 0:
  3697. (maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, FALSE)));
  3698. if(idxPeriod > 0)
  3699. {
  3700. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3701. {
  3702. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3703. }
  3704. }
  3705. }
  3706. }
  3707. }
  3708. else
  3709. {
  3710. if(maxProfile.chargingSchedule[0].duration != -1)
  3711. {
  3712. maxProfile.chargingSchedule[0].duration = ((maxProfile.chargingSchedule[0].duration-getStartSinceRecurring(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE))<0?
  3713. 0:
  3714. (maxProfile.chargingSchedule[0].duration-getStartSinceRecurring(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE)));
  3715. }
  3716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  3717. {
  3718. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3719. {
  3720. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE))<0?
  3721. 0:
  3722. (maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[0].startSchedule, compositeProfile->chargingSchedule[0].startSchedule, TRUE)));
  3723. if(idxPeriod > 0)
  3724. {
  3725. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod)
  3726. {
  3727. maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit;
  3728. }
  3729. }
  3730. }
  3731. }
  3732. }
  3733. }
  3734. /*
  3735. DEBUG_INFO("MaxProfile after align.\n");
  3736. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3737. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3738. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3739. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3740. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3741. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3742. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3743. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3744. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[0].Duration);
  3745. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[0].ChargingRateUnit);
  3746. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[0].MinChargingRate);
  3747. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[0].ChargingSchedulePeriod);idxPeriod++)
  3748. {
  3749. if(maxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3750. {
  3751. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3752. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].Limit);
  3753. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[0].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3754. }
  3755. }
  3756. DEBUG_INFO("------------------------------------\n");*/
  3757. }
  3758. /*
  3759. * Merge to conposite schedule
  3760. */
  3761. //DEBUG_INFO("====================================\n");
  3762. // Find each profile period quantity
  3763. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[0].chargingSchedulePeriod);idx++)
  3764. {
  3765. if(maxProfile.chargingSchedule[0].chargingSchedulePeriod[idx].limit != -1)
  3766. limitMax = idx+1;
  3767. }
  3768. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod);idx++)
  3769. {
  3770. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idx].limit != -1)
  3771. limitDef = idx+1;
  3772. }
  3773. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[0].chargingSchedulePeriod);idx++)
  3774. {
  3775. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idx].limit != -1)
  3776. limitTx = idx+1;
  3777. }
  3778. // TxProfile found, composite schedule based on it
  3779. if(txProfile.id != -1)
  3780. {
  3781. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3782. {
  3783. if((txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  3784. (txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  3785. (txProfile.chargingSchedule[0].duration > 0))
  3786. {
  3787. if(maxProfile.id != -1)
  3788. {
  3789. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3790. {
  3791. if((txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  3792. {
  3793. if((maxProfile.chargingSchedule[0].duration > 0))
  3794. {
  3795. tmpPeriod.startPeriod = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  3796. tmpPeriod.numberPhases = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  3797. tmpPeriod.limit = (txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].limit>maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit:txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].limit);
  3798. }
  3799. else
  3800. {
  3801. tmpPeriod.startPeriod = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  3802. tmpPeriod.numberPhases = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  3803. tmpPeriod.limit = txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].limit;
  3804. }
  3805. }
  3806. if(idxMaxPeriod == (limitMax-1))
  3807. {
  3808. if(tmpPeriod.limit != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  3809. {
  3810. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3811. {
  3812. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  3813. compositePeriodIdx++;
  3814. }
  3815. else
  3816. {
  3817. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  3818. }
  3819. }
  3820. }
  3821. }
  3822. }
  3823. else
  3824. {
  3825. if(txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3826. {
  3827. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3828. compositePeriodIdx++;
  3829. }
  3830. else
  3831. {
  3832. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3833. }
  3834. }
  3835. }
  3836. if(idxTxPeriod == (limitTx-1))
  3837. {
  3838. if(defaultTxProfile.id != -1)
  3839. {
  3840. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3841. {
  3842. if((defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[0].duration-defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  3843. (defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  3844. (defaultTxProfile.chargingSchedule[0].duration>0))
  3845. {
  3846. if(maxProfile.id != -1)
  3847. {
  3848. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3849. {
  3850. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  3851. {
  3852. if((maxProfile.chargingSchedule[0].duration > 0))
  3853. {
  3854. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  3855. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  3856. tmpPeriod.limit = (defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].limit>maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit:defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxTxPeriod].limit);
  3857. }
  3858. else
  3859. {
  3860. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  3861. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  3862. tmpPeriod.limit = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].limit;
  3863. }
  3864. if(tmpPeriod.limit != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  3865. {
  3866. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3867. {
  3868. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  3869. compositePeriodIdx++;
  3870. }
  3871. else
  3872. {
  3873. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  3874. }
  3875. }
  3876. break;
  3877. }
  3878. }
  3879. }
  3880. else
  3881. {
  3882. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3883. {
  3884. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  3885. compositePeriodIdx++;
  3886. }
  3887. else
  3888. {
  3889. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  3890. }
  3891. }
  3892. }
  3893. }
  3894. }
  3895. }
  3896. }
  3897. }
  3898. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3899. else if(defaultTxProfile.id != -1)
  3900. {
  3901. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3902. {
  3903. if((defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  3904. (defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  3905. (defaultTxProfile.chargingSchedule[0].duration > 0))
  3906. {
  3907. if(maxProfile.id != -1)
  3908. {
  3909. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3910. {
  3911. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  3912. {
  3913. if((maxProfile.chargingSchedule[0].duration > 0))
  3914. {
  3915. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  3916. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  3917. tmpPeriod.limit = (defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].limit>maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit:defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].limit);
  3918. }
  3919. else
  3920. {
  3921. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  3922. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  3923. tmpPeriod.limit = defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].limit;
  3924. }
  3925. if(tmpPeriod.limit != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  3926. {
  3927. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3928. {
  3929. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  3930. compositePeriodIdx++;
  3931. }
  3932. else
  3933. {
  3934. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  3935. }
  3936. }
  3937. break;
  3938. }
  3939. }
  3940. }
  3941. else
  3942. {
  3943. if(defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3944. {
  3945. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  3946. compositePeriodIdx++;
  3947. }
  3948. else
  3949. {
  3950. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[0].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  3951. }
  3952. }
  3953. }
  3954. }
  3955. }
  3956. // Fill other period by MaxProfile
  3957. if(maxProfile.id != -1)
  3958. {
  3959. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3960. {
  3961. if((maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  3962. (maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  3963. (maxProfile.chargingSchedule[0].duration > 0))
  3964. {
  3965. if((maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].startPeriod >= compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod) &&
  3966. (maxProfile.chargingSchedule[0].duration > compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  3967. {
  3968. tmpPeriod.startPeriod = compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod;
  3969. tmpPeriod.numberPhases = compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].numberPhases;
  3970. tmpPeriod.limit = maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit;
  3971. }
  3972. if((maxProfile.chargingSchedule[0].duration > compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  3973. {
  3974. tmpPeriod.startPeriod = compositeProfile->chargingSchedule[0].duration;
  3975. tmpPeriod.numberPhases = maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  3976. tmpPeriod.limit = maxProfile.chargingSchedule[0].chargingSchedulePeriod[idxMaxPeriod].limit;
  3977. }
  3978. if(tmpPeriod.limit != -1)
  3979. {
  3980. if(tmpPeriod.limit != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  3981. {
  3982. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3983. {
  3984. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  3985. compositePeriodIdx++;
  3986. }
  3987. else
  3988. {
  3989. memcpy(&compositeProfile->chargingSchedule[0].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  3990. }
  3991. }
  3992. }
  3993. }
  3994. }
  3995. }
  3996. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3997. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[0].startSchedule);
  3998. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[0].duration);
  3999. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[0].chargingRateUnit);
  4000. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[0].chargingSchedulePeriod);idxPeriod++)
  4001. {
  4002. if(compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4003. {
  4004. compositeProfile->id = 1;
  4005. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod);
  4006. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit);
  4007. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].numberPhases);
  4008. }
  4009. if(compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit == -1)
  4010. compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].limit =0;
  4011. if(compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4012. compositeProfile->chargingSchedule[0].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4013. }
  4014. if(line)
  4015. free(line);
  4016. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  4017. }
  4018. //==========================================
  4019. // Init all share memory
  4020. //==========================================
  4021. int InitShareMemory()
  4022. {
  4023. int result = PASS;
  4024. int MeterSMId;
  4025. //creat ShmSysConfigAndInfo
  4026. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4027. {
  4028. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4029. result = FAIL;
  4030. }
  4031. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4032. {
  4033. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4034. result = FAIL;
  4035. }
  4036. else
  4037. {}
  4038. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4039. {
  4040. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4041. result = FAIL;
  4042. }
  4043. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4044. {
  4045. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4046. result = FAIL;
  4047. }
  4048. else
  4049. {}
  4050. //creat ShmPsuData
  4051. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4052. {
  4053. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4054. result = FAIL;
  4055. }
  4056. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4057. {
  4058. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4059. result = FAIL;
  4060. }
  4061. else
  4062. {}
  4063. //creat ShmOCPP20Data
  4064. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  4065. {
  4066. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  4067. result = FAIL;
  4068. }
  4069. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4070. {
  4071. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  4072. result = FAIL;
  4073. }
  4074. else
  4075. {}
  4076. /****************************** For Initial Settings************************************************/
  4077. //offline MeterValue Interval
  4078. TempMeterValueInterval = 0;
  4079. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  4080. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  4081. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  4082. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  4083. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  4084. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  4085. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  4086. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  4087. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  4088. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  4089. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  4090. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  4091. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  4092. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  4093. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  4094. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  4095. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  4096. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  4097. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  4098. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  4099. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  4100. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  4101. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  4102. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  4103. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  4104. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  4105. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  4106. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  4107. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  4108. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  4109. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  4110. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  4111. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  4112. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  4113. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  4114. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  4115. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  4116. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  4117. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  4118. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  4119. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  4120. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  4121. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  4122. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  4123. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  4124. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  4125. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  4126. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  4127. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  4128. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  4129. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  4130. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  4131. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  4132. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  4133. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  4134. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  4135. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  4136. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  4137. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  4138. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  4139. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  4140. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  4141. return result;
  4142. }
  4143. int ProcessShareMemory()
  4144. {
  4145. if(InitShareMemory() == FAIL)
  4146. {
  4147. DEBUG_ERROR("InitShareMemory NG\n");
  4148. if(ShmStatusCodeData!=NULL)
  4149. {
  4150. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4151. }
  4152. sleep(5);
  4153. return FAIL;
  4154. }
  4155. return PASS;
  4156. }
  4157. //---------------------common routine---------------------------//
  4158. int isOFFline(void)
  4159. {
  4160. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  4161. {
  4162. if(TempMeterValueInterval >= 2 )
  4163. {
  4164. TempMeterValueInterval = 0;
  4165. return TRUE;
  4166. }
  4167. else
  4168. {
  4169. TempMeterValueInterval = TempMeterValueInterval+ 1;
  4170. return FALSE;
  4171. }
  4172. }
  4173. else
  4174. {
  4175. return FALSE;
  4176. }
  4177. }
  4178. void checkNetworkProfile(void)
  4179. {
  4180. uint8_t isGetProfile = FALSE;
  4181. json_object *priority;
  4182. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  4183. if(!is_error(priority))
  4184. {
  4185. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  4186. {
  4187. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  4188. {
  4189. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  4190. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  4191. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  4192. {
  4193. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  4194. memcpy(ShmSysConfigAndInfo->SysConfig.OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  4195. isGetProfile = TRUE;
  4196. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  4197. break;
  4198. }
  4199. }
  4200. }
  4201. }
  4202. json_object_put(priority);
  4203. if(!isGetProfile && (strlen((char*)ShmOCPP20Data->OcppServerURL) > 0))
  4204. {
  4205. memcpy(ShmSysConfigAndInfo->SysConfig.OcppServerURL, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  4206. }
  4207. DEBUG_INFO("Get network profile URL: %s\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  4208. }
  4209. void CheckSystemValue(void)
  4210. {
  4211. char filenmae[100]={0};
  4212. char str[100]={0};
  4213. int tempIndex = 0;
  4214. //===============================
  4215. // EVSE operation check
  4216. //===============================
  4217. //===============================
  4218. // Heartbeat check
  4219. //===============================
  4220. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  4221. {
  4222. clientTime.Heartbeat = time((time_t*)NULL);
  4223. if(server_sign == TRUE)
  4224. {
  4225. HeartBeatWaitTime = ShmOCPP20Data->BootNotification.Response_interval;
  4226. }
  4227. else
  4228. {
  4229. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  4230. }
  4231. }
  4232. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4233. {
  4234. //parameter for test
  4235. sendHeartbeatRequest(0);
  4236. //==============================================
  4237. // Reset Waiting Time
  4238. //==============================================
  4239. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  4240. }
  4241. //===============================
  4242. // CSU Trigger Reset Conf
  4243. //===============================
  4244. if(isWebsocketSendable && (ShmOCPP20Data->MsMsg.bits.ResetConf == ON))
  4245. {
  4246. sendResetConfirmation((char *)ShmOCPP20Data->Reset.guid);
  4247. }
  4248. //===============================
  4249. // CSU Trigger Authorize Request
  4250. //===============================
  4251. if(isWebsocketSendable &&
  4252. (server_sign == TRUE) &&
  4253. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  4254. (authorizeRetryTimes < 3))
  4255. {
  4256. sendAuthorizeRequest(0);
  4257. authorizeRetryTimes = authorizeRetryTimes + 1;
  4258. if(authorizeRetryTimes < 3)
  4259. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  4260. }
  4261. else if((server_sign == TRUE) &&
  4262. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  4263. (authorizeRetryTimes >= 3))
  4264. {
  4265. authorizeRetryTimes = 0;
  4266. SetOcppConnStatus(FALSE);
  4267. server_sign = FALSE;
  4268. }
  4269. else if((server_sign == FALSE) &&
  4270. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE") == 0) &&
  4271. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  4272. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  4273. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  4274. {
  4275. sendAuthorizeRequest(0);
  4276. }
  4277. //===============================
  4278. // Each connector operation check
  4279. //===============================
  4280. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4281. {
  4282. //==========================================
  4283. // csu trigger DataTransferReq
  4284. //==========================================
  4285. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  4286. {
  4287. sendDataTransferRequest(gun_index);
  4288. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  4289. }
  4290. //===============================
  4291. // CSU Trigger Smart Charging Profilw
  4292. //===============================
  4293. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  4294. {
  4295. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index]);
  4296. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  4297. }
  4298. //==============================================
  4299. // Charger start transaction
  4300. //==============================================
  4301. /*
  4302. if((ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq == ON))
  4303. {
  4304. ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq = OFF;
  4305. sendStartTransactionRequest(gun_index);
  4306. clientTime.StartTransaction = time((time_t*)NULL);
  4307. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4308. }*/
  4309. //==============================================
  4310. // Charger stop transaction
  4311. //==============================================
  4312. /*
  4313. if(((ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq == ON)))
  4314. {
  4315. ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq =OFF;
  4316. sendStopTransactionRequest(gun_index);
  4317. clientTime.StopTransaction = time((time_t*)NULL);
  4318. }*/
  4319. //==============================================
  4320. // Charger status notification & Transaction event report
  4321. //==============================================
  4322. //--- Check Mode Change ---//
  4323. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4324. if(gunType[gun_index] == 'J')
  4325. {
  4326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4327. {
  4328. tempIndex = ((gun_index==2) ? 1: 0);
  4329. }
  4330. else
  4331. {
  4332. tempIndex = gun_index;
  4333. }
  4334. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4335. {
  4336. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4337. {
  4338. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4339. {
  4340. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4341. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4342. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4343. if(SystemInitial == 0)
  4344. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4345. }
  4346. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4347. {
  4348. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4349. if((access(filenmae,F_OK))!=-1)
  4350. {
  4351. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4352. sprintf(str,"rm -f %s",filenmae);
  4353. system(str);
  4354. }
  4355. }
  4356. #if 1 // for TempStopTransaction
  4357. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4358. {
  4359. checkTempStopTransaction(gun_index);
  4360. }
  4361. #endif
  4362. }
  4363. }
  4364. }
  4365. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4366. {
  4367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4368. {
  4369. tempIndex = ((gun_index==2) ? 1: 0);
  4370. }
  4371. else
  4372. {
  4373. tempIndex = gun_index;
  4374. }
  4375. for (int index = 0; index < CCS_QUANTITY; index++)
  4376. {
  4377. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4378. {
  4379. if((SystemInitial > 0) || (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]*/ )
  4380. {
  4381. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4382. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4383. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4384. if(SystemInitial == 0)
  4385. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4386. }
  4387. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4388. {
  4389. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4390. if((access(filenmae,F_OK))!=-1)
  4391. {
  4392. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4393. sprintf(str,"rm -f %s",filenmae);
  4394. system(str);
  4395. }
  4396. }
  4397. #if 1 // for TempStopTransaction
  4398. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4399. {
  4400. checkTempStopTransaction(gun_index);
  4401. }
  4402. #endif
  4403. }
  4404. }
  4405. }
  4406. else if(gunType[gun_index] == 'G')
  4407. {
  4408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4409. {
  4410. tempIndex = ((gun_index==2) ? 1: 0);
  4411. }
  4412. else
  4413. {
  4414. tempIndex = gun_index;
  4415. }
  4416. for (int index = 0; index < GB_QUANTITY; index++)
  4417. {
  4418. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4419. {
  4420. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4421. {
  4422. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4423. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4424. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4425. if(SystemInitial == 0)
  4426. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4427. }
  4428. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4429. {
  4430. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4431. if((access(filenmae,F_OK))!=-1)
  4432. {
  4433. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4434. sprintf(str,"rm -f %s",filenmae);
  4435. system(str);
  4436. }
  4437. }
  4438. #if 1 // for TempStopTransaction
  4439. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4440. {
  4441. checkTempStopTransaction(gun_index);
  4442. }
  4443. #endif
  4444. }
  4445. }
  4446. }
  4447. else if(gunType[gun_index] == 'O')
  4448. {
  4449. tempIndex = gun_index;
  4450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4451. {
  4452. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4453. {
  4454. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4455. {
  4456. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4457. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4458. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4459. if(SystemInitial == 0)
  4460. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4461. }
  4462. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  4463. {
  4464. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4465. if((access(filenmae,F_OK))!=-1)
  4466. {
  4467. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4468. sprintf(str,"rm -f %s",filenmae);
  4469. system(str);
  4470. }
  4471. }
  4472. #if 1 // for TempStopTransaction
  4473. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4474. {
  4475. checkTempStopTransaction(gun_index);
  4476. }
  4477. #endif
  4478. }
  4479. }
  4480. }
  4481. else
  4482. {
  4483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4484. {
  4485. tempIndex = 2;
  4486. }
  4487. else
  4488. {
  4489. tempIndex = gun_index;
  4490. }
  4491. for (int index = 0; index < AC_QUANTITY; index++)
  4492. {
  4493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4494. {
  4495. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4496. {
  4497. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4498. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4499. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4500. if(SystemInitial == 0)
  4501. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4502. }
  4503. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4504. {
  4505. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4506. if((access(filenmae,F_OK))!=-1)
  4507. {
  4508. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4509. sprintf(str,"rm -f %s",filenmae);
  4510. system(str);
  4511. }
  4512. }
  4513. #if 1 // for TempStopTransaction
  4514. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4515. {
  4516. checkTempStopTransaction(gun_index);
  4517. }
  4518. #endif
  4519. }
  4520. }// END
  4521. }
  4522. if(isWebsocketSendable &&
  4523. (cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) &&
  4524. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10) )
  4525. {
  4526. if(SystemInitial > 0)
  4527. SystemInitial -= 1;
  4528. sendStatusNotificationRequest(gun_index);
  4529. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  4530. }
  4531. if(isWebsocketSendable && (server_sign == TRUE) && (cpinitateMsg.bits[gun_index].TransactionEventReq == ON))
  4532. {
  4533. sendTransactionEventRequest(gun_index);
  4534. cpinitateMsg.bits[gun_index].TransactionEventReq = OFF;
  4535. }
  4536. //==============================================
  4537. // Meter report
  4538. //==============================================
  4539. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  4540. {
  4541. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  4542. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  4543. }
  4544. // ClockAlign MeterValue
  4545. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value)))==0):FALSE))
  4546. {
  4547. //check Transaction active
  4548. if(gunType[gun_index] == 'J')
  4549. {
  4550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4551. {
  4552. tempIndex = ((gun_index==2) ? 1: 0);
  4553. }
  4554. else
  4555. {
  4556. tempIndex = gun_index;
  4557. }
  4558. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4559. {
  4560. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4561. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4562. {
  4563. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  4564. {
  4565. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  4566. }
  4567. }
  4568. }// End for CHAdeMO
  4569. }
  4570. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4571. {
  4572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4573. {
  4574. tempIndex = ((gun_index==2) ? 1: 0);
  4575. }
  4576. else
  4577. {
  4578. tempIndex = gun_index;
  4579. }
  4580. for (int index = 0; index < CCS_QUANTITY; index++)
  4581. {
  4582. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4583. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4584. {
  4585. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  4586. {
  4587. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  4588. }
  4589. }
  4590. } // End for CCS
  4591. }
  4592. else if(gunType[gun_index] == 'G')
  4593. {
  4594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4595. {
  4596. tempIndex = ((gun_index==2) ? 1: 0);
  4597. }
  4598. else
  4599. {
  4600. tempIndex = gun_index;
  4601. }
  4602. for (int index = 0; index < GB_QUANTITY; index++)
  4603. {
  4604. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4605. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4606. {
  4607. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  4608. {
  4609. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  4610. }
  4611. }
  4612. }// End for GB
  4613. }
  4614. else if(gunType[gun_index] == 'O')
  4615. {
  4616. tempIndex = gun_index;
  4617. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4618. {
  4619. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4620. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4621. {
  4622. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  4623. {
  4624. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  4625. }
  4626. }
  4627. }
  4628. }
  4629. else
  4630. {
  4631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4632. {
  4633. tempIndex = 2;
  4634. }
  4635. else
  4636. {
  4637. tempIndex = gun_index;
  4638. }
  4639. for (int index = 0; index < AC_QUANTITY; index++)
  4640. {
  4641. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4642. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4643. {
  4644. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  4645. {
  4646. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  4647. }
  4648. }
  4649. }//End for AC
  4650. }
  4651. if(cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON)
  4652. {
  4653. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  4654. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  4655. }
  4656. }
  4657. // Sample period MeterValue
  4658. if(((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1)))
  4659. {
  4660. //check Transaction active
  4661. if(gunType[gun_index] == 'J')
  4662. {
  4663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4664. {
  4665. tempIndex = ((gun_index==2) ? 1: 0);
  4666. }
  4667. else
  4668. {
  4669. tempIndex = gun_index;
  4670. }
  4671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4672. {
  4673. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4674. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4675. {
  4676. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4677. {
  4678. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  4679. }
  4680. }
  4681. }// End for CHAdeMO
  4682. }
  4683. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4684. {
  4685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4686. {
  4687. tempIndex = ((gun_index==2) ? 1: 0);
  4688. }
  4689. else
  4690. {
  4691. tempIndex = gun_index;
  4692. }
  4693. for (int index = 0; index < CCS_QUANTITY; index++)
  4694. {
  4695. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4696. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4697. {
  4698. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4699. {
  4700. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  4701. }
  4702. }
  4703. } // End for CCS
  4704. }
  4705. else if(gunType[gun_index] == 'G')
  4706. {
  4707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4708. {
  4709. tempIndex = ((gun_index==2) ? 1: 0);
  4710. }
  4711. else
  4712. {
  4713. tempIndex = gun_index;
  4714. }
  4715. for (int index = 0; index < GB_QUANTITY; index++)
  4716. {
  4717. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4718. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4719. {
  4720. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4721. {
  4722. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  4723. }
  4724. }
  4725. }// End for GB
  4726. }
  4727. else if(gunType[gun_index] == 'O')
  4728. {
  4729. tempIndex = gun_index;
  4730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4731. {
  4732. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4733. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4734. {
  4735. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4736. {
  4737. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  4738. }
  4739. }
  4740. }
  4741. }
  4742. else
  4743. {
  4744. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4745. {
  4746. tempIndex = 2;
  4747. }
  4748. else
  4749. {
  4750. tempIndex = gun_index;
  4751. }
  4752. for (int index = 0; index < AC_QUANTITY; index++)
  4753. {
  4754. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4755. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4756. {
  4757. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4758. {
  4759. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  4760. }
  4761. }
  4762. }//End for AC
  4763. }
  4764. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  4765. {
  4766. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  4767. storeTempStopTransaction(gun_index);
  4768. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  4769. }
  4770. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4771. }
  4772. //==============================================
  4773. // Check Connector reserved
  4774. //==============================================
  4775. //===============================
  4776. // Check if Reserve is expired
  4777. //===============================
  4778. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0) )
  4779. {
  4780. double diff_t;
  4781. struct tm tp;
  4782. // current time
  4783. time_t t = time(NULL);
  4784. strptime((char *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime, "%Y-%m-%dT%H:%M:%S", &tp);
  4785. tp.tm_isdst = -1;
  4786. time_t utc = mktime(&tp);
  4787. diff_t = difftime(utc, t);
  4788. if(diff_t <= 0)
  4789. {
  4790. DEBUG_INFO("reserve expired.\n");
  4791. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  4792. }
  4793. }//END OF Check if Reserve is expired
  4794. //==========================================
  4795. // csu trigger FirmwareStatusNotificationReq
  4796. //==========================================
  4797. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  4798. {
  4799. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  4800. }
  4801. //==========================================
  4802. // csu trigger CancelReservationConf
  4803. //==========================================
  4804. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  4805. {
  4806. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  4807. }
  4808. //==========================================
  4809. // csu trigger ChangeAvailabilityConf
  4810. //==========================================
  4811. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  4812. {
  4813. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  4814. }
  4815. //==========================================
  4816. // csu trigger UnlockConnectorConf
  4817. //==========================================
  4818. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  4819. {
  4820. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  4821. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  4822. }
  4823. //==========================================
  4824. // csu trigger ReserveNowConf
  4825. //==========================================
  4826. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  4827. {
  4828. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  4829. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  4830. }
  4831. }
  4832. }
  4833. //==========================================
  4834. // send request routine
  4835. //==========================================
  4836. int sendAuthorizeRequest(int gun_index)
  4837. {
  4838. mtrace();
  4839. int result = FAIL;
  4840. char message[4096]={0};
  4841. char guid[37];
  4842. char tempdata[128]={0};
  4843. json_object *Authorize = json_object_new_object();
  4844. json_object *idToken = json_object_new_object();
  4845. DEBUG_INFO("sendAuthorizeRequest...\n");
  4846. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  4847. //Local Authorize
  4848. if ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "TRUE")==0) &&(ShmOCPP20Data->OcppConnStatus == 0))
  4849. {
  4850. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  4851. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  4852. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  4853. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  4854. result = PASS;
  4855. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  4856. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  4857. authorizeRetryTimes = 0;
  4858. return result;
  4859. }
  4860. 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))||
  4861. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0)))
  4862. {
  4863. // Query idtag from cache
  4864. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  4865. // Query idtag from list
  4866. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  4867. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  4868. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  4869. {
  4870. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  4871. {
  4872. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idToken.idToken);
  4873. }
  4874. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  4875. {
  4876. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idToken.idToken);
  4877. }
  4878. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  4879. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  4880. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4881. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  4882. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  4883. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  4884. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  4885. authorizeRetryTimes = 0;
  4886. return result;
  4887. }
  4888. else
  4889. {
  4890. DEBUG_INFO("offline Local Authorization get result !!!!\n");
  4891. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  4892. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4893. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  4894. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  4895. else
  4896. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  4897. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  4898. result = PASS;
  4899. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  4900. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  4901. authorizeRetryTimes = 0;
  4902. return result;
  4903. }
  4904. }
  4905. //initialize struct Authorize
  4906. memset(&(ShmOCPP20Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4907. //get data from shared memory
  4908. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4909. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  4910. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  4911. json_object_object_add(Authorize, "idToken", idToken);
  4912. random_uuid(guid);
  4913. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  4914. json_object_put(Authorize);
  4915. LWS_Send(message);
  4916. sprintf(tempdata, "Authorize,%d", gun_index);
  4917. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  4918. {
  4919. result = PASS;
  4920. }
  4921. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  4922. return result;
  4923. }
  4924. int sendBootNotificationRequest()
  4925. {
  4926. mtrace();
  4927. int result = FAIL;
  4928. char message[4096]={0};
  4929. char guid[37]={0};
  4930. char tempdata[128]={0};
  4931. json_object *BootNotification = json_object_new_object();
  4932. json_object *chargingStation = json_object_new_object();
  4933. json_object *modem = json_object_new_object();
  4934. // Fill BootNotification fields
  4935. DB_getBooType();
  4936. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  4937. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4938. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4939. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4940. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4941. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4942. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  4943. {
  4944. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  4945. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  4946. json_object_object_add(chargingStation, "modem", modem);
  4947. }
  4948. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  4949. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  4950. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  4951. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  4952. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  4953. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  4954. random_uuid(guid);
  4955. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  4956. json_object_put(BootNotification);
  4957. LWS_Send(message);
  4958. sprintf(tempdata, "BootNotification,0");
  4959. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  4960. {
  4961. result = PASS;
  4962. }
  4963. return result;
  4964. }
  4965. int sendClearedChargingLimitRequest(int gun_index)
  4966. {
  4967. mtrace();
  4968. int result = FAIL;
  4969. char message[4096]={0};
  4970. char guid[37]={0};
  4971. char tempdata[128]={0};
  4972. json_object *ClearedChargingLimit = json_object_new_object();
  4973. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  4974. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  4975. random_uuid(guid);
  4976. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  4977. json_object_put(ClearedChargingLimit);
  4978. LWS_Send(message);
  4979. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  4980. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  4981. {
  4982. result = PASS;
  4983. }
  4984. return result;
  4985. }
  4986. int sendDataTransferRequest(int gun_index)
  4987. {
  4988. mtrace();
  4989. char message[1000]={0};
  4990. char guid[37]={0};
  4991. char tempdata[65]={0};
  4992. int result = FAIL;
  4993. random_uuid(guid);
  4994. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4995. MESSAGE_TYPE_CALL,
  4996. guid,
  4997. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  4998. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  4999. ShmOCPP20Data->DataTransfer[gun_index].data);
  5000. LWS_Send(message);
  5001. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5002. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5003. {
  5004. result = PASS;
  5005. }
  5006. return result;
  5007. }
  5008. int sendFirmwareStatusNotificationRequest(char *status)
  5009. {
  5010. mtrace();
  5011. int result = FAIL;
  5012. char message[110]={0};
  5013. char guid[37]={0};
  5014. char tempdata[65]={0};
  5015. json_object *FirmwareStatusNotification = json_object_new_object();
  5016. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5017. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  5018. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  5019. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  5020. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  5021. random_uuid(guid);
  5022. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5023. json_object_put(FirmwareStatusNotification);
  5024. LWS_SendNow(message);
  5025. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5026. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5027. {
  5028. result = PASS;
  5029. }
  5030. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  5031. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  5032. //record status
  5033. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  5034. {
  5035. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  5036. }
  5037. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  5038. {
  5039. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  5040. }
  5041. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  5042. {
  5043. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  5044. }
  5045. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  5046. {
  5047. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  5048. }
  5049. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  5050. {
  5051. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  5052. }
  5053. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  5054. {
  5055. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  5056. }
  5057. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  5058. {
  5059. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  5060. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5061. }
  5062. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  5063. {
  5064. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  5065. }
  5066. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  5067. {
  5068. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  5069. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5070. }
  5071. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  5072. {
  5073. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  5074. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5075. }
  5076. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  5077. {
  5078. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  5079. }
  5080. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  5081. {
  5082. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  5083. }
  5084. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  5085. {
  5086. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  5087. }
  5088. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  5089. {
  5090. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  5091. }
  5092. return result;
  5093. }
  5094. int sendGet15118EVCertificateRequest()
  5095. {
  5096. mtrace();
  5097. int result = FAIL;
  5098. char message[4096]={0};
  5099. char guid[37]={0};
  5100. char tempdata[128]={0};
  5101. json_object *Get15118EVCertificate = json_object_new_object();
  5102. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  5103. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  5104. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  5105. random_uuid(guid);
  5106. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  5107. json_object_put(Get15118EVCertificate);
  5108. LWS_Send(message);
  5109. sprintf(tempdata, "Get15118EVCertificate,0");
  5110. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5111. {
  5112. result = PASS;
  5113. }
  5114. return result;
  5115. }
  5116. int sendGetCertificateStatusRequest()
  5117. {
  5118. mtrace();
  5119. int result = FAIL;
  5120. char message[4096]={0};
  5121. char guid[37]={0};
  5122. char tempdata[128]={0};
  5123. json_object *GetCertificateStatus = json_object_new_object();
  5124. json_object *ocspRequestData = json_object_new_object();
  5125. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5126. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  5127. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5128. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  5129. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  5130. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  5131. random_uuid(guid);
  5132. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  5133. json_object_put(GetCertificateStatus);
  5134. LWS_Send(message);
  5135. sprintf(tempdata, "GetCertificateStatus,0");
  5136. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5137. {
  5138. result = PASS;
  5139. }
  5140. return result;
  5141. }
  5142. int sendHeartbeatRequest()
  5143. {
  5144. mtrace();
  5145. int result = FAIL;
  5146. char message[40096]={0};
  5147. char guid[37]={0};
  5148. char tempdata[128]={0};
  5149. random_uuid(guid);
  5150. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5151. , MESSAGE_TYPE_CALL
  5152. , guid );
  5153. LWS_Send(message);
  5154. sprintf(tempdata, "Heartbeat,%d", 0);
  5155. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5156. {
  5157. result = PASS;
  5158. }
  5159. return result;
  5160. }
  5161. int sendLogStatusNotificationRequest(char *status)
  5162. {
  5163. mtrace();
  5164. int result = FAIL;
  5165. char message[4096]={0};
  5166. char guid[37]={0};
  5167. char tempdata[128]={0};
  5168. json_object *LogStatusNotification = json_object_new_object();
  5169. DEBUG_INFO("sendLogStatusNotificationRequest \n");
  5170. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  5171. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  5172. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  5173. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  5174. random_uuid(guid);
  5175. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5176. json_object_put(LogStatusNotification);
  5177. LWS_SendNow(message);
  5178. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5179. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5180. {
  5181. result = PASS;
  5182. }
  5183. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  5184. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  5185. //record status
  5186. if(strcmp(status,"BadMessage")==0)
  5187. {
  5188. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  5189. }
  5190. else if(strcmp(status,"Idle")==0)
  5191. {
  5192. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  5193. }
  5194. else if(strcmp(status,"NotSupportedOperation")==0)
  5195. {
  5196. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  5197. }
  5198. else if(strcmp(status,"PermissionDenied")==0)
  5199. {
  5200. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  5201. }
  5202. else if(strcmp(status,"Uploaded")==0)
  5203. {
  5204. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  5205. }
  5206. else if(strcmp(status,"UploadFailure")==0)
  5207. {
  5208. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  5209. }
  5210. else if(strcmp(status,"Uploading")==0)
  5211. {
  5212. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  5213. }
  5214. return result;
  5215. }
  5216. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  5217. {
  5218. mtrace();
  5219. int result = FAIL;
  5220. char guid[37]={0};
  5221. char tempdata[65]={0};
  5222. int tempIndex = 0;
  5223. json_object *MeterValueReq = json_object_new_object();
  5224. json_object *meterValues = json_object_new_array();
  5225. json_object *meterValue = json_object_new_object();
  5226. json_object *sampledValues = json_object_new_array();
  5227. json_object *sampledValue = json_object_new_object();
  5228. json_object *unitOfMeasure = json_object_new_object();
  5229. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5230. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5231. //set value
  5232. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  5233. //UTC Date time
  5234. struct timeval tmnow;
  5235. struct tm *tm;
  5236. char buf[28];//, usec_buf[6];
  5237. gettimeofday(&tmnow, NULL);
  5238. time_t t;
  5239. t = time(NULL);
  5240. /*UTC time and date*/
  5241. tm = gmtime(&t);
  5242. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5243. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  5244. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5245. //idx_sample=0;
  5246. //********************************(1)Current.Import L1************************************************/
  5247. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5248. if(gunType[gun_index] == 'J')
  5249. {
  5250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5251. {
  5252. tempIndex = ((gun_index==2) ? 1: 0);
  5253. }
  5254. else
  5255. {
  5256. tempIndex = gun_index;
  5257. }
  5258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5259. {
  5260. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5261. {
  5262. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent;
  5263. }
  5264. }
  5265. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5266. }
  5267. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  5268. {
  5269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5270. {
  5271. tempIndex = ((gun_index==2) ? 1: 0);
  5272. }
  5273. else
  5274. {
  5275. tempIndex = gun_index;
  5276. }
  5277. for (int index = 0; index < CCS_QUANTITY; index++)
  5278. {
  5279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5280. {
  5281. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent;
  5282. }
  5283. }
  5284. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5285. }
  5286. else if(gunType[gun_index] == 'G')
  5287. {
  5288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5289. {
  5290. tempIndex = ((gun_index==2) ? 1: 0);
  5291. }
  5292. else
  5293. {
  5294. tempIndex = gun_index;
  5295. }
  5296. for (int index = 0; index < GB_QUANTITY; index++)
  5297. {
  5298. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5299. {
  5300. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent;
  5301. }
  5302. }
  5303. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5304. }
  5305. else if(gunType[gun_index] == 'O')
  5306. {
  5307. tempIndex = gun_index;
  5308. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5309. {
  5310. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5311. {
  5312. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent;
  5313. }
  5314. }
  5315. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5316. }
  5317. else
  5318. {
  5319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5320. {
  5321. tempIndex = 2;
  5322. }
  5323. else
  5324. {
  5325. tempIndex = gun_index;
  5326. }
  5327. for (int index = 0; index < AC_QUANTITY; index++)
  5328. {
  5329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5330. {
  5331. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent;
  5332. }
  5333. }
  5334. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  5335. }
  5336. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  5337. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  5338. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5339. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  5340. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  5341. //idx_sample=1;
  5342. //********************************(2)Energy.Active.Import.Register ************************************************/
  5343. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5344. if(gunType[gun_index] == 'J')
  5345. {
  5346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5347. {
  5348. tempIndex = ((gun_index==2) ? 1: 0);
  5349. }
  5350. else
  5351. {
  5352. tempIndex = gun_index;
  5353. }
  5354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5355. {
  5356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5357. {
  5358. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5359. }
  5360. }
  5361. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5362. }
  5363. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  5364. {
  5365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5366. {
  5367. tempIndex = ((gun_index==2) ? 1: 0);
  5368. }
  5369. else
  5370. {
  5371. tempIndex = gun_index;
  5372. }
  5373. for (int index = 0; index < CCS_QUANTITY; index++)
  5374. {
  5375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5376. {
  5377. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5378. }
  5379. }
  5380. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5381. }
  5382. else if(gunType[gun_index] == 'G')
  5383. {
  5384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5385. {
  5386. tempIndex = ((gun_index==2) ? 1: 0);
  5387. }
  5388. else
  5389. {
  5390. tempIndex = gun_index;
  5391. }
  5392. for (int index = 0; index < GB_QUANTITY; index++)
  5393. {
  5394. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5395. {
  5396. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5397. }
  5398. }
  5399. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5400. }
  5401. else if(gunType[gun_index] == 'O')
  5402. {
  5403. tempIndex = gun_index;
  5404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5405. {
  5406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5407. {
  5408. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5409. }
  5410. }
  5411. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5412. }
  5413. else
  5414. {
  5415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5416. {
  5417. tempIndex = 2;
  5418. }
  5419. else
  5420. {
  5421. tempIndex = gun_index;
  5422. }
  5423. for (int index = 0; index < AC_QUANTITY; index++)
  5424. {
  5425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5426. {
  5427. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5428. }
  5429. }
  5430. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  5431. }
  5432. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  5433. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  5434. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5435. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  5436. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  5437. //idx_sample=2;
  5438. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5439. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5440. if(gunType[gun_index] == 'J')
  5441. {
  5442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5443. {
  5444. tempIndex = ((gun_index==2) ? 1: 0);
  5445. }
  5446. else
  5447. {
  5448. tempIndex = gun_index;
  5449. }
  5450. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5451. {
  5452. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5453. {
  5454. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  5455. }
  5456. } // END OF FOR CHAdeMO_QUANTITY
  5457. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5458. }
  5459. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  5460. {
  5461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5462. {
  5463. tempIndex = ((gun_index==2) ? 1: 0);
  5464. }
  5465. else
  5466. {
  5467. tempIndex = gun_index;
  5468. }
  5469. for (int index = 0; index < CCS_QUANTITY; index++)
  5470. {
  5471. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5472. {
  5473. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  5474. }
  5475. } // END OF CCS_QUANTITY
  5476. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5477. }
  5478. else if(gunType[gun_index] == 'G')
  5479. {
  5480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5481. {
  5482. tempIndex = ((gun_index==2) ? 1: 0);
  5483. }
  5484. else
  5485. {
  5486. tempIndex = gun_index;
  5487. }
  5488. for (int index = 0; index < GB_QUANTITY; index++)
  5489. {
  5490. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5491. {
  5492. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  5493. }
  5494. } // END OF GB_QUANTITY
  5495. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5496. }
  5497. else if(gunType[gun_index] == 'O')
  5498. {
  5499. tempIndex = gun_index;
  5500. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5503. {
  5504. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy;
  5505. }
  5506. }
  5507. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5508. }
  5509. else
  5510. {
  5511. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5512. {
  5513. tempIndex = 2;
  5514. }
  5515. else
  5516. {
  5517. tempIndex = gun_index;
  5518. }
  5519. for (int index = 0; index < AC_QUANTITY; index++)
  5520. {
  5521. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5522. {
  5523. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  5524. }
  5525. }
  5526. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  5527. }
  5528. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  5529. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  5530. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5531. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  5532. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  5533. //idx_sample=3;
  5534. //********************************(4)Power.Active.Import************************************************/
  5535. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5536. if(gunType[gun_index] == 'J')
  5537. {
  5538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5539. {
  5540. tempIndex = ((gun_index==2) ? 1: 0);
  5541. }
  5542. else
  5543. {
  5544. tempIndex = gun_index;
  5545. }
  5546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5547. {
  5548. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5549. {
  5550. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower;
  5551. }
  5552. } // END OF FOR
  5553. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5554. }
  5555. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  5556. {
  5557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5558. {
  5559. tempIndex = ((gun_index==2) ? 1: 0);
  5560. }
  5561. else
  5562. {
  5563. tempIndex = gun_index;
  5564. }
  5565. for (int index = 0; index < CCS_QUANTITY; index++)
  5566. {
  5567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5568. {
  5569. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower;
  5570. }
  5571. }
  5572. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5573. }
  5574. else if(gunType[gun_index] == 'G')
  5575. {
  5576. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5577. {
  5578. tempIndex = ((gun_index==2) ? 1: 0);
  5579. }
  5580. else
  5581. {
  5582. tempIndex = gun_index;
  5583. }
  5584. for (int index = 0; index < GB_QUANTITY; index++)
  5585. {
  5586. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5587. {
  5588. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5589. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower;
  5590. }
  5591. }
  5592. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5593. }
  5594. else if(gunType[gun_index] == 'O')
  5595. {
  5596. tempIndex = gun_index;
  5597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5598. {
  5599. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5600. {
  5601. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5602. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower;
  5603. }
  5604. }
  5605. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5606. }
  5607. else
  5608. {
  5609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5610. {
  5611. tempIndex = 2;
  5612. }
  5613. else
  5614. {
  5615. tempIndex = gun_index;
  5616. }
  5617. for (int index = 0; index < AC_QUANTITY; index++)
  5618. {
  5619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5620. {
  5621. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower;
  5622. }
  5623. }
  5624. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  5625. }
  5626. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  5627. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  5628. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5629. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  5630. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  5631. //idx_sample=4;
  5632. //***********************************************(5)VOLTAGE L1******************************************************/
  5633. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5634. if(gunType[gun_index] == 'J')
  5635. {
  5636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5637. {
  5638. tempIndex = ((gun_index==2) ? 1: 0);
  5639. }
  5640. else
  5641. {
  5642. tempIndex = gun_index;
  5643. }
  5644. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5645. {
  5646. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5647. {
  5648. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage;
  5649. }
  5650. }
  5651. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5652. }
  5653. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  5654. {
  5655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5656. {
  5657. tempIndex = ((gun_index==2) ? 1: 0);
  5658. }
  5659. else
  5660. {
  5661. tempIndex = gun_index;
  5662. }
  5663. for (int index = 0; index < CCS_QUANTITY; index++)
  5664. {
  5665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5666. {
  5667. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage;
  5668. }
  5669. }
  5670. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5671. }
  5672. else if(gunType[gun_index] == 'G')
  5673. {
  5674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5675. {
  5676. tempIndex = ((gun_index==2) ? 1: 0);
  5677. }
  5678. else
  5679. {
  5680. tempIndex = gun_index;
  5681. }
  5682. for (int index = 0; index < GB_QUANTITY; index++)
  5683. {
  5684. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5685. {
  5686. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage;
  5687. }
  5688. }
  5689. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5690. }
  5691. else if(gunType[gun_index] == 'O')
  5692. {
  5693. tempIndex = gun_index;
  5694. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5695. {
  5696. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5697. {
  5698. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage;
  5699. }
  5700. }
  5701. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5702. }
  5703. else
  5704. {
  5705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5706. {
  5707. tempIndex = 2;
  5708. }
  5709. else
  5710. {
  5711. tempIndex = gun_index;
  5712. }
  5713. for (int index = 0; index < AC_QUANTITY; index++)
  5714. {
  5715. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5716. {
  5717. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage;
  5718. }
  5719. }
  5720. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  5721. }
  5722. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  5723. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  5724. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5725. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  5726. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  5727. //***********************************************(6)SOC******************************************************/
  5728. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  5729. {
  5730. //idx_sample=5;
  5731. //sampledValue = NULL;
  5732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5733. {
  5734. tempIndex = ((gun_index==2) ? 1: 0);
  5735. }
  5736. else
  5737. {
  5738. tempIndex = gun_index;
  5739. }
  5740. if(gunType[gun_index] == 'J')
  5741. {
  5742. //tempIndex = ((gun_index==2) ? 1: 0);
  5743. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5744. {
  5745. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5746. {
  5747. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  5748. }
  5749. }
  5750. }
  5751. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  5752. {
  5753. //tempIndex = ((gun_index==2) ? 1: 0);
  5754. for (int index = 0; index < CCS_QUANTITY; index++)
  5755. {
  5756. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5757. {
  5758. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  5759. }
  5760. }
  5761. }
  5762. else if(gunType[gun_index] == 'G')
  5763. {
  5764. //tempIndex = ((gun_index==2) ? 1: 0);
  5765. for (int index = 0; index < GB_QUANTITY; index++)
  5766. {
  5767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5768. {
  5769. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  5770. }
  5771. }
  5772. }
  5773. else if(gunType[gun_index] == 'O')
  5774. {
  5775. //tempIndex = ((gun_index==2) ? 1: 0);
  5776. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5777. {
  5778. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5779. {
  5780. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  5781. }
  5782. }
  5783. }
  5784. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  5785. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  5786. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5787. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  5788. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  5789. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  5790. }
  5791. //********************************(7)Current.Import L2************************************************/
  5792. // Only for AC 3 phase
  5793. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  5794. {
  5795. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5796. {
  5797. tempIndex = 2;
  5798. }
  5799. else
  5800. {
  5801. tempIndex = gun_index;
  5802. }
  5803. for (int index = 0; index < AC_QUANTITY; index++)
  5804. {
  5805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5806. {
  5807. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2;
  5808. }
  5809. }
  5810. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  5811. }
  5812. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  5813. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  5814. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5815. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  5816. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  5817. //********************************(8)Current.Import L3************************************************/
  5818. // Only for AC 3 phase
  5819. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  5820. {
  5821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5822. {
  5823. tempIndex = 2;
  5824. }
  5825. else
  5826. {
  5827. tempIndex = gun_index;
  5828. }
  5829. for (int index = 0; index < AC_QUANTITY; index++)
  5830. {
  5831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5832. {
  5833. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3;
  5834. }
  5835. }
  5836. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5837. }
  5838. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  5839. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  5840. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5841. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  5842. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  5843. //***********************************************(9)VOLTAGE L2******************************************************/
  5844. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  5845. {
  5846. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5847. {
  5848. tempIndex = 2;
  5849. }
  5850. else
  5851. {
  5852. tempIndex = gun_index;
  5853. }
  5854. for (int index = 0; index < AC_QUANTITY; index++)
  5855. {
  5856. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5857. {
  5858. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2;
  5859. }
  5860. }
  5861. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  5862. }
  5863. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  5864. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  5865. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5866. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  5867. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  5868. //***********************************************(10)VOLTAGE L3******************************************************/
  5869. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  5870. {
  5871. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5872. {
  5873. tempIndex = 2;
  5874. }
  5875. else
  5876. {
  5877. tempIndex = gun_index;
  5878. }
  5879. for (int index = 0; index < AC_QUANTITY; index++)
  5880. {
  5881. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5882. {
  5883. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3;
  5884. }
  5885. }
  5886. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5887. }
  5888. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  5889. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  5890. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5891. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  5892. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  5893. // Message create ====================================================================================================
  5894. random_uuid(guid);
  5895. uint8_t idxMeter = 0;
  5896. while(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp) > 0)
  5897. {
  5898. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  5899. {
  5900. if(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value > 0)
  5901. {
  5902. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  5903. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  5904. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  5905. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  5906. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  5907. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  5908. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  5909. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  5910. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  5911. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  5912. {
  5913. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  5914. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  5915. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  5916. }
  5917. json_object_array_add(sampledValues, sampledValue);
  5918. }
  5919. }
  5920. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  5921. json_object_object_add(meterValue, "sampledValue", sampledValues);
  5922. json_object_array_add(meterValues, meterValue);
  5923. idxMeter++;
  5924. }
  5925. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  5926. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  5927. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5928. ,gun_index + 1
  5929. ,MESSAGE_TYPE_CALL
  5930. ,guid
  5931. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5932. json_object_put(MeterValueReq);
  5933. // Put request guid to hash map
  5934. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5935. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5936. {
  5937. result = PASS;
  5938. }
  5939. if((dataType != ReadingContextEnumType_Trigger) &&
  5940. (dataType != ReadingContextEnumType_Sample_Clock))
  5941. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5942. else
  5943. {
  5944. if(FirstHeartBeat)
  5945. LWS_Send(queuedata +2);
  5946. }
  5947. return result;
  5948. }
  5949. int sendNotifyChargingLimitRequest(int gun_index)
  5950. {
  5951. mtrace();
  5952. int result = FAIL;
  5953. char message[4096]={0};
  5954. char guid[37]={0};
  5955. char tempdata[128]={0};
  5956. json_object *NotifyChargingLimit = json_object_new_object();
  5957. json_object *chargingLimit = json_object_new_object();
  5958. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  5959. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  5960. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  5961. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  5962. random_uuid(guid);
  5963. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  5964. json_object_put(NotifyChargingLimit);
  5965. LWS_Send(message);
  5966. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  5967. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5968. {
  5969. result = PASS;
  5970. }
  5971. return result;
  5972. }
  5973. int sendNotifyCustomerInformationRequest()
  5974. {
  5975. mtrace();
  5976. int result = FAIL;
  5977. char message[4096]={0};
  5978. char guid[37]={0};
  5979. char tempdata[128]={0};
  5980. json_object *NotifyCustomerInformation = json_object_new_object();
  5981. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  5982. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  5983. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  5984. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  5985. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  5986. random_uuid(guid);
  5987. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  5988. json_object_put(NotifyCustomerInformation);
  5989. LWS_Send(message);
  5990. sprintf(tempdata, "NotifyCustomerInformation,0");
  5991. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5992. {
  5993. result = PASS;
  5994. }
  5995. return result;
  5996. }
  5997. int sendNotifyDisplayMessagesRequest()
  5998. {
  5999. mtrace();
  6000. int result = FAIL;
  6001. char message[4096]={0};
  6002. char guid[37]={0};
  6003. char tempdata[128]={0};
  6004. json_object *NotifyDisplayMessages = json_object_new_object();
  6005. json_object *messageInfos = json_object_new_array();
  6006. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  6007. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  6008. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  6009. {
  6010. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  6011. {
  6012. json_object *messageInfo = json_object_new_object();
  6013. json_object *message = json_object_new_object();
  6014. json_object *display = json_object_new_object();
  6015. json_object *evse = json_object_new_object();
  6016. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  6017. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  6018. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  6019. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  6020. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  6021. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  6022. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  6023. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  6024. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  6025. json_object_object_add(messageInfo, "message", message);
  6026. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  6027. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  6028. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  6029. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  6030. json_object_object_add(display, "evse",evse);
  6031. json_object_object_add(messageInfo, "evse", display);
  6032. json_object_array_add(messageInfos, messageInfo);
  6033. }
  6034. }
  6035. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  6036. random_uuid(guid);
  6037. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  6038. json_object_put(NotifyDisplayMessages);
  6039. LWS_Send(message);
  6040. sprintf(tempdata, "NotifyDisplayMessages,0");
  6041. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6042. {
  6043. result = PASS;
  6044. }
  6045. return result;
  6046. }
  6047. int sendNotifyEVChargingNeedsRequest(int gun_index)
  6048. {
  6049. mtrace();
  6050. int result = FAIL;
  6051. char message[4096]={0};
  6052. char guid[37]={0};
  6053. char tempdata[128]={0};
  6054. json_object *NotifyEVChargingNeeds = json_object_new_object();
  6055. json_object *chargingNeeds = json_object_new_object();
  6056. json_object *acChargingParameters = json_object_new_object();
  6057. json_object *dcChargingParameters = json_object_new_object();
  6058. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  6059. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  6060. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  6061. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  6062. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  6063. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  6064. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  6065. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  6066. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  6067. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  6068. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  6069. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  6070. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  6071. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  6072. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  6073. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  6074. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  6075. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  6076. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  6077. random_uuid(guid);
  6078. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  6079. json_object_put(NotifyEVChargingNeeds);
  6080. LWS_Send(message);
  6081. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  6082. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6083. {
  6084. result = PASS;
  6085. }
  6086. return result;
  6087. }
  6088. int sendNotifyEVChargingScheduleRequest(int gun_index)
  6089. {
  6090. mtrace();
  6091. int result = FAIL;
  6092. char message[4096]={0};
  6093. char guid[37]={0};
  6094. char tempdata[128]={0};
  6095. json_object *NotifyEVChargingSchedule = json_object_new_object();
  6096. json_object *chargingSchedule = json_object_new_object();
  6097. json_object *periods = json_object_new_array();
  6098. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  6099. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  6100. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  6101. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  6102. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  6103. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  6104. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  6105. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  6106. {
  6107. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  6108. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  6109. {
  6110. json_object *Period = json_object_new_object();
  6111. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  6112. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  6113. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  6114. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  6115. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  6116. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  6117. json_object_array_add(periods, Period);
  6118. }
  6119. }
  6120. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  6121. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  6122. random_uuid(guid);
  6123. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  6124. json_object_put(NotifyEVChargingSchedule);
  6125. LWS_Send(message);
  6126. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  6127. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6128. {
  6129. result = PASS;
  6130. }
  6131. return result;
  6132. }
  6133. int sendNotifyEventRequest()
  6134. {
  6135. mtrace();
  6136. int result = FAIL;
  6137. char message[4096]={0};
  6138. char guid[37]={0};
  6139. char tempdata[128]={0};
  6140. json_object *NotifyEvent = json_object_new_object();
  6141. json_object *eventDatas = json_object_new_array();
  6142. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  6143. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  6144. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  6145. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  6146. {
  6147. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  6148. {
  6149. json_object *eventData = json_object_new_object();
  6150. json_object *component = json_object_new_object();
  6151. json_object *evse = json_object_new_object();
  6152. json_object *variable = json_object_new_object();
  6153. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  6154. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  6155. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  6156. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  6157. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  6158. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  6159. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  6160. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  6161. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  6162. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  6163. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  6164. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  6165. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  6166. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  6167. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  6168. json_object_object_add(component, "evse",evse);
  6169. json_object_object_add(eventData, "component", component);
  6170. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  6171. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  6172. json_object_object_add(eventData, "variable", variable);
  6173. json_object_array_add(eventDatas, eventData);
  6174. }
  6175. }
  6176. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  6177. random_uuid(guid);
  6178. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  6179. json_object_put(NotifyEvent);
  6180. LWS_Send(message);
  6181. sprintf(tempdata, "NotifyEvent,0");
  6182. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6183. {
  6184. result = PASS;
  6185. }
  6186. return result;
  6187. }
  6188. int sendNotifyMonitoringReportRequest()
  6189. {
  6190. mtrace();
  6191. int result = FAIL;
  6192. char message[4096]={0};
  6193. char guid[37]={0};
  6194. char tempdata[128]={0};
  6195. json_object *NotifyMonitoringReport = json_object_new_object();
  6196. json_object *monitors = json_object_new_array();
  6197. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  6198. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  6199. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  6200. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  6201. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  6202. {
  6203. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  6204. {
  6205. json_object *monitor = json_object_new_object();
  6206. json_object *component = json_object_new_object();
  6207. json_object *evse = json_object_new_object();
  6208. json_object *variable = json_object_new_object();
  6209. json_object *variableMonitorings = json_object_new_array();
  6210. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  6211. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  6212. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  6213. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  6214. json_object_object_add(component, "evse",evse);
  6215. json_object_object_add(monitor, "component", component);
  6216. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  6217. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  6218. json_object_object_add(monitor, "variable", variable);
  6219. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  6220. {
  6221. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  6222. {
  6223. json_object *variableMonitoring = json_object_new_object();
  6224. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  6225. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  6226. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  6227. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  6228. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  6229. json_object_array_add(variableMonitorings, variableMonitoring);
  6230. }
  6231. }
  6232. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  6233. json_object_array_add(monitors, monitor);
  6234. }
  6235. }
  6236. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  6237. random_uuid(guid);
  6238. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  6239. json_object_put(NotifyMonitoringReport);
  6240. LWS_Send(message);
  6241. sprintf(tempdata, "NotifyMonitoringReport,0");
  6242. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6243. {
  6244. result = PASS;
  6245. }
  6246. return result;
  6247. }
  6248. int sendNotifyReportRequest()
  6249. {
  6250. mtrace();
  6251. int result = FAIL;
  6252. char message[4096]={0};
  6253. char guid[37]={0};
  6254. char tempdata[128]={0};
  6255. json_object *NotifyReport = json_object_new_object();
  6256. json_object *reportDatas = json_object_new_array();
  6257. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  6258. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  6259. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  6260. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  6261. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  6262. {
  6263. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  6264. {
  6265. json_object *reportData = json_object_new_object();
  6266. json_object *component = json_object_new_object();
  6267. json_object *evse = json_object_new_object();
  6268. json_object *variable = json_object_new_object();
  6269. json_object *variableAttributes = json_object_new_array();
  6270. json_object *variableCharacteristics = json_object_new_object();
  6271. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  6272. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  6273. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  6274. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  6275. json_object_object_add(component, "evse",evse);
  6276. json_object_object_add(reportData, "component", component);
  6277. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  6278. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  6279. json_object_object_add(reportData, "variable",variable);
  6280. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  6281. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  6282. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  6283. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  6284. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  6285. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  6286. {
  6287. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  6288. {
  6289. json_object *variableAttribute = json_object_new_object();
  6290. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  6291. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  6292. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  6293. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  6294. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  6295. json_object_array_add(variableAttributes, variableAttribute);
  6296. }
  6297. }
  6298. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  6299. json_object_array_add(reportDatas, reportData);
  6300. }
  6301. }
  6302. json_object_object_add(NotifyReport, "reportData", reportDatas);
  6303. random_uuid(guid);
  6304. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  6305. json_object_put(NotifyReport);
  6306. LWS_Send(message);
  6307. sprintf(tempdata, "NotifyReport,0");
  6308. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6309. {
  6310. result = PASS;
  6311. }
  6312. return result;
  6313. }
  6314. int sendPublishFirmwareStatusNotificationRequest()
  6315. {
  6316. mtrace();
  6317. int result = FAIL;
  6318. char message[4096]={0};
  6319. char guid[37]={0};
  6320. char tempdata[128]={0};
  6321. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  6322. json_object *locations = json_object_new_array();
  6323. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  6324. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  6325. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  6326. {
  6327. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  6328. }
  6329. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  6330. random_uuid(guid);
  6331. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6332. json_object_put(PublishFirmwareStatusNotification);
  6333. LWS_Send(message);
  6334. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  6335. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6336. {
  6337. result = PASS;
  6338. }
  6339. return result;
  6340. }
  6341. int sendReportChargingProfilesRequest(int gun_index)
  6342. {
  6343. mtrace();
  6344. int result = FAIL;
  6345. char message[4096]={0};
  6346. char guid[37]={0};
  6347. char tempdata[128]={0};
  6348. json_object *ReportChargingProfiles = json_object_new_object();
  6349. json_object *chargingProfiles = json_object_new_array();
  6350. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  6351. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  6352. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  6353. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  6354. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  6355. {
  6356. json_object *chargingProfile = json_object_new_object();
  6357. json_object *chargingSchedules = json_object_new_array();
  6358. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  6359. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  6360. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  6361. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  6362. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  6363. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  6364. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  6365. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  6366. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  6367. {
  6368. json_object *chargingSchedule = json_object_new_object();
  6369. json_object *chargingSchedulePeriods = json_object_new_array();
  6370. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  6371. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  6372. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  6373. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  6374. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  6375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6376. {
  6377. json_object *chargingSchedulePeriod = json_object_new_object();
  6378. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  6379. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  6380. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  6381. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  6382. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  6383. }
  6384. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  6385. json_object_array_add(chargingSchedules, chargingSchedule);
  6386. }
  6387. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  6388. json_object_array_add(chargingProfiles, chargingProfile);
  6389. }
  6390. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  6391. random_uuid(guid);
  6392. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  6393. json_object_put(ReportChargingProfiles);
  6394. LWS_Send(message);
  6395. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  6396. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6397. {
  6398. result = PASS;
  6399. }
  6400. return result;
  6401. }
  6402. int sendReservationStatusUpdateRequest(int gun_index)
  6403. {
  6404. mtrace();
  6405. int result = FAIL;
  6406. char message[4096]={0};
  6407. char guid[37]={0};
  6408. char tempdata[128]={0};
  6409. json_object *ReservationStatusUpdate = json_object_new_object();
  6410. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  6411. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  6412. random_uuid(guid);
  6413. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  6414. json_object_put(ReservationStatusUpdate);
  6415. LWS_Send(message);
  6416. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  6417. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6418. {
  6419. result = PASS;
  6420. }
  6421. return result;
  6422. }
  6423. int sendSecurityEventNotificationRequest()
  6424. {
  6425. mtrace();
  6426. int result = FAIL;
  6427. char message[4096]={0};
  6428. char guid[37]={0};
  6429. char tempdata[128]={0};
  6430. json_object *SecurityEventNotification = json_object_new_object();
  6431. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  6432. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  6433. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techinfo));
  6434. random_uuid(guid);
  6435. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6436. json_object_put(SecurityEventNotification);
  6437. LWS_Send(message);
  6438. sprintf(tempdata, "SecurityEventNotification,0");
  6439. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6440. {
  6441. result = PASS;
  6442. }
  6443. return result;
  6444. }
  6445. int sendSignCertificateRequest()
  6446. {
  6447. mtrace();
  6448. int result = FAIL;
  6449. char message[4096]={0};
  6450. char guid[37]={0};
  6451. char tempdata[128]={0};
  6452. json_object *SignCertificate = json_object_new_object();
  6453. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  6454. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  6455. random_uuid(guid);
  6456. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6457. json_object_put(SignCertificate);
  6458. LWS_Send(message);
  6459. sprintf(tempdata, "SignCertificate,0");
  6460. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6461. {
  6462. result = PASS;
  6463. }
  6464. return result;
  6465. }
  6466. int sendStatusNotificationRequest(int gun_index)
  6467. {
  6468. mtrace();
  6469. int result = FAIL;
  6470. char message[600]={0};
  6471. char guid[37];
  6472. int currentStatus = 0;
  6473. struct timeval tmnow;
  6474. struct tm *tm;
  6475. char buf[28];//, usec_buf[6];
  6476. char tempdata[65]={0};
  6477. int tempIndex = 0;
  6478. gettimeofday(&tmnow, NULL);
  6479. time_t t;
  6480. t = time(NULL);
  6481. /*UTC time and date*/
  6482. tm = gmtime(&t);
  6483. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6484. #if 0 // remove temporally
  6485. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6486. strcat(buf,".");
  6487. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6488. strcat(buf,usec_buf);
  6489. #endif
  6490. printf("%s",buf);
  6491. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  6492. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  6493. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  6494. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6495. /*
  6496. enum _SYSTEM_STATUS
  6497. {
  6498. S_BOOTING = 0,
  6499. S_IDLE, = 1
  6500. S_AUTHORIZING, =2
  6501. S_REASSIGN_CHECK, =3
  6502. S_REASSIGN, =4
  6503. S_PRECHARGE, =5
  6504. S_PREPARING_FOR_EV, =6
  6505. S_PREPARING_FOR_EVSE, =7
  6506. S_CHARGING, =8
  6507. S_TERMINATING, =9
  6508. S_COMPLETE, =10
  6509. S_ALARM, =11
  6510. S_FAULT =12
  6511. }
  6512. */
  6513. //check Transaction active
  6514. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6515. if(gunType[gun_index] == 'J')
  6516. {
  6517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6518. {
  6519. tempIndex = ((gun_index==2) ? 1: 0);
  6520. }
  6521. else
  6522. {
  6523. tempIndex = gun_index;
  6524. }
  6525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6526. {
  6527. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6528. {
  6529. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6530. {
  6531. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  6532. {
  6533. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6534. }
  6535. else
  6536. {
  6537. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  6538. }
  6539. }
  6540. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6541. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6542. ) //S_PRECHARGE
  6543. {
  6544. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6545. }
  6546. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6547. {
  6548. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  6549. }
  6550. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6551. {
  6552. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  6553. }
  6554. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6555. {
  6556. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  6557. }
  6558. 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
  6559. {
  6560. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  6561. }
  6562. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6563. {
  6564. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  6565. }
  6566. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6567. {
  6568. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  6569. }
  6570. } //end of the same index
  6571. }//end of for CHAdeMO_QUANTITY
  6572. }
  6573. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  6574. {
  6575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6576. {
  6577. tempIndex = ((gun_index==2) ? 1: 0);
  6578. }
  6579. else
  6580. {
  6581. tempIndex = gun_index;
  6582. }
  6583. for (int index = 0; index < CCS_QUANTITY; index++)
  6584. {
  6585. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6586. {
  6587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6588. {
  6589. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  6590. {
  6591. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6592. }
  6593. else
  6594. {
  6595. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  6596. }
  6597. }
  6598. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6599. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6600. ) //S_PRECHARGE
  6601. {
  6602. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6603. }
  6604. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6605. {
  6606. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  6607. }
  6608. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6609. {
  6610. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  6611. }
  6612. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6613. {
  6614. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  6615. }
  6616. 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
  6617. {
  6618. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  6619. }
  6620. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6621. {
  6622. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  6623. }
  6624. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6625. {
  6626. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  6627. }
  6628. } //end of the same index
  6629. } // end of for CCS_QUANTITY
  6630. }
  6631. else if(gunType[gun_index] == 'G')
  6632. {
  6633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6634. {
  6635. tempIndex = ((gun_index==2) ? 1: 0);
  6636. }
  6637. else
  6638. {
  6639. tempIndex = gun_index;
  6640. }
  6641. for (int index = 0; index < GB_QUANTITY; index++)
  6642. {
  6643. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6644. {
  6645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6646. {
  6647. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  6648. {
  6649. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6650. }
  6651. else
  6652. {
  6653. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  6654. }
  6655. }
  6656. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6657. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6658. ) //S_PRECHARGE
  6659. {
  6660. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6661. }
  6662. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6663. {
  6664. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  6665. }
  6666. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6667. {
  6668. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  6669. }
  6670. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6671. {
  6672. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  6673. }
  6674. 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
  6675. {
  6676. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  6677. }
  6678. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6679. {
  6680. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  6681. }
  6682. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6683. {
  6684. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  6685. }
  6686. } //end of the same index
  6687. } // end of for GB_QUANTITY
  6688. }
  6689. else if(gunType[gun_index] == 'O')
  6690. {
  6691. tempIndex = gun_index;
  6692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6693. {
  6694. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6695. {
  6696. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6697. {
  6698. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  6699. {
  6700. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6701. }
  6702. else
  6703. {
  6704. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  6705. }
  6706. }
  6707. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6708. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6709. ) //S_PRECHARGE
  6710. {
  6711. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6712. }
  6713. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6714. {
  6715. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  6716. }
  6717. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6718. {
  6719. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  6720. }
  6721. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6722. {
  6723. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  6724. }
  6725. 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
  6726. {
  6727. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  6728. }
  6729. 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
  6730. {
  6731. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  6732. }
  6733. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6734. {
  6735. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  6736. }
  6737. } //end of the same index
  6738. }
  6739. }
  6740. else
  6741. {
  6742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6743. {
  6744. tempIndex = 2;
  6745. }
  6746. else
  6747. {
  6748. tempIndex = gun_index;
  6749. }
  6750. for (int index = 0; index < AC_QUANTITY; index++)
  6751. {
  6752. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6753. {
  6754. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6755. {
  6756. 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))
  6757. {
  6758. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6759. }
  6760. else
  6761. {
  6762. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  6763. }
  6764. }
  6765. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6766. {
  6767. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  6768. }
  6769. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6770. {
  6771. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  6772. }
  6773. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6774. {
  6775. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  6776. }
  6777. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6778. {
  6779. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  6780. }
  6781. 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
  6782. {
  6783. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  6784. }
  6785. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6786. {
  6787. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  6788. }
  6789. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6790. {
  6791. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  6792. }
  6793. }//end of the same index
  6794. }//end of for AC_QUANTITY
  6795. }
  6796. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  6797. random_uuid(guid);
  6798. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  6799. , MESSAGE_TYPE_CALL
  6800. , guid
  6801. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  6802. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  6803. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  6804. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  6805. if((server_sign == TRUE))
  6806. {
  6807. LWS_Send(message);
  6808. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6809. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6810. {
  6811. result = PASS;
  6812. }
  6813. }
  6814. else
  6815. {
  6816. result = PASS;
  6817. }
  6818. return result;
  6819. }
  6820. int sendTransactionEventRequest(int gun_index)
  6821. {
  6822. mtrace();
  6823. int result = FAIL;
  6824. char message[1024*20]={0};
  6825. char guid[37]={0};
  6826. char tempdata[128]={0};
  6827. uint8_t tempIndex;
  6828. json_object *TransactionEvent = json_object_new_object();
  6829. json_object *transactionInfo = json_object_new_object();
  6830. json_object *idToken = json_object_new_object();
  6831. json_object *evse = json_object_new_object();
  6832. json_object *meterValues = json_object_new_array();
  6833. if(gunType[gun_index] == 'J')
  6834. {
  6835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6836. {
  6837. tempIndex = ((gun_index==2) ? 1: 0);
  6838. }
  6839. else
  6840. {
  6841. tempIndex = gun_index;
  6842. }
  6843. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6844. {
  6845. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6846. {
  6847. getNowDatetime(ShmOCPP20Data->TransactionEvent[index].timestamp);
  6848. if((ShmOCPP20Data->TransactionEvent[index].seqNo + 1) < INT_MAX)
  6849. ShmOCPP20Data->TransactionEvent[index].seqNo++;
  6850. else
  6851. ShmOCPP20Data->TransactionEvent[index].seqNo = 0;
  6852. ShmOCPP20Data->TransactionEvent[index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  6853. ShmOCPP20Data->TransactionEvent[index].evse.id = 0;
  6854. ShmOCPP20Data->TransactionEvent[index].evse.connectorId = (gun_index + 1);
  6855. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6856. {
  6857. memset(&ShmOCPP20Data->TransactionEvent[index].transactionInfo, 0x00, sizeof(struct TransactionType));
  6858. memset(&ShmOCPP20Data->TransactionEvent[index].idToken, 0x00, sizeof(struct IdTokenType));
  6859. memset(&ShmOCPP20Data->TransactionEvent[index].meterValue, 0x00, sizeof(struct MeterValueType));
  6860. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  6861. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  6862. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  6863. {
  6864. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  6865. }
  6866. else
  6867. {
  6868. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  6869. }
  6870. }
  6871. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  6872. {
  6873. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  6874. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  6875. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  6876. }
  6877. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6878. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6879. ) //S_PRECHARGE
  6880. {
  6881. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  6882. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  6883. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  6884. }
  6885. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6886. {
  6887. if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
  6888. random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
  6889. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  6890. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  6891. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  6892. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  6893. }
  6894. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6895. {
  6896. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  6897. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  6898. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  6899. }
  6900. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6901. {
  6902. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  6903. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  6904. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  6905. }
  6906. 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
  6907. {
  6908. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  6909. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  6910. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  6911. }
  6912. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6913. {
  6914. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  6915. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  6916. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  6917. }
  6918. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6919. {
  6920. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  6921. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  6922. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  6923. }
  6924. } //end of the same index
  6925. }//end of for CHAdeMO_QUANTITY
  6926. }
  6927. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  6928. {
  6929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6930. {
  6931. tempIndex = ((gun_index==2) ? 1: 0);
  6932. }
  6933. else
  6934. {
  6935. tempIndex = gun_index;
  6936. }
  6937. for (int index = 0; index < CCS_QUANTITY; index++)
  6938. {
  6939. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6940. {
  6941. getNowDatetime(ShmOCPP20Data->TransactionEvent[index].timestamp);
  6942. if((ShmOCPP20Data->TransactionEvent[index].seqNo + 1) < INT_MAX)
  6943. ShmOCPP20Data->TransactionEvent[index].seqNo++;
  6944. else
  6945. ShmOCPP20Data->TransactionEvent[index].seqNo = 0;
  6946. ShmOCPP20Data->TransactionEvent[index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  6947. ShmOCPP20Data->TransactionEvent[index].evse.id = 0;
  6948. ShmOCPP20Data->TransactionEvent[index].evse.connectorId = (gun_index + 1);
  6949. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6950. {
  6951. memset(&ShmOCPP20Data->TransactionEvent[index].transactionInfo, 0x00, sizeof(struct TransactionType));
  6952. memset(&ShmOCPP20Data->TransactionEvent[index].idToken, 0x00, sizeof(struct IdTokenType));
  6953. memset(&ShmOCPP20Data->TransactionEvent[index].meterValue, 0x00, sizeof(struct MeterValueType));
  6954. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  6955. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  6956. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  6957. {
  6958. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  6959. }
  6960. else
  6961. {
  6962. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  6963. }
  6964. }
  6965. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  6966. {
  6967. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  6968. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  6969. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  6970. }
  6971. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6972. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6973. ) //S_PRECHARGE
  6974. {
  6975. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  6976. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  6977. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  6978. }
  6979. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6980. {
  6981. if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
  6982. random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
  6983. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  6984. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  6985. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  6986. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  6987. }
  6988. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6989. {
  6990. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  6991. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  6992. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  6993. }
  6994. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6995. {
  6996. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  6997. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  6998. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  6999. }
  7000. 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
  7001. {
  7002. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7003. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7004. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7005. }
  7006. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7007. {
  7008. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7009. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7010. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7011. }
  7012. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7013. {
  7014. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7015. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7016. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7017. }
  7018. } //end of the same index
  7019. } // end of for CCS_QUANTITY
  7020. }
  7021. else if(gunType[gun_index] == 'G')
  7022. {
  7023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7024. {
  7025. tempIndex = ((gun_index==2) ? 1: 0);
  7026. }
  7027. else
  7028. {
  7029. tempIndex = gun_index;
  7030. }
  7031. for (int index = 0; index < GB_QUANTITY; index++)
  7032. {
  7033. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7034. {
  7035. getNowDatetime(ShmOCPP20Data->TransactionEvent[index].timestamp);
  7036. if((ShmOCPP20Data->TransactionEvent[index].seqNo + 1) < INT_MAX)
  7037. ShmOCPP20Data->TransactionEvent[index].seqNo++;
  7038. else
  7039. ShmOCPP20Data->TransactionEvent[index].seqNo = 0;
  7040. ShmOCPP20Data->TransactionEvent[index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7041. ShmOCPP20Data->TransactionEvent[index].evse.id = 0;
  7042. ShmOCPP20Data->TransactionEvent[index].evse.connectorId = (gun_index + 1);
  7043. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7044. {
  7045. memset(&ShmOCPP20Data->TransactionEvent[index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7046. memset(&ShmOCPP20Data->TransactionEvent[index].idToken, 0x00, sizeof(struct IdTokenType));
  7047. memset(&ShmOCPP20Data->TransactionEvent[index].meterValue, 0x00, sizeof(struct MeterValueType));
  7048. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7049. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7050. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  7051. {
  7052. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7053. }
  7054. else
  7055. {
  7056. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7057. }
  7058. }
  7059. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7060. {
  7061. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7062. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7063. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7064. }
  7065. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7066. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7067. ) //S_PRECHARGE
  7068. {
  7069. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7070. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7071. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7072. }
  7073. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7074. {
  7075. if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
  7076. random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
  7077. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  7078. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7079. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7080. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7081. }
  7082. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7083. {
  7084. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7085. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7086. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7087. }
  7088. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7089. {
  7090. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7091. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7092. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7093. }
  7094. 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
  7095. {
  7096. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7097. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7098. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7099. }
  7100. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7101. {
  7102. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7103. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7104. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7105. }
  7106. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7107. {
  7108. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7109. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7110. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7111. }
  7112. } //end of the same index
  7113. } // end of for GB_QUANTITY
  7114. }
  7115. else if(gunType[gun_index] == 'O')
  7116. {
  7117. tempIndex = gun_index;
  7118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7119. {
  7120. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7121. {
  7122. getNowDatetime(ShmOCPP20Data->TransactionEvent[index].timestamp);
  7123. if((ShmOCPP20Data->TransactionEvent[index].seqNo + 1) < INT_MAX)
  7124. ShmOCPP20Data->TransactionEvent[index].seqNo++;
  7125. else
  7126. ShmOCPP20Data->TransactionEvent[index].seqNo = 0;
  7127. ShmOCPP20Data->TransactionEvent[index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7128. ShmOCPP20Data->TransactionEvent[index].evse.id = 0;
  7129. ShmOCPP20Data->TransactionEvent[index].evse.connectorId = (gun_index + 1);
  7130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7131. {
  7132. memset(&ShmOCPP20Data->TransactionEvent[index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7133. memset(&ShmOCPP20Data->TransactionEvent[index].idToken, 0x00, sizeof(struct IdTokenType));
  7134. memset(&ShmOCPP20Data->TransactionEvent[index].meterValue, 0x00, sizeof(struct MeterValueType));
  7135. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7136. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7137. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7138. {
  7139. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7140. }
  7141. else
  7142. {
  7143. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7144. }
  7145. }
  7146. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7147. {
  7148. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7149. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7150. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7151. }
  7152. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7153. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7154. ) //S_PRECHARGE
  7155. {
  7156. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7157. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7158. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7159. }
  7160. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7161. {
  7162. if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
  7163. random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
  7164. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  7165. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7166. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7167. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7168. }
  7169. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7170. {
  7171. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7172. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7173. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7174. }
  7175. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7176. {
  7177. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7178. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7179. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7180. }
  7181. 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
  7182. {
  7183. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7184. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7185. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7186. }
  7187. 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
  7188. {
  7189. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7190. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7191. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7192. }
  7193. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7194. {
  7195. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7196. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7197. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7198. }
  7199. } //end of the same index
  7200. }
  7201. }
  7202. else
  7203. {
  7204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7205. {
  7206. tempIndex = 2;
  7207. }
  7208. else
  7209. {
  7210. tempIndex = gun_index;
  7211. }
  7212. for (int index = 0; index < AC_QUANTITY; index++)
  7213. {
  7214. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7215. {
  7216. getNowDatetime(ShmOCPP20Data->TransactionEvent[index].timestamp);
  7217. if((ShmOCPP20Data->TransactionEvent[index].seqNo + 1) < INT_MAX)
  7218. ShmOCPP20Data->TransactionEvent[index].seqNo++;
  7219. else
  7220. ShmOCPP20Data->TransactionEvent[index].seqNo = 0;
  7221. ShmOCPP20Data->TransactionEvent[index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7222. ShmOCPP20Data->TransactionEvent[index].evse.id = 0;
  7223. ShmOCPP20Data->TransactionEvent[index].evse.connectorId = (gun_index + 1);
  7224. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  7225. {
  7226. memset(&ShmOCPP20Data->TransactionEvent[index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7227. memset(&ShmOCPP20Data->TransactionEvent[index].idToken, 0x00, sizeof(struct IdTokenType));
  7228. memset(&ShmOCPP20Data->TransactionEvent[index].meterValue, 0x00, sizeof(struct MeterValueType));
  7229. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7230. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7231. 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))
  7232. {
  7233. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7234. }
  7235. else
  7236. {
  7237. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7238. }
  7239. }
  7240. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7241. {
  7242. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7243. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7244. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7245. }
  7246. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7247. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7248. ) //S_PRECHARGE
  7249. {
  7250. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7251. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7252. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7253. }
  7254. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7255. {
  7256. if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
  7257. random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
  7258. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  7259. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7260. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7261. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7262. }
  7263. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7264. {
  7265. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7266. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7267. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7268. }
  7269. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7270. {
  7271. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7272. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7273. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7274. }
  7275. 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
  7276. {
  7277. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7278. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7279. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7280. }
  7281. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7282. {
  7283. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7284. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7285. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7286. }
  7287. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7288. {
  7289. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7290. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7291. sprintf((char*)ShmOCPP20Data->TransactionEvent[index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7292. }
  7293. }//end of the same index
  7294. }//end of for AC_QUANTITY
  7295. }
  7296. // Message
  7297. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7298. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  7299. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  7300. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  7301. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  7302. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  7303. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  7304. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  7305. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  7306. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  7307. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  7308. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  7309. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  7310. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  7311. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  7312. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  7313. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  7314. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  7315. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  7316. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  7317. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  7318. {
  7319. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  7320. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  7321. json_object_object_add(TransactionEvent, "idToken", idToken);
  7322. }
  7323. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  7324. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  7325. json_object_object_add(TransactionEvent, "evse", evse);
  7326. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  7327. {
  7328. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  7329. {
  7330. json_object *meterValue = json_object_new_object();
  7331. json_object *sampledValues = json_object_new_array();
  7332. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  7333. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  7334. {
  7335. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  7336. {
  7337. json_object *sampledValue = json_object_new_object();
  7338. json_object *unitOfMeasure = json_object_new_object();
  7339. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  7340. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  7341. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  7342. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  7343. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  7344. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  7345. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  7346. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  7347. json_object_array_add(sampledValues, sampledValue);
  7348. }
  7349. }
  7350. json_object_object_add(meterValue, "sampledValue", sampledValues);
  7351. json_object_array_add(meterValues, meterValue);
  7352. }
  7353. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  7354. }
  7355. random_uuid(guid);
  7356. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  7357. json_object_put(TransactionEvent);
  7358. LWS_Send(message);
  7359. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  7360. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7361. {
  7362. result = PASS;
  7363. }
  7364. return result;
  7365. }
  7366. //==========================================
  7367. // send confirm routine
  7368. //==========================================
  7369. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  7370. {
  7371. mtrace();
  7372. int result = FAIL;
  7373. char message[4096]={0};
  7374. json_object *CancelReservation = json_object_new_object();
  7375. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7376. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  7377. sprintf(message,"[%d,\"%s\",%s]"
  7378. ,MESSAGE_TYPE_CALLRESULT
  7379. ,uuid
  7380. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  7381. json_object_put(CancelReservation);
  7382. ShmOCPP20Data->CsMsg.bits[0].CancelReservationConf = OFF;
  7383. LWS_Send(message);
  7384. result = TRUE;
  7385. return result;
  7386. }
  7387. int sendCertificateSignedConfirmation(char *uuid)
  7388. {
  7389. mtrace();
  7390. int result = FAIL;
  7391. char message[4096]={0};
  7392. json_object *CertificateSigned = json_object_new_object();
  7393. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7394. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  7395. sprintf(message,"[%d,\"%s\",%s]"
  7396. ,MESSAGE_TYPE_CALLRESULT
  7397. ,uuid
  7398. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7399. json_object_put(CertificateSigned);
  7400. LWS_Send(message);
  7401. result = TRUE;
  7402. return result;
  7403. }
  7404. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  7405. {
  7406. mtrace();
  7407. int result = FAIL;
  7408. char message[4096]={0};
  7409. json_object *ChangeAvailability = json_object_new_object();
  7410. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7411. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  7412. sprintf(message,"[%d,\"%s\",%s]"
  7413. ,MESSAGE_TYPE_CALLRESULT
  7414. ,uuid
  7415. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  7416. json_object_put(ChangeAvailability);
  7417. LWS_Send(message);
  7418. result = TRUE;
  7419. return result;
  7420. }
  7421. int sendClearCacheConfirmation(char *uuid)
  7422. {
  7423. mtrace();
  7424. int result = FAIL;
  7425. char message[4096]={0};
  7426. json_object *ClearCache = json_object_new_object();
  7427. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7428. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  7429. sprintf(message,"[%d,\"%s\",%s]"
  7430. ,MESSAGE_TYPE_CALLRESULT
  7431. ,uuid
  7432. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  7433. json_object_put(ClearCache);
  7434. LWS_Send(message);
  7435. result = TRUE;
  7436. return result;
  7437. }
  7438. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7439. {
  7440. mtrace();
  7441. int result = FAIL;
  7442. char message[500]={0};
  7443. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7444. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7445. LWS_Send(message);
  7446. return result;
  7447. }
  7448. int sendClearDisplayMessageConfirmation(char *uuid)
  7449. {
  7450. mtrace();
  7451. int result = FAIL;
  7452. char message[4096]={0};
  7453. json_object *ClearDisplayMessage = json_object_new_object();
  7454. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  7455. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  7456. sprintf(message,"[%d,\"%s\",%s]"
  7457. ,MESSAGE_TYPE_CALLRESULT
  7458. ,uuid
  7459. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  7460. json_object_put(ClearDisplayMessage);
  7461. LWS_Send(message);
  7462. result = TRUE;
  7463. return result;
  7464. }
  7465. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  7466. {
  7467. mtrace();
  7468. int result = FAIL;
  7469. char message[4096]={0};
  7470. json_object *ClearVariableMonitoring = json_object_new_object();
  7471. json_object *clearMonitoringResults = json_object_new_array();
  7472. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  7473. for(int idx=0;idx<variableQuantity;idx++)
  7474. {
  7475. json_object *clearMonitoringResult = json_object_new_object();
  7476. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  7477. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  7478. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  7479. }
  7480. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  7481. sprintf(message,"[%d,\"%s\",%s]"
  7482. ,MESSAGE_TYPE_CALLRESULT
  7483. ,uuid
  7484. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  7485. json_object_put(ClearVariableMonitoring);
  7486. LWS_Send(message);
  7487. result = TRUE;
  7488. return result;
  7489. }
  7490. int sendCostUpdatedConfirmation(char *uuid)
  7491. {
  7492. mtrace();
  7493. int result = FAIL;
  7494. char message[4096]={0};
  7495. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  7496. sprintf(message,"[%d,\"%s\",{}]"
  7497. ,MESSAGE_TYPE_CALLRESULT
  7498. ,uuid);
  7499. LWS_Send(message);
  7500. result = TRUE;
  7501. return result;
  7502. }
  7503. int sendCustomerInformationConfirmation(char *uuid)
  7504. {
  7505. mtrace();
  7506. int result = FAIL;
  7507. char message[4096]={0};
  7508. json_object *CustomerInformation = json_object_new_object();
  7509. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  7510. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  7511. sprintf(message,"[%d,\"%s\",%s]"
  7512. ,MESSAGE_TYPE_CALLRESULT
  7513. ,uuid
  7514. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  7515. json_object_put(CustomerInformation);
  7516. LWS_Send(message);
  7517. result = TRUE;
  7518. return result;
  7519. }
  7520. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  7521. {
  7522. mtrace();
  7523. int result = FAIL;
  7524. char message[4096]={0};
  7525. json_object *DataTransfer = json_object_new_object();
  7526. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7527. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  7528. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  7529. sprintf(message,"[%d,\"%s\",%s]"
  7530. ,MESSAGE_TYPE_CALLRESULT
  7531. ,uuid
  7532. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  7533. json_object_put(DataTransfer);
  7534. LWS_Send(message);
  7535. result = TRUE;
  7536. return result;
  7537. }
  7538. int sendDeleteCertificateConfirmation(char *uuid)
  7539. {
  7540. mtrace();
  7541. int result = FAIL;
  7542. char message[4096]={0};
  7543. json_object *DeleteCertificate = json_object_new_object();
  7544. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7545. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  7546. sprintf(message,"[%d,\"%s\",%s]"
  7547. ,MESSAGE_TYPE_CALLRESULT
  7548. ,uuid
  7549. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7550. json_object_put(DeleteCertificate);
  7551. LWS_Send(message);
  7552. result = TRUE;
  7553. return result;
  7554. }
  7555. int sendGetBaseReportConfirmation(char *uuid)
  7556. {
  7557. mtrace();
  7558. int result = FAIL;
  7559. char message[4096]={0};
  7560. json_object *GetBaseReport = json_object_new_object();
  7561. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  7562. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  7563. sprintf(message,"[%d,\"%s\",%s]"
  7564. ,MESSAGE_TYPE_CALLRESULT
  7565. ,uuid
  7566. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  7567. json_object_put(GetBaseReport);
  7568. LWS_Send(message);
  7569. result = TRUE;
  7570. return result;
  7571. }
  7572. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  7573. {
  7574. mtrace();
  7575. int result = FAIL;
  7576. char message[4096]={0};
  7577. json_object *GetChargingProfiles = json_object_new_object();
  7578. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  7579. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  7580. sprintf(message,"[%d,\"%s\",%s]"
  7581. ,MESSAGE_TYPE_CALLRESULT
  7582. ,uuid
  7583. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  7584. json_object_put(GetChargingProfiles);
  7585. LWS_Send(message);
  7586. result = TRUE;
  7587. return result;
  7588. }
  7589. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7590. {
  7591. mtrace();
  7592. int result = FAIL;
  7593. char message[4096]={0};
  7594. int CompositeScheduleIndex = 0;
  7595. json_object *GetCompositeSchedule = json_object_new_object();
  7596. json_object *schedule = json_object_new_object();
  7597. json_object *chargingSchedule = json_object_new_object();
  7598. json_object *chargingSchedulePeriod = json_object_new_array();
  7599. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7600. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  7601. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7602. if(nPeriod == 0)
  7603. {
  7604. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  7605. {
  7606. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  7607. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  7608. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  7609. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  7610. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  7611. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  7612. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  7613. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  7614. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  7615. {
  7616. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  7617. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  7618. {
  7619. json_object *Period = json_object_new_object();
  7620. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  7621. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  7622. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  7623. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  7624. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  7625. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  7626. json_object_array_add(chargingSchedulePeriod, Period);
  7627. }
  7628. }
  7629. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  7630. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  7631. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  7632. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  7633. }
  7634. }
  7635. else
  7636. {
  7637. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  7638. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  7639. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  7640. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  7641. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  7642. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  7643. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  7644. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  7645. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  7646. {
  7647. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  7648. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  7649. {
  7650. json_object *Period = json_object_new_object();
  7651. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  7652. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  7653. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  7654. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  7655. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  7656. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  7657. json_object_array_add(chargingSchedulePeriod, Period);
  7658. }
  7659. }
  7660. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  7661. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  7662. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  7663. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  7664. }
  7665. sprintf(message,"[%d,\"%s\",%s]"
  7666. ,MESSAGE_TYPE_CALLRESULT
  7667. ,uuid
  7668. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  7669. json_object_put(GetCompositeSchedule);
  7670. LWS_Send(message);
  7671. result = TRUE;
  7672. return result;
  7673. }
  7674. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  7675. {
  7676. mtrace();
  7677. int result = FAIL;
  7678. char message[4096]={0};
  7679. json_object *GetGetDisplayMessages = json_object_new_object();
  7680. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  7681. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  7682. sprintf(message,"[%d,\"%s\",%s]"
  7683. ,MESSAGE_TYPE_CALLRESULT
  7684. ,uuid
  7685. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  7686. json_object_put(GetGetDisplayMessages);
  7687. LWS_Send(message);
  7688. result = TRUE;
  7689. return result;
  7690. }
  7691. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  7692. {
  7693. mtrace();
  7694. int result = FAIL;
  7695. char message[4096]={0};
  7696. json_object *GetInstalledCertificateIds = json_object_new_object();
  7697. json_object *certificateHashDataChains = json_object_new_array();
  7698. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7699. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  7700. for(int idx=0;idx<certQuantity;idx++)
  7701. {
  7702. json_object *cert = json_object_new_object();
  7703. json_object *certificateHashData = json_object_new_object();
  7704. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  7705. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  7706. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  7707. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  7708. json_object_object_add(cert, "certificateHashData", certificateHashData);
  7709. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  7710. json_object_array_add(certificateHashDataChains, cert);
  7711. }
  7712. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  7713. sprintf(message,"[%d,\"%s\",%s]"
  7714. ,MESSAGE_TYPE_CALLRESULT
  7715. ,uuid
  7716. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7717. json_object_put(GetInstalledCertificateIds);
  7718. LWS_Send(message);
  7719. result = TRUE;
  7720. return result;
  7721. }
  7722. int sendGetLocalListVersionConfirmation(char *uuid)
  7723. {
  7724. mtrace();
  7725. int result = FAIL;
  7726. char message[4096]={0};
  7727. json_object *GetLocalListVersion = json_object_new_object();
  7728. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7729. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  7730. sprintf(message,"[%d,\"%s\",%s]"
  7731. ,MESSAGE_TYPE_CALLRESULT
  7732. ,uuid
  7733. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  7734. json_object_put(GetLocalListVersion);
  7735. LWS_Send(message);
  7736. result = TRUE;
  7737. return result;
  7738. }
  7739. int sendGetLogConfirmation(char *uuid)
  7740. {
  7741. mtrace();
  7742. int result = FAIL;
  7743. char message[4096]={0};
  7744. json_object *GetLog = json_object_new_object();
  7745. DEBUG_INFO("sendGetLogConfirmation...\n");
  7746. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  7747. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  7748. sprintf(message,"[%d,\"%s\",%s]"
  7749. ,MESSAGE_TYPE_CALLRESULT
  7750. ,uuid
  7751. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7752. json_object_put(GetLog);
  7753. LWS_Send(message);
  7754. result = TRUE;
  7755. return result;
  7756. }
  7757. int sendGetMonitoringReportConfirmation(char *uuid)
  7758. {
  7759. mtrace();
  7760. int result = FAIL;
  7761. char message[4096]={0};
  7762. json_object *GetMonitoringReport = json_object_new_object();
  7763. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  7764. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  7765. sprintf(message,"[%d,\"%s\",%s]"
  7766. ,MESSAGE_TYPE_CALLRESULT
  7767. ,uuid
  7768. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  7769. json_object_put(GetMonitoringReport);
  7770. LWS_Send(message);
  7771. result = TRUE;
  7772. return result;
  7773. }
  7774. int sendGetReportConfirmation(char *uuid)
  7775. {
  7776. mtrace();
  7777. int result = FAIL;
  7778. char message[4096]={0};
  7779. json_object *GetReport = json_object_new_object();
  7780. DEBUG_INFO("sendGetReportConfirmation...\n");
  7781. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  7782. sprintf(message,"[%d,\"%s\",%s]"
  7783. ,MESSAGE_TYPE_CALLRESULT
  7784. ,uuid
  7785. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  7786. json_object_put(GetReport);
  7787. LWS_Send(message);
  7788. result = TRUE;
  7789. return result;
  7790. }
  7791. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  7792. {
  7793. mtrace();
  7794. int result = FAIL;
  7795. char message[4096]={0};
  7796. json_object *GetTransactionStatus = json_object_new_object();
  7797. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  7798. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  7799. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  7800. sprintf(message,"[%d,\"%s\",%s]"
  7801. ,MESSAGE_TYPE_CALLRESULT
  7802. ,uuid
  7803. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  7804. json_object_put(GetTransactionStatus);
  7805. LWS_Send(message);
  7806. result = TRUE;
  7807. return result;
  7808. }
  7809. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  7810. {
  7811. mtrace();
  7812. int result = FAIL;
  7813. char message[4096]={0};
  7814. json_object *GetVariables = json_object_new_object();
  7815. json_object *getVariableResults = json_object_new_array();
  7816. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  7817. for(int idx=0;idx<variableQuantity;idx++)
  7818. {
  7819. json_object *variableResult = json_object_new_object();
  7820. json_object *component = json_object_new_object();
  7821. json_object *variable = json_object_new_object();
  7822. json_object *evse = json_object_new_object();
  7823. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  7824. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  7825. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  7826. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  7827. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  7828. json_object_object_add(component, "component", evse);
  7829. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  7830. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  7831. json_object_object_add(variableResult, "component", component);
  7832. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  7833. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  7834. json_object_object_add(variableResult, "variable", variable);
  7835. json_object_array_add(getVariableResults, variableResult);
  7836. }
  7837. json_object_object_add(GetVariables , "setVariableResult", getVariableResults);
  7838. sprintf(message,"[%d,\"%s\",%s]"
  7839. ,MESSAGE_TYPE_CALLRESULT
  7840. ,uuid
  7841. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  7842. json_object_put(GetVariables);
  7843. LWS_Send(message);
  7844. result = TRUE;
  7845. return result;
  7846. }
  7847. int sendInstallCertificateConfirmation(char *uuid)
  7848. {
  7849. mtrace();
  7850. int result = FAIL;
  7851. char message[4096]={0};
  7852. json_object *InstallCertificate = json_object_new_object();
  7853. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7854. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  7855. sprintf(message,"[%d,\"%s\",%s]"
  7856. ,MESSAGE_TYPE_CALLRESULT
  7857. ,uuid
  7858. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7859. json_object_put(InstallCertificate);
  7860. LWS_Send(message);
  7861. result = TRUE;
  7862. return result;
  7863. }
  7864. int sendPublishFirmwareConfirmation(char *uuid)
  7865. {
  7866. mtrace();
  7867. int result = FAIL;
  7868. char message[4096]={0};
  7869. json_object *PublishFirmware = json_object_new_object();
  7870. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  7871. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  7872. sprintf(message,"[%d,\"%s\",%s]"
  7873. ,MESSAGE_TYPE_CALLRESULT
  7874. ,uuid
  7875. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  7876. json_object_put(PublishFirmware);
  7877. LWS_Send(message);
  7878. result = TRUE;
  7879. return result;
  7880. }
  7881. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  7882. {
  7883. mtrace();
  7884. int result = FAIL;
  7885. char message[4096]={0};
  7886. json_object *RemoteStartTransaction = json_object_new_object();
  7887. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  7888. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  7889. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7890. sprintf(message,"[%d,\"%s\",%s]"
  7891. ,MESSAGE_TYPE_CALLRESULT
  7892. ,uuid
  7893. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  7894. json_object_put(RemoteStartTransaction);
  7895. LWS_Send(message);
  7896. result = TRUE;
  7897. return result;
  7898. }
  7899. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  7900. {
  7901. mtrace();
  7902. int result = FAIL;
  7903. char message[4096]={0};
  7904. json_object *RemoteStopTransaction = json_object_new_object();
  7905. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  7906. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7907. sprintf(message,"[%d,\"%s\",%s]"
  7908. ,MESSAGE_TYPE_CALLRESULT
  7909. ,uuid
  7910. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  7911. json_object_put(RemoteStopTransaction);
  7912. LWS_Send(message);
  7913. result = TRUE;
  7914. return result;
  7915. }
  7916. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  7917. {
  7918. mtrace();
  7919. int result = FAIL;
  7920. char message[4096]={0};
  7921. json_object *ReserveNow = json_object_new_object();
  7922. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  7923. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7924. sprintf(message,"[%d,\"%s\",%s]"
  7925. ,MESSAGE_TYPE_CALLRESULT
  7926. ,uuid
  7927. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  7928. json_object_put(ReserveNow);
  7929. LWS_Send(message);
  7930. result = TRUE;
  7931. return result;
  7932. }
  7933. int sendResetConfirmation(char *uuid)
  7934. {
  7935. mtrace();
  7936. int result = FAIL;
  7937. char message[4096]={0};
  7938. json_object *Reset = json_object_new_object();
  7939. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  7940. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  7941. sprintf(message,"[%d,\"%s\",%s]"
  7942. ,MESSAGE_TYPE_CALLRESULT
  7943. ,uuid
  7944. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  7945. json_object_put(Reset);
  7946. LWS_Send(message);
  7947. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  7948. {
  7949. DB_updateBootType(BootReasonEnumType_RemoteReset);
  7950. }
  7951. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  7952. {
  7953. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  7954. }
  7955. result = TRUE;
  7956. return result;
  7957. }
  7958. int sendSendLocalListConfirmation(char *uuid)
  7959. {
  7960. mtrace();
  7961. int result = FAIL;
  7962. char message[4096]={0};
  7963. json_object *SendLocalList = json_object_new_object();
  7964. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  7965. sprintf(message,"[%d,\"%s\",%s]"
  7966. ,MESSAGE_TYPE_CALLRESULT
  7967. ,uuid
  7968. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  7969. json_object_put(SendLocalList);
  7970. LWS_Send(message);
  7971. result = TRUE;
  7972. return result;
  7973. }
  7974. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  7975. {
  7976. mtrace();
  7977. int result = FAIL;
  7978. char message[4096]={0};
  7979. json_object *SetChargingProfile = json_object_new_object();
  7980. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7981. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  7982. sprintf(message,"[%d,\"%s\",%s]"
  7983. ,MESSAGE_TYPE_CALLRESULT
  7984. ,uuid
  7985. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  7986. json_object_put(SetChargingProfile);
  7987. LWS_Send(message);
  7988. result = TRUE;
  7989. return result;
  7990. }
  7991. int sendSetDisplayMessageConfirmation(char *uuid)
  7992. {
  7993. mtrace();
  7994. int result = FAIL;
  7995. char message[4096]={0};
  7996. json_object *SetDisplayMessage = json_object_new_object();
  7997. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  7998. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  7999. sprintf(message,"[%d,\"%s\",%s]"
  8000. ,MESSAGE_TYPE_CALLRESULT
  8001. ,uuid
  8002. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  8003. json_object_put(SetDisplayMessage);
  8004. LWS_Send(message);
  8005. result = TRUE;
  8006. return result;
  8007. }
  8008. int sendSetMonitoringBaseConfirmation(char *uuid)
  8009. {
  8010. mtrace();
  8011. int result = FAIL;
  8012. char message[4096]={0};
  8013. json_object *SetMonitoringBase = json_object_new_object();
  8014. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  8015. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  8016. sprintf(message,"[%d,\"%s\",%s]"
  8017. ,MESSAGE_TYPE_CALLRESULT
  8018. ,uuid
  8019. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  8020. json_object_put(SetMonitoringBase);
  8021. LWS_Send(message);
  8022. result = TRUE;
  8023. return result;
  8024. }
  8025. int sendSetMonitoringLevelConfirmation(char *uuid)
  8026. {
  8027. mtrace();
  8028. int result = FAIL;
  8029. char message[4096]={0};
  8030. json_object *SetMonitoringLevel = json_object_new_object();
  8031. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  8032. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  8033. sprintf(message,"[%d,\"%s\",%s]"
  8034. ,MESSAGE_TYPE_CALLRESULT
  8035. ,uuid
  8036. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  8037. json_object_put(SetMonitoringLevel);
  8038. LWS_Send(message);
  8039. result = TRUE;
  8040. return result;
  8041. }
  8042. int sendSetNetworkProfileConfirmation(char *uuid)
  8043. {
  8044. mtrace();
  8045. int result = FAIL;
  8046. char message[4096]={0};
  8047. json_object *SetNetworkProfile = json_object_new_object();
  8048. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  8049. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  8050. sprintf(message,"[%d,\"%s\",%s]"
  8051. ,MESSAGE_TYPE_CALLRESULT
  8052. ,uuid
  8053. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  8054. json_object_put(SetNetworkProfile);
  8055. LWS_Send(message);
  8056. result = TRUE;
  8057. return result;
  8058. }
  8059. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  8060. {
  8061. mtrace();
  8062. int result = FAIL;
  8063. char message[4096]={0};
  8064. json_object *SetVariableMonitoring = json_object_new_object();
  8065. json_object *setMonitoringResults = json_object_new_array();
  8066. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  8067. for(int idx=0;idx<variableQuantity;idx++)
  8068. {
  8069. json_object *variableMonitorResult = json_object_new_object();
  8070. json_object *component = json_object_new_object();
  8071. json_object *variable = json_object_new_object();
  8072. json_object *evse = json_object_new_object();
  8073. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  8074. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  8075. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  8076. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  8077. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  8078. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  8079. json_object_object_add(component, "component", evse);
  8080. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  8081. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  8082. json_object_object_add(variableMonitorResult, "component", component);
  8083. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  8084. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  8085. json_object_object_add(variableMonitorResult, "variable", variable);
  8086. json_object_array_add(setMonitoringResults, variableMonitorResult);
  8087. }
  8088. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  8089. sprintf(message,"[%d,\"%s\",%s]"
  8090. ,MESSAGE_TYPE_CALLRESULT
  8091. ,uuid
  8092. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  8093. json_object_put(SetVariableMonitoring);
  8094. LWS_Send(message);
  8095. result = TRUE;
  8096. return result;
  8097. }
  8098. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  8099. {
  8100. mtrace();
  8101. int result = FAIL;
  8102. char message[4096]={0};
  8103. json_object *SetVariable = json_object_new_object();
  8104. json_object *setVariableResults = json_object_new_array();
  8105. DEBUG_INFO("sendSetVariableConfirmation...\n");
  8106. for(int idx=0;idx<variableQuantity;idx++)
  8107. {
  8108. json_object *variableResult = json_object_new_object();
  8109. json_object *component = json_object_new_object();
  8110. json_object *variable = json_object_new_object();
  8111. json_object *evse = json_object_new_object();
  8112. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  8113. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  8114. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  8115. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  8116. json_object_object_add(component, "component", evse);
  8117. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  8118. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  8119. json_object_object_add(variableResult, "component", component);
  8120. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  8121. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  8122. json_object_object_add(variableResult, "variable", variable);
  8123. json_object_array_add(setVariableResults, variableResult);
  8124. }
  8125. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  8126. sprintf(message,"[%d,\"%s\",%s]"
  8127. ,MESSAGE_TYPE_CALLRESULT
  8128. ,uuid
  8129. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  8130. json_object_put(SetVariable);
  8131. LWS_Send(message);
  8132. result = TRUE;
  8133. return result;
  8134. }
  8135. int sendTriggerMessageConfirmation(char *uuid)
  8136. {
  8137. mtrace();
  8138. int result = FAIL;
  8139. char message[4096]={0};
  8140. json_object *TriggerMessage = json_object_new_object();
  8141. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8142. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  8143. sprintf(message,"[%d,\"%s\",%s]",
  8144. MESSAGE_TYPE_CALLRESULT,
  8145. uuid,
  8146. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  8147. json_object_put(TriggerMessage);
  8148. LWS_Send(message);
  8149. result = TRUE;
  8150. return result;
  8151. }
  8152. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  8153. {
  8154. mtrace();
  8155. int result = FAIL;
  8156. char message[4096]={0};
  8157. json_object *UnlockConnector = json_object_new_object();
  8158. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8159. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  8160. sprintf(message,"[%d,\"%s\",%s]",
  8161. MESSAGE_TYPE_CALLRESULT,
  8162. uuid,
  8163. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  8164. json_object_put(UnlockConnector);
  8165. LWS_Send(message);
  8166. result = TRUE;
  8167. return result;
  8168. }
  8169. int sendUnpublishFirmwareConfirmation(char *uuid)
  8170. {
  8171. mtrace();
  8172. int result = FAIL;
  8173. char message[4096]={0};
  8174. json_object *UnpublishFirmware = json_object_new_object();
  8175. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  8176. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  8177. sprintf(message,"[%d,\"%s\",%s]"
  8178. ,MESSAGE_TYPE_CALLRESULT
  8179. ,uuid
  8180. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  8181. json_object_put(UnpublishFirmware);
  8182. LWS_Send(message);
  8183. result = TRUE;
  8184. return result;
  8185. }
  8186. int sendUpdateFirmwareConfirmation(char *uuid)
  8187. {
  8188. mtrace();
  8189. int result = FAIL;
  8190. char message[4096]={0};
  8191. json_object *UpdateFirmware = json_object_new_object();
  8192. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8193. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  8194. sprintf(message,"[%d,\"%s\",%s]"
  8195. ,MESSAGE_TYPE_CALLRESULT
  8196. ,uuid
  8197. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8198. json_object_put(UpdateFirmware);
  8199. LWS_Send(message);
  8200. result = TRUE;
  8201. return result;
  8202. }
  8203. //==========================================
  8204. // send CallError routine
  8205. //==========================================
  8206. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  8207. {
  8208. mtrace();
  8209. char message[220]={0};
  8210. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  8211. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  8212. LWS_Send(message);
  8213. }
  8214. //==========================================
  8215. // Handle server request routine Start
  8216. //==========================================
  8217. int handleCancelReservationRequest(char *uuid, char *payload)
  8218. {
  8219. mtrace();
  8220. int result = FAIL;
  8221. int gunNO = 0;
  8222. int reservationIdInt = -1;
  8223. DEBUG_INFO("handleCancelReservationRequest...\n");
  8224. json_object *CancelReservation;
  8225. CancelReservation = json_tokener_parse(payload);
  8226. if(!is_error(CancelReservation))
  8227. {
  8228. // Required data
  8229. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8230. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8231. }
  8232. json_object_put(CancelReservation);
  8233. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8234. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  8235. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  8236. if(reservationIdInt != -1)
  8237. {
  8238. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8239. //check Transaction active
  8240. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8242. {
  8243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8244. {
  8245. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  8246. if(gunType[2] == 'J')
  8247. {
  8248. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8249. }
  8250. else
  8251. {
  8252. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8253. }
  8254. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  8255. goto end;
  8256. }
  8257. }
  8258. for (int index = 0; index < CCS_QUANTITY; index++)
  8259. {
  8260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8261. {
  8262. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  8263. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  8264. {
  8265. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8266. }
  8267. else
  8268. {
  8269. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8270. }
  8271. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  8272. goto end;
  8273. }
  8274. }
  8275. for (int index = 0; index < GB_QUANTITY; index++)
  8276. {
  8277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8278. {
  8279. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  8280. if(gunType[2] == 'G')
  8281. {
  8282. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8283. }
  8284. else
  8285. {
  8286. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8287. }
  8288. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  8289. goto end;
  8290. }
  8291. }
  8292. for (int index = 0; index < AC_QUANTITY; index++)
  8293. {
  8294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8295. {
  8296. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  8297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8298. {
  8299. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8300. }
  8301. else
  8302. {
  8303. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8304. }
  8305. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  8306. goto end;
  8307. }
  8308. }
  8309. }
  8310. //The reservationId does NOT match the reservationId
  8311. sendCancelReservationConfirmation(uuid, gunNO);
  8312. end:
  8313. // Fill in ocpp packet uuid
  8314. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  8315. return result;
  8316. }
  8317. int handleCertificateSignedRequest(char *uuid, char *payload)
  8318. {
  8319. mtrace();
  8320. int result = FAIL;
  8321. json_object *CertificateSigned;
  8322. DEBUG_INFO("handleCertificateSignedRequest...\n");
  8323. CertificateSigned = json_tokener_parse(payload);
  8324. if(!is_error(CertificateSigned))
  8325. {
  8326. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  8327. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  8328. // Required data
  8329. if(json_object_array_length(json_object_object_get(CertificateSigned, "certificate")) <= ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.certificate))
  8330. {
  8331. for(int idx=0;idx<json_object_array_length(json_object_object_get(CertificateSigned, "certificate"));idx++)
  8332. {
  8333. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificate[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateType"), idx)));
  8334. /*
  8335. * TODO:
  8336. * 1. Certificate install response
  8337. */
  8338. }
  8339. }
  8340. // Optional data
  8341. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  8342. {
  8343. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  8344. }
  8345. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  8346. }
  8347. else
  8348. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  8349. json_object_put(CertificateSigned);
  8350. sendCertificateSignedConfirmation(uuid);
  8351. return result;
  8352. }
  8353. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8354. {
  8355. mtrace();
  8356. int result = FAIL;
  8357. int evseId = 0, gunIndex = 0;
  8358. char operationalStatus[16]={0};
  8359. char comfirmstr[20];
  8360. int specificId = FALSE;
  8361. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8362. json_object *ChangeAvailability;
  8363. ChangeAvailability = json_tokener_parse(payload);
  8364. if(!is_error(ChangeAvailability))
  8365. {
  8366. // Required data
  8367. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  8368. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  8369. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  8370. {
  8371. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  8372. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  8373. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  8374. }
  8375. }
  8376. json_object_put(ChangeAvailability);
  8377. if((evseId != 0) && (evseId <= gunTotalNumber))
  8378. {
  8379. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  8380. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  8381. }
  8382. else if(evseId == 0)
  8383. {
  8384. for(int i=0; i < gunTotalNumber; i++)
  8385. {
  8386. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  8387. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  8388. }
  8389. }
  8390. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8391. {
  8392. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  8393. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  8394. }
  8395. else if(gunIndex == 0)
  8396. {
  8397. for(int i=0; i < gunTotalNumber; i++)
  8398. {
  8399. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  8400. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  8401. }
  8402. }
  8403. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8404. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8405. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  8406. {
  8407. specificId = TRUE;
  8408. }
  8409. if(specificId == FALSE)
  8410. goto end;
  8411. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  8412. {
  8413. //----------------------gunIndex is 0 ------------------------------------------------//
  8414. if(gunIndex == 0)
  8415. {
  8416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8417. {
  8418. for(int i=0; i < gunTotalNumber; i++)
  8419. {
  8420. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8421. {
  8422. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8423. {
  8424. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8425. {
  8426. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8427. goto end;
  8428. }
  8429. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8430. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8431. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8432. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8433. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8434. {
  8435. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8436. goto end;
  8437. }
  8438. }
  8439. }//END FOR CHAdeMO_QUANTITY
  8440. for (int index = 0; index < CCS_QUANTITY; index++)
  8441. {
  8442. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8443. {
  8444. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8445. {
  8446. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8447. goto end;
  8448. }
  8449. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8450. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8451. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8452. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8453. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8454. {
  8455. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8456. goto end;
  8457. }
  8458. }
  8459. }//END FOR CCS_QUANTITY
  8460. for (int index = 0; index < GB_QUANTITY; index++)
  8461. {
  8462. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8463. {
  8464. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8465. {
  8466. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8467. goto end;
  8468. }
  8469. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8470. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8471. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8472. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8473. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8474. {
  8475. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8476. goto end;
  8477. }
  8478. }
  8479. }// END FOR GB_QUANTITY
  8480. for (int index = 0; index < AC_QUANTITY; index++)
  8481. {
  8482. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8483. {
  8484. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8485. {
  8486. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8487. goto end;
  8488. }
  8489. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8490. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8491. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8492. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8493. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8494. {
  8495. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8496. goto end;
  8497. }
  8498. }
  8499. }//END FOR AC_QUANTITY
  8500. }// END FOR gunTotalNumber
  8501. }
  8502. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8503. {
  8504. for(int i=0; i < gunTotalNumber; i++)
  8505. {
  8506. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8507. {
  8508. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8509. goto end;
  8510. }
  8511. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8512. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8513. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8514. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8515. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8516. {
  8517. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8518. goto end;
  8519. }
  8520. }
  8521. }
  8522. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8523. goto end;
  8524. }
  8525. //----------------------gunIndex is not 0 ------------------------------------------------//
  8526. //check Transaction active
  8527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8528. {
  8529. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  8530. {
  8531. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8532. {
  8533. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8534. goto end;
  8535. }
  8536. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8537. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8538. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8539. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8540. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8541. {
  8542. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8543. goto end;
  8544. }
  8545. else
  8546. {
  8547. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8548. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8549. goto end;
  8550. }
  8551. }
  8552. }//END FOR CHAdeMO_QUANTITY
  8553. for (int index = 0; index < CCS_QUANTITY; index++)
  8554. {
  8555. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  8556. {
  8557. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8558. {
  8559. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8560. goto end;
  8561. }
  8562. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8563. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8564. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8565. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8566. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8567. {
  8568. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8569. goto end;
  8570. }
  8571. else
  8572. {
  8573. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8574. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8575. goto end;
  8576. }
  8577. }
  8578. }//END FOR CCS_QUANTITY
  8579. for (int index = 0; index < GB_QUANTITY; index++)
  8580. {
  8581. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  8582. {
  8583. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8584. {
  8585. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8586. goto end;
  8587. }
  8588. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8590. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8591. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8592. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8593. {
  8594. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8595. goto end;
  8596. }
  8597. else
  8598. {
  8599. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8600. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8601. goto end;
  8602. }
  8603. }
  8604. }// END FOR GB_QUANTITY
  8605. for (int index = 0; index < AC_QUANTITY; index++)
  8606. {
  8607. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  8608. {
  8609. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8610. {
  8611. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8612. goto end;
  8613. }
  8614. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8615. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8616. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8617. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8618. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8619. {
  8620. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  8621. goto end;
  8622. }
  8623. else
  8624. {
  8625. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8626. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8627. goto end;
  8628. }
  8629. }
  8630. }//END FOR AC_QUANTITY
  8631. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  8632. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  8633. {
  8634. //----------------------gunIndex is 0 ------------------------------------------------//
  8635. if(gunIndex == 0)
  8636. {
  8637. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8638. {
  8639. for(int i=0; i < gunTotalNumber; i++)
  8640. {
  8641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8642. {
  8643. if ((gunType[i] == 'J' )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8644. {
  8645. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8646. goto end;
  8647. }
  8648. }//END FOR CHAdeMO_QUANTITY
  8649. for (int index = 0; index < CCS_QUANTITY; index++)
  8650. {
  8651. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(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
  8652. {
  8653. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8654. goto end;
  8655. }
  8656. }//END FOR CCS_QUANTITY
  8657. for (int index = 0; index < GB_QUANTITY; index++)
  8658. {
  8659. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8660. {
  8661. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  8662. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8663. goto end;
  8664. }
  8665. }// END FOR GB_QUANTITY
  8666. for (int index = 0; index < AC_QUANTITY; index++)
  8667. {
  8668. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(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
  8669. {
  8670. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8671. goto end;
  8672. }
  8673. }//END FOR CHAdeMO_QUANTITY
  8674. }// END FOR gunTotalNumber
  8675. }
  8676. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8677. {
  8678. for(int i=0; i < gunTotalNumber; i++)
  8679. {
  8680. for (int index = 0; index < AC_QUANTITY; index++)
  8681. {
  8682. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(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
  8683. {
  8684. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  8685. goto end;
  8686. }
  8687. }//END FOR CHAdeMO_QUANTITY
  8688. } // END FOR gunTotalNumber
  8689. }
  8690. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8691. goto end;
  8692. }
  8693. //----------------------gunIndex is not 0 ------------------------------------------------//
  8694. //check Transaction active
  8695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8696. {
  8697. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8698. {
  8699. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8700. goto end;
  8701. }
  8702. }//END FOR CHAdeMO_QUANTITY
  8703. for (int index = 0; index < CCS_QUANTITY; index++)
  8704. {
  8705. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8706. {
  8707. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8708. goto end;
  8709. }
  8710. }//END FOR CCS_QUANTITY
  8711. for (int index = 0; index < GB_QUANTITY; index++)
  8712. {
  8713. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8714. {
  8715. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8716. goto end;
  8717. }
  8718. }// END FOR GB_QUANTITY
  8719. for (int index = 0; index < AC_QUANTITY; index++)
  8720. {
  8721. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8722. {
  8723. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  8724. goto end;
  8725. }
  8726. }//END FOR AC_QUANTITY
  8727. }//END FOR AvailabilityEnumTypeStr[Operative]
  8728. end:
  8729. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8730. {
  8731. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  8732. }
  8733. else
  8734. {
  8735. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  8736. }
  8737. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8738. {
  8739. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  8740. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  8741. }
  8742. else if(gunIndex == 0)
  8743. {
  8744. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  8745. {
  8746. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8747. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  8748. }
  8749. }
  8750. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  8751. return result;
  8752. }
  8753. int handleClearCacheRequest(char *uuid, char *payload)
  8754. {
  8755. mtrace();
  8756. int result = FAIL;
  8757. char rmFileCmd[100]={0};
  8758. struct stat stats;
  8759. DEBUG_INFO("handleClearCacheRequest...\n");
  8760. stat("/Storage/OCPP", &stats);
  8761. // Check for directory existence
  8762. if (S_ISDIR(stats.st_mode) == 1)
  8763. {}
  8764. else
  8765. {
  8766. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8767. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8768. system(rmFileCmd);
  8769. }
  8770. /*
  8771. * TODO:
  8772. * 1. Clear cache from sqlite db
  8773. */
  8774. if(1)
  8775. {
  8776. DEBUG_INFO("open AuthorizationCache file failed\n");
  8777. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  8778. }
  8779. else
  8780. {
  8781. DEBUG_INFO("open AuthorizationCache file successful\n");
  8782. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  8783. }
  8784. sendClearCacheConfirmation(uuid);
  8785. return result;
  8786. }
  8787. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8788. {
  8789. mtrace();
  8790. int result = FAIL;
  8791. int resultRename;
  8792. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8793. char chargingProfilePurposeStr[26]={0};
  8794. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8795. char tempchargingProfilePurposeStr[26]={0};
  8796. char sstr[160]={0};
  8797. char str[100]={0};
  8798. int c = 0;
  8799. char *loc;
  8800. char fname[200]={0};
  8801. char comfirmstr[20]={0};
  8802. char word[1600]={0};
  8803. int clearflag = FALSE;
  8804. int chargingProfileIdIsNULL = FALSE;
  8805. int connectorIsNULL = FALSE;
  8806. int chargingProfilePurposeIsNULL = FALSE;
  8807. int stackLevelIsNULL = FALSE;
  8808. //int GotoEnd = FALSE;
  8809. FILE *fptr1, *fptr2;
  8810. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8811. int n_chargingProfile=0;
  8812. int isEmptyFile = FALSE;
  8813. char sLineWord[1600]={0};
  8814. char chargingProfiles[10][100]={0};
  8815. int ChargeProfileCount = 0;
  8816. int ch;
  8817. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8818. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8819. json_object *ClearChargingProfile;
  8820. ClearChargingProfile = json_tokener_parse(payload);
  8821. if(!is_error(ClearChargingProfile))
  8822. {
  8823. // Optional data
  8824. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  8825. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  8826. else
  8827. chargingProfileIdIsNULL = TRUE;
  8828. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  8829. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  8830. else
  8831. connectorIsNULL = TRUE;
  8832. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  8833. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  8834. else
  8835. chargingProfilePurposeIsNULL = TRUE;
  8836. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  8837. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  8838. else
  8839. stackLevelIsNULL = TRUE;
  8840. }
  8841. json_object_put(ClearChargingProfile);
  8842. if(connectorIsNULL == FALSE)
  8843. {
  8844. switch(connectorIdInt)
  8845. {
  8846. case 0:
  8847. if(chargingProfilePurposeIsNULL == TRUE)
  8848. {
  8849. int l = 0;
  8850. strcpy(fname, ChargePointMaxProfile_JSON);
  8851. if((access(fname,F_OK))!=-1)
  8852. {
  8853. strcpy(chargingProfiles[l], fname);
  8854. l = l + 1;
  8855. }
  8856. strcpy(fname, TxDefaultProfile_0_JSON);
  8857. if((access(fname,F_OK))!=-1)
  8858. {
  8859. strcpy(chargingProfiles[l], fname);
  8860. l = l + 1;
  8861. }
  8862. ChargeProfileCount = l;
  8863. }
  8864. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8865. {
  8866. strcpy(fname, ChargePointMaxProfile_JSON);
  8867. if((access(fname,F_OK))!=-1)
  8868. {
  8869. strcpy(chargingProfiles[0], fname);
  8870. ChargeProfileCount = 1;
  8871. }
  8872. }
  8873. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8874. {
  8875. strcpy(fname, TxDefaultProfile_0_JSON);
  8876. if((access(fname,F_OK))!=-1)
  8877. {
  8878. strcpy(chargingProfiles[0], fname);
  8879. ChargeProfileCount = 1;
  8880. }
  8881. }
  8882. break;
  8883. default:
  8884. if(chargingProfilePurposeIsNULL == TRUE)
  8885. {
  8886. int m = 0;
  8887. memset(fname, 0, ARRAY_SIZE(fname));
  8888. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8889. if((access(fname,F_OK))!=-1)
  8890. {
  8891. strcpy(chargingProfiles[m], fname);
  8892. m = m + 1;
  8893. }
  8894. memset(fname, 0, ARRAY_SIZE(fname));
  8895. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8896. if((access(fname,F_OK))!=-1)
  8897. {
  8898. strcpy(chargingProfiles[m], fname);
  8899. m = m + 1;
  8900. }
  8901. ChargeProfileCount = m;
  8902. }
  8903. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8904. {
  8905. //strcpy(fname, TxDefaultProfile_1_JSON);
  8906. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8907. if((access(fname,F_OK))!=-1)
  8908. {
  8909. strcpy(chargingProfiles[0], fname);
  8910. ChargeProfileCount = 1;
  8911. }
  8912. }
  8913. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8914. {
  8915. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8916. if((access(fname,F_OK))!=-1)
  8917. {
  8918. strcpy(chargingProfiles[0], fname);
  8919. ChargeProfileCount = 1;
  8920. }
  8921. }
  8922. //strcpy(fname, ChargePointMaxProfile_JSON );
  8923. break;
  8924. }
  8925. }
  8926. else // Check all Charging Profiles
  8927. {
  8928. int i = 0;
  8929. char fnametemp[200]={0};
  8930. ChargeProfileCount = 0;
  8931. //Check ChargePointMaxProfile.json exit
  8932. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8933. {
  8934. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8935. i = i + 1;
  8936. }
  8937. //Check TxDefaultProfile_0.json exit
  8938. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8939. {
  8940. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8941. i = i + 1;
  8942. }
  8943. //Check TxDefaultProfile_%d.json
  8944. for(int j=1; j <= gunTotalNumber; j++)
  8945. {
  8946. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8947. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8948. if((access(fnametemp,F_OK))!=-1)
  8949. {
  8950. strcpy(chargingProfiles[i], fnametemp);
  8951. i = i + 1;
  8952. }
  8953. }
  8954. //Check TxProfile_%d.json
  8955. for(int j=1; j <= gunTotalNumber; j++)
  8956. {
  8957. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8958. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8959. if((access(fnametemp,F_OK))!=-1)
  8960. {
  8961. strcpy(chargingProfiles[i], fnametemp);
  8962. i = i + 1;
  8963. }
  8964. }
  8965. ChargeProfileCount = i;
  8966. }// End connectorIsNULL is TRUE
  8967. if(ChargeProfileCount == 0)
  8968. {
  8969. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  8970. goto end;
  8971. }
  8972. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8973. {
  8974. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  8975. goto end;
  8976. }
  8977. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8978. {
  8979. memset(str, 0, ARRAY_SIZE(str));
  8980. // clear temp file
  8981. sprintf(str,"rm -f %s",temp);
  8982. system(str);
  8983. for(int k=0; k < ChargeProfileCount; k++)
  8984. {
  8985. memset(str, 0, ARRAY_SIZE(str));
  8986. //clear file in C
  8987. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8988. system(str);
  8989. }
  8990. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  8991. goto end;
  8992. }
  8993. else if(connectorIsNULL == TRUE)
  8994. {
  8995. for(int k=0; k < ChargeProfileCount; k++)
  8996. {
  8997. fptr1 = fopen(chargingProfiles[k], "r");
  8998. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8999. //Check Charging Profile Count
  9000. while(fscanf(fptr1, "%s", word) != EOF)
  9001. {
  9002. //DEBUG_INFO("word=%s\n",word);
  9003. if(strstr(word, "chargingProfileId")!= NULL)
  9004. {
  9005. //DEBUG_INFO("test chargingProfileId \n");
  9006. n_chargingProfile = n_chargingProfile + 1;
  9007. //DEBUG_INFO("chargingProfileId Found\n");
  9008. }
  9009. }
  9010. rewind(fptr1);
  9011. //search Charging Profile Element
  9012. //int i= 0;
  9013. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9014. {
  9015. //------------------------tempconnectorIdInt------------------------//
  9016. loc = strstr(sLineWord, "connectorId");
  9017. c = 0;
  9018. memset(sstr ,0, sizeof(sstr) );
  9019. while (loc[strlen("connectorId")+2+c] != ',')
  9020. {
  9021. sstr[c] = loc[strlen("connectorId")+2+c];
  9022. c++;
  9023. }
  9024. sstr[c] = '\0';
  9025. tempconnectorIdInt = atoi(sstr);
  9026. printf("file's gun number is %d\n", tempconnectorIdInt);
  9027. //--------------------------chargingProfileId--------------------//
  9028. c = 0;
  9029. loc = strstr(sLineWord, "chargingProfileId");
  9030. memset(sstr ,0, ARRAY_SIZE(sstr));
  9031. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9032. {
  9033. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9034. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9035. c++;
  9036. }
  9037. sstr[c] = '\0';
  9038. tempchargingProfileIdInt = atoi(sstr);
  9039. //stackLevel
  9040. c = 0;
  9041. loc = strstr(sLineWord, "stackLevel");
  9042. memset(sstr ,0, ARRAY_SIZE(sstr));
  9043. while (loc[strlen("stackLevel")+2+c] != ',')
  9044. {
  9045. sstr[c] = loc[strlen("stackLevel")+2+c];
  9046. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9047. c++;
  9048. }
  9049. sstr[c] = '\0';
  9050. tempstackLevelInt = atoi(sstr);
  9051. c = 0;
  9052. loc = strstr(sLineWord, "chargingProfilePurpose");
  9053. memset(sstr ,0, ARRAY_SIZE(sstr));
  9054. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9055. {
  9056. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9057. c++;
  9058. }
  9059. sstr[c] = '\0';
  9060. strcpy(tempchargingProfilePurposeStr, sstr);
  9061. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9062. {
  9063. //------- not write to fptr2-------//
  9064. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9065. //clearflag = TRUE;
  9066. }
  9067. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9068. {
  9069. //------- not write to fptr2-------//
  9070. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9071. }
  9072. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9073. {
  9074. //------- not write to fptr2-------//
  9075. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9076. }
  9077. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9078. {
  9079. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9080. }
  9081. else
  9082. {
  9083. fprintf(fptr2, sLineWord);//writing data into file
  9084. }
  9085. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9086. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9087. if(clearflag == TRUE)
  9088. {
  9089. fclose(fptr1);
  9090. fclose(fptr2);
  9091. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9092. system(str);
  9093. // clear temp file
  9094. sprintf(str,"rm -f %s",temp);
  9095. system(str);
  9096. }
  9097. else
  9098. {
  9099. fclose(fptr1);
  9100. fclose(fptr2);
  9101. memset(str, 0, ARRAY_SIZE(str));
  9102. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9103. system(str);
  9104. resultRename = rename(temp, chargingProfiles[k]);
  9105. if(resultRename == 0)
  9106. {
  9107. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9108. }
  9109. else
  9110. {
  9111. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9112. }
  9113. if(comfirmstr[0]== 0)
  9114. {
  9115. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  9116. }
  9117. //Check chargingProfile is empty file
  9118. /*------ Read the file ----------------*/
  9119. fptr1=fopen(chargingProfiles[k],"r");
  9120. ch=fgetc(fptr1);
  9121. rewind(fptr1);
  9122. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9123. if(ch!=EOF)
  9124. {
  9125. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9126. {
  9127. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9128. if(sLineWord[0]=='\0')
  9129. {
  9130. isEmptyFile = TRUE;
  9131. break;
  9132. }
  9133. else
  9134. {
  9135. isEmptyFile = FALSE;
  9136. break;
  9137. }
  9138. }
  9139. }
  9140. else
  9141. isEmptyFile = TRUE;
  9142. fclose(fptr1);
  9143. if(isEmptyFile == TRUE)
  9144. {
  9145. memset(str, 0, ARRAY_SIZE(str));
  9146. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9147. system(str);
  9148. }
  9149. }
  9150. }// End of while(int k=0; k < ChargePointCount; k++)
  9151. }
  9152. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9153. {
  9154. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9155. for(int k=0; k < ChargeProfileCount; k++)
  9156. {
  9157. fptr1 = fopen(chargingProfiles[k], "r");
  9158. fptr2 = fopen(temp, "w+");
  9159. //Check Charging Profile Count
  9160. while(fscanf(fptr1, "%s", word) != EOF)
  9161. {
  9162. //DEBUG_INFO("word=%s\n",word);
  9163. if(strstr(word, "chargingProfileId")!= NULL)
  9164. {
  9165. n_chargingProfile = n_chargingProfile + 1;
  9166. }
  9167. }
  9168. rewind(fptr1);
  9169. //search Charging Profile Element
  9170. //int i= 0;
  9171. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9172. {
  9173. //*************************tempconnectorIdInt*********************************/
  9174. loc = strstr(sLineWord, "connectorId");
  9175. c = 0;
  9176. memset(sstr ,0, ARRAY_SIZE(sstr));
  9177. while (loc[strlen("connectorId")+2+c] != ',')
  9178. {
  9179. sstr[c] = loc[strlen("connectorId")+2+c];
  9180. c++;
  9181. }
  9182. sstr[c] = '\0';
  9183. tempconnectorIdInt = atoi(sstr);
  9184. //chargingProfileId
  9185. c = 0;
  9186. loc = strstr(sLineWord, "chargingProfileId");
  9187. memset(sstr ,0, ARRAY_SIZE(sstr));
  9188. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9189. {
  9190. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9191. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9192. c++;
  9193. }
  9194. sstr[c] = '\0';
  9195. tempchargingProfileIdInt = atoi(sstr);
  9196. //stackLevel
  9197. c = 0;
  9198. loc = strstr(sLineWord, "stackLevel");
  9199. memset(sstr ,0, ARRAY_SIZE(sstr));
  9200. while (loc[strlen("stackLevel")+2+c] != ',')
  9201. {
  9202. sstr[c] = loc[strlen("stackLevel")+2+c];
  9203. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9204. c++;
  9205. }
  9206. sstr[c] = '\0';
  9207. tempstackLevelInt = atoi(sstr);
  9208. c = 0;
  9209. loc = strstr(sLineWord, "chargingProfilePurpose");
  9210. memset(sstr ,0, ARRAY_SIZE(sstr));
  9211. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9212. {
  9213. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9214. c++;
  9215. }
  9216. sstr[c] = '\0';
  9217. strcpy(tempchargingProfilePurposeStr, sstr);
  9218. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9219. {
  9220. //------- not write to fptr2-------//
  9221. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9222. //clearflag = TRUE;
  9223. }
  9224. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9225. {
  9226. //------- not write to fptr2-------//
  9227. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9228. }
  9229. else if(stackLevelIsNULL == TRUE)
  9230. {
  9231. //Clear Whole File
  9232. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9233. clearflag = TRUE;
  9234. break;
  9235. }
  9236. else
  9237. {
  9238. fprintf(fptr2, sLineWord);//writing data into file
  9239. }
  9240. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9241. }
  9242. if(clearflag == TRUE)
  9243. {
  9244. fclose(fptr1);
  9245. fclose(fptr2);
  9246. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9247. system(str);
  9248. // clear temp file
  9249. sprintf(str,"rm -f %s",temp);
  9250. system(str);
  9251. }
  9252. else
  9253. {
  9254. fclose(fptr1);
  9255. fclose(fptr2);
  9256. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9257. system(str);
  9258. resultRename = rename(temp, chargingProfiles[k]);
  9259. if(resultRename == 0)
  9260. {
  9261. DEBUG_INFO("File ChargingProfile renamed successfully");
  9262. }
  9263. else
  9264. {
  9265. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9266. }
  9267. if(comfirmstr[0]== 0)
  9268. {
  9269. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  9270. }
  9271. //Check chargingProfile is empty file
  9272. /*------ Read the file ----------------*/
  9273. fptr1=fopen(chargingProfiles[k],"r");
  9274. ch=fgetc(fptr1);
  9275. rewind(fptr1);
  9276. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9277. if(ch!=EOF)
  9278. {
  9279. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9280. {
  9281. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9282. if(sLineWord[0]=='\0')
  9283. {
  9284. isEmptyFile = TRUE;
  9285. break;
  9286. }
  9287. else
  9288. {
  9289. isEmptyFile = FALSE;
  9290. break;
  9291. }
  9292. }
  9293. }
  9294. else
  9295. isEmptyFile = TRUE;
  9296. fclose(fptr1);
  9297. if(isEmptyFile == TRUE)
  9298. {
  9299. memset(str, 0, ARRAY_SIZE(str));
  9300. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9301. system(str);
  9302. }
  9303. /*------- End of reading ---------------*/
  9304. }
  9305. } // while(int k=0; k < ChargeProfileCount; k++)
  9306. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9307. end:
  9308. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  9309. {
  9310. if(connectorIdInt == 0)
  9311. {
  9312. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9313. {
  9314. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx]);
  9315. }
  9316. }
  9317. else
  9318. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1]);
  9319. }
  9320. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9321. return result;
  9322. }
  9323. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  9324. {
  9325. mtrace();
  9326. int result = FAIL;
  9327. json_object *ClearDisplayMessage;
  9328. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  9329. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  9330. ClearDisplayMessage = json_tokener_parse(payload);
  9331. if(!is_error(ClearDisplayMessage))
  9332. {
  9333. // Required data
  9334. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  9335. {
  9336. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  9337. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  9338. }
  9339. }
  9340. json_object_put(ClearDisplayMessage);
  9341. sendCostUpdatedConfirmation(uuid);
  9342. return result;
  9343. }
  9344. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  9345. {
  9346. mtrace();
  9347. int result = FAIL;
  9348. json_object *ClearVariableMonitorin;
  9349. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  9350. ClearVariableMonitorin = json_tokener_parse(payload);
  9351. if(!is_error(ClearVariableMonitorin))
  9352. {
  9353. // Required data
  9354. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  9355. {
  9356. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  9357. {
  9358. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  9359. /*
  9360. * TODO:
  9361. * 1. Check response
  9362. */
  9363. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  9364. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  9365. }
  9366. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  9367. }
  9368. }
  9369. json_object_put(ClearVariableMonitorin);
  9370. return result;
  9371. }
  9372. int handleCostUpdatedRequest(char *uuid, char *payload)
  9373. {
  9374. mtrace();
  9375. int result = FAIL;
  9376. json_object *CostUpdate;
  9377. DEBUG_INFO("handleCostUpdatedRequest...\n");
  9378. CostUpdate = json_tokener_parse(payload);
  9379. if(!is_error(CostUpdate))
  9380. {
  9381. // Required data
  9382. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  9383. {
  9384. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  9385. }
  9386. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  9387. {
  9388. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  9389. }
  9390. }
  9391. json_object_put(CostUpdate);
  9392. sendCostUpdatedConfirmation(uuid);
  9393. return result;
  9394. }
  9395. int handleCustomerInformationRequest(char *uuid, char *payload)
  9396. {
  9397. mtrace();
  9398. int result = FAIL;
  9399. json_object *CustomerInformation;
  9400. DEBUG_INFO("handleCustomerInformationRequest...\n");
  9401. CustomerInformation = json_tokener_parse(payload);
  9402. if(!is_error(CustomerInformation))
  9403. {
  9404. // Required data
  9405. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  9406. {
  9407. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  9408. }
  9409. if(json_object_object_get(CustomerInformation, "report") != NULL)
  9410. {
  9411. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  9412. }
  9413. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  9414. {
  9415. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  9416. }
  9417. // Optional data
  9418. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  9419. {
  9420. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  9421. {
  9422. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  9423. }
  9424. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  9425. {
  9426. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  9427. }
  9428. }
  9429. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  9430. {
  9431. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  9432. {
  9433. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  9434. }
  9435. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  9436. {
  9437. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  9438. }
  9439. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  9440. {
  9441. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  9442. }
  9443. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  9444. {
  9445. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  9446. }
  9447. }
  9448. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  9449. }
  9450. else
  9451. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  9452. json_object_put(CustomerInformation);
  9453. sendCustomerInformationConfirmation(uuid);
  9454. return result;
  9455. }
  9456. void createFirmwareVersionByDataTransfer(void)
  9457. {
  9458. json_object *FirmwareDataTransfer = json_object_new_object();
  9459. // AC & DC model
  9460. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9461. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9462. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9463. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9464. // DC model
  9465. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9466. {
  9467. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9468. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9469. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9470. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9471. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9472. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9473. }
  9474. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  9475. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  9476. {
  9477. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9478. }
  9479. // 4G model
  9480. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  9481. {
  9482. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9483. }
  9484. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "Phihong Technology");
  9485. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion");
  9486. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, json_object_to_json_string(FirmwareDataTransfer));
  9487. }
  9488. int handleDataTransferRequest(char *uuid, char *payload)
  9489. {
  9490. mtrace();
  9491. int result = PASS;
  9492. DEBUG_INFO("handleDataTransferRequest...\n");
  9493. if((uuid != NULL) && (payload != NULL))
  9494. {
  9495. json_object *DataTransfer;
  9496. DataTransfer = json_tokener_parse(payload);
  9497. if(!is_error(DataTransfer))
  9498. {
  9499. // Required data
  9500. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9501. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9502. // Optional data
  9503. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9504. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9505. if(json_object_object_get(DataTransfer, "data") != NULL)
  9506. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9507. result = PASS;
  9508. }
  9509. json_object_put(DataTransfer);
  9510. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  9511. {
  9512. // Send all moudle firmware version on EVSE
  9513. system("/usr/bin/run_tmate_restart.sh");
  9514. createFirmwareVersionByDataTransfer();
  9515. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  9516. }
  9517. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  9518. {
  9519. json_object *data;
  9520. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  9521. if(!is_error(data))
  9522. {
  9523. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9524. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9525. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9526. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9527. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9528. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9529. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9530. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9531. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9532. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9533. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  9534. }
  9535. else
  9536. {
  9537. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  9538. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  9539. }
  9540. json_object_put(data);
  9541. }
  9542. else
  9543. {
  9544. // Can not find valid message id
  9545. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  9546. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  9547. ,ShmOCPP20Data->DataTransfer[0].vendorId
  9548. ,ShmOCPP20Data->DataTransfer[0].messageId
  9549. ,ShmOCPP20Data->DataTransfer[0].data);
  9550. }
  9551. }
  9552. else
  9553. {
  9554. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  9555. result = FAIL;
  9556. }
  9557. sendDataTransferConfirmation(uuid, 0);
  9558. return result;
  9559. }
  9560. int handleDeleteCertificateRequest(char *uuid, char *payload)
  9561. {
  9562. mtrace();
  9563. int result = FAIL;
  9564. json_object *DeleteCertificate;
  9565. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  9566. DeleteCertificate = json_tokener_parse(payload);
  9567. if(!is_error(DeleteCertificate))
  9568. {
  9569. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  9570. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  9571. // Required data
  9572. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  9573. {
  9574. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  9575. {
  9576. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  9577. }
  9578. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  9579. {
  9580. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  9581. }
  9582. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  9583. {
  9584. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  9585. }
  9586. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  9587. {
  9588. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  9589. }
  9590. /*
  9591. * TODO:
  9592. * 1. Delete certification and response
  9593. */
  9594. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  9595. }
  9596. }
  9597. else
  9598. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  9599. json_object_put(DeleteCertificate);
  9600. sendDeleteCertificateConfirmation(uuid);
  9601. return result;
  9602. }
  9603. int handleGetBaseReportRequest(char *uuid, char *payload)
  9604. {
  9605. mtrace();
  9606. int result = FAIL;
  9607. json_object *GetBaseRepor;
  9608. DEBUG_INFO("handleGetBaseReportRequest...\n");
  9609. GetBaseRepor = json_tokener_parse(payload);
  9610. if(!is_error(GetBaseRepor))
  9611. {
  9612. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  9613. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  9614. // Required data
  9615. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  9616. {
  9617. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  9618. }
  9619. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  9620. {
  9621. sprintf((char*)ShmOCPP20Data->GetBaseReport.requestId, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  9622. }
  9623. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  9624. }
  9625. else
  9626. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  9627. json_object_put(GetBaseRepor);
  9628. sendGetBaseReportConfirmation(uuid);
  9629. /*
  9630. * TODO:
  9631. * 1. Delete certification and response
  9632. */
  9633. return result;
  9634. }
  9635. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  9636. {
  9637. mtrace();
  9638. int result = FAIL;
  9639. int gun_index = -1;
  9640. json_object *GetChargingProfiles;
  9641. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  9642. GetChargingProfiles = json_tokener_parse(payload);
  9643. if(!is_error(GetChargingProfiles))
  9644. {
  9645. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  9646. {
  9647. 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;
  9648. }
  9649. if(gun_index >-1)
  9650. {
  9651. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  9652. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  9653. // Required data
  9654. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  9655. {
  9656. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  9657. }
  9658. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  9659. {
  9660. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  9661. {
  9662. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  9663. }
  9664. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  9665. {
  9666. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  9667. }
  9668. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  9669. {
  9670. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  9671. {
  9672. 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)));
  9673. }
  9674. }
  9675. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  9676. {
  9677. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  9678. {
  9679. 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));
  9680. }
  9681. }
  9682. }
  9683. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  9684. }
  9685. else
  9686. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  9687. }
  9688. json_object_put(GetChargingProfiles);
  9689. sendGetChargingProfilesConfirmation(uuid, gun_index);
  9690. return result;
  9691. }
  9692. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9693. {
  9694. mtrace();
  9695. int result = FAIL;
  9696. int connectorIdInt, durationInt;
  9697. char chargingRateUnitStr[4]={0};
  9698. char comfirmstr[20];
  9699. int confirmPeriods = 0;
  9700. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9701. json_object *GetCompositeSchedule;
  9702. GetCompositeSchedule = json_tokener_parse(payload);
  9703. if(!is_error(GetCompositeSchedule))
  9704. {
  9705. // Required data
  9706. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  9707. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  9708. else
  9709. connectorIdInt = -1;
  9710. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9711. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9712. else
  9713. durationInt = 86400;
  9714. // Optional data
  9715. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9716. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9717. }
  9718. json_object_put(GetCompositeSchedule);
  9719. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9720. if((connectorIdInt == 0) ||
  9721. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9722. {
  9723. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9724. struct ChargingProfileType tmpProfile[1];
  9725. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  9726. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  9727. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  9728. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  9729. {
  9730. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  9731. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  9732. }
  9733. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct CompositeScheduleType));
  9734. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  9735. {
  9736. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  9737. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  9738. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  9739. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0))
  9740. {
  9741. confirmPeriods = idx;
  9742. break;
  9743. }
  9744. }
  9745. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  9746. }
  9747. else
  9748. {
  9749. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  9750. }
  9751. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9752. return result;
  9753. }
  9754. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  9755. {
  9756. mtrace();
  9757. int result = FAIL;
  9758. json_object *GetDisplayMessages;
  9759. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  9760. GetDisplayMessages = json_tokener_parse(payload);
  9761. if(!is_error(GetDisplayMessages))
  9762. {
  9763. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  9764. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  9765. // Required data
  9766. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  9767. {
  9768. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  9769. }
  9770. // Optional data
  9771. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  9772. {
  9773. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  9774. }
  9775. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  9776. {
  9777. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  9778. }
  9779. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  9780. {
  9781. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  9782. {
  9783. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  9784. }
  9785. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  9786. }
  9787. else
  9788. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  9789. }
  9790. json_object_put(GetDisplayMessages);
  9791. return result;
  9792. }
  9793. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  9794. {
  9795. mtrace();
  9796. int result = FAIL;
  9797. json_object *GetInstalledCertificateIds;
  9798. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  9799. GetInstalledCertificateIds = json_tokener_parse(payload);
  9800. if(!is_error(GetInstalledCertificateIds))
  9801. {
  9802. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  9803. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  9804. // Optional data
  9805. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  9806. {
  9807. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  9808. {
  9809. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  9810. /*
  9811. * TODO:
  9812. * 1. Get installed certificate info for response
  9813. */
  9814. }
  9815. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  9816. }
  9817. else
  9818. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  9819. }
  9820. json_object_put(GetInstalledCertificateIds);
  9821. sendInstallCertificateConfirmation(uuid);
  9822. return result;
  9823. }
  9824. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9825. {
  9826. mtrace();
  9827. int result = FAIL;
  9828. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9829. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  9830. {
  9831. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9832. localversion = -1;
  9833. }
  9834. else
  9835. {
  9836. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9837. DB_getListVerion();
  9838. }
  9839. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  9840. sendGetLocalListVersionConfirmation(uuid);
  9841. return result;
  9842. }
  9843. static char fnamePlusPath[100]={0};
  9844. static char fnamePWithNoPath[60]={0};
  9845. void checkUploadLog(void)
  9846. {
  9847. FILE *fp;
  9848. /* Open the command for reading. */
  9849. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9850. if (fp == NULL) {
  9851. printf("Failed to run command\n" );
  9852. exit(1);
  9853. }
  9854. int ftppathlen = 0;
  9855. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9856. int i = 0;
  9857. /* Read the output a line at a time - output it. */
  9858. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9859. if(i==0)
  9860. {
  9861. ftppathlen = strlen(fnamePlusPath);
  9862. printf("%s\n", fnamePlusPath);
  9863. fnamePlusPath[ftppathlen]='\0';
  9864. break;
  9865. }
  9866. i= i+1;
  9867. }
  9868. /* close */
  9869. pclose(fp);
  9870. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9871. {
  9872. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  9873. {
  9874. fnamePlusPath[k]='\0';
  9875. }
  9876. }
  9877. i=1;
  9878. //char fname[60]={0};
  9879. while(i < ftppathlen)
  9880. {
  9881. int len=ftppathlen-i;
  9882. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9883. {
  9884. printf("compare '/' all right\n");
  9885. break;
  9886. }
  9887. i=i+1;
  9888. }
  9889. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9890. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9891. fnamePWithNoPath[i+1] = '\0';
  9892. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9893. {
  9894. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9895. {
  9896. fnamePWithNoPath[j]='\0';
  9897. }
  9898. }
  9899. FILE* fp1 = fopen(fnamePlusPath, "r");
  9900. if (fp1)
  9901. {
  9902. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9903. // file exists
  9904. fclose(fp1);
  9905. }
  9906. else
  9907. {
  9908. // file doesn't exist
  9909. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9910. }
  9911. }
  9912. void* GetLogProcess(void* data)
  9913. {
  9914. pthread_detach(pthread_self());
  9915. mtrace();
  9916. int requestId, retriesInt=0, retryIntervalInt=0;
  9917. char logType[32], remoteLocation[512]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  9918. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  9919. int port=0;
  9920. int isSuccess = FALSE;
  9921. char ftpbuf[200]={0};
  9922. json_object *GetLog;
  9923. DEBUG_INFO("GetGetProcess...\n");
  9924. GetLog = json_tokener_parse(data);
  9925. if(!is_error(GetLog))
  9926. {
  9927. // Required data
  9928. if(json_object_object_get(GetLog, "requestId") != NULL)
  9929. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  9930. if(json_object_object_get(GetLog, "logType") != NULL)
  9931. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  9932. if(json_object_object_get(GetLog, "log") != NULL)
  9933. {
  9934. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  9935. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  9936. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  9937. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  9938. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  9939. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  9940. }
  9941. // Optional data
  9942. if(json_object_object_get(GetLog, "retries") != NULL)
  9943. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  9944. else
  9945. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9946. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  9947. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  9948. else
  9949. retryIntervalInt = 30;
  9950. }
  9951. json_object_put(GetLog);
  9952. ShmOCPP20Data->GetLog.requestId = requestId;
  9953. //****************location*******************/
  9954. if(strcmp(remoteLocation,"")==0)
  9955. {
  9956. DEBUG_INFO("remoteLocation is <Empty>!\n");
  9957. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  9958. goto end;
  9959. }
  9960. memset(protocol, 0, ARRAY_SIZE(protocol));
  9961. memset(user, 0, ARRAY_SIZE(user) );
  9962. memset(password, 0, ARRAY_SIZE(password));
  9963. memset(host, 0, ARRAY_SIZE(host));
  9964. memset(path, 0, ARRAY_SIZE(path));
  9965. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9966. memset(host1, 0, ARRAY_SIZE(host1));
  9967. memset(path1, 0, ARRAY_SIZE(path1));
  9968. /*location: ftp://user:password@host:port/path*/
  9969. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9970. if((access(fnamePlusPath,F_OK))!=-1)
  9971. {
  9972. DEBUG_INFO("fnamePlusPath exist.\n");
  9973. }
  9974. else
  9975. {
  9976. DEBUG_INFO("fnamePlusPath not exist!\n");
  9977. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  9978. goto end;
  9979. }
  9980. if(strchr(remoteLocation,'@')==NULL)
  9981. {
  9982. sscanf(remoteLocation,
  9983. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9984. protocol, host, &port, path);
  9985. strcpy(user,"anonymous");
  9986. strcpy(password,"");
  9987. }
  9988. else
  9989. {
  9990. //DEBUG_INFO("pch=%s\n", pch);
  9991. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9992. protocol, user, password, host, &port, path);
  9993. }
  9994. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  9995. {
  9996. DEBUG_INFO("protocol is not ftp/http ! \n");
  9997. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  9998. goto end;
  9999. }
  10000. if(strncmp(remoteLocation,"http", 4) == 0)
  10001. {
  10002. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10003. sprintf(ftppath,"/%s", path);
  10004. do
  10005. {
  10006. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  10007. sleep(3);
  10008. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  10009. if(!isSuccess)
  10010. {
  10011. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  10012. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  10013. sleep(retryIntervalInt);
  10014. }
  10015. else
  10016. {
  10017. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  10018. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  10019. }
  10020. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt--));
  10021. }
  10022. else
  10023. {
  10024. sscanf(host,"%[^/]%s",host1, path1);
  10025. sprintf(ftppath,"%s", path1);
  10026. int ftppathlen=strlen(ftppath);
  10027. int i=1;
  10028. char filenametemp[50];
  10029. while(i < ftppathlen)
  10030. {
  10031. int len=ftppathlen-i;
  10032. if(ftppath[len]== 47) // '/' ascll code: 47
  10033. {
  10034. DEBUG_INFO("find '/' all right\n");
  10035. break;
  10036. }
  10037. i=i+1;
  10038. }
  10039. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10040. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10041. filenametemp[i+1] = 0;
  10042. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10043. if(port == 0)
  10044. port = 21;
  10045. do
  10046. {
  10047. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  10048. sleep(3);
  10049. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10050. if(!isSuccess)
  10051. {
  10052. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  10053. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  10054. sleep(retryIntervalInt);
  10055. }
  10056. else
  10057. {
  10058. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  10059. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  10060. }
  10061. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  10062. }
  10063. end:
  10064. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  10065. pthread_exit(NULL);
  10066. }
  10067. int handleGetLogRequest(char *uuid, char *payload)
  10068. {
  10069. mtrace();
  10070. int result = FAIL;
  10071. char cmdBuf[512];
  10072. char fName[258];
  10073. time_t CurrentTime;
  10074. struct tm *tm;
  10075. pthread_t th_Status;
  10076. system("/usr/bin/run_tmate_restart.sh");
  10077. CurrentTime = time(NULL);
  10078. tm = localtime(&CurrentTime);
  10079. 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);
  10080. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  10081. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  10082. sendGetLogConfirmation(uuid);
  10083. system("exec /root/logPackTools 'log' 6");
  10084. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  10085. system(cmdBuf);
  10086. checkUploadLog();
  10087. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  10088. return result;
  10089. }
  10090. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  10091. {
  10092. mtrace();
  10093. int result = FAIL;
  10094. json_object *GetMonitoringReport;
  10095. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  10096. GetMonitoringReport = json_tokener_parse(payload);
  10097. if(!is_error(GetMonitoringReport))
  10098. {
  10099. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  10100. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  10101. // Required data
  10102. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  10103. {
  10104. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  10105. }
  10106. // Optional data
  10107. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  10108. {
  10109. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  10110. }
  10111. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  10112. {
  10113. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  10114. {
  10115. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  10116. {
  10117. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  10118. {
  10119. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  10120. {
  10121. 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")));
  10122. }
  10123. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  10124. {
  10125. 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")));
  10126. }
  10127. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  10128. {
  10129. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "getVariableData"), idx), "component"), "evse"), "id") != NULL)
  10130. {
  10131. 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"));
  10132. }
  10133. 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)
  10134. {
  10135. 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"));
  10136. }
  10137. }
  10138. }
  10139. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  10140. {
  10141. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  10142. {
  10143. 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")));
  10144. }
  10145. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  10146. {
  10147. 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")));
  10148. }
  10149. }
  10150. }
  10151. }
  10152. }
  10153. }
  10154. json_object_put(GetMonitoringReport);
  10155. /*
  10156. * TODO:
  10157. * 1. Response result
  10158. */
  10159. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  10160. sendGetMonitoringReportConfirmation(uuid);
  10161. return result;
  10162. }
  10163. int handleGetReportRequest(char *uuid, char *payload)
  10164. {
  10165. mtrace();
  10166. int result = FAIL;
  10167. json_object *GetReport;
  10168. DEBUG_INFO("handleGetReportRequest...\n");
  10169. GetReport = json_tokener_parse(payload);
  10170. if(!is_error(GetReport))
  10171. {
  10172. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  10173. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  10174. // Required data
  10175. if(json_object_object_get(GetReport, "requestId") != NULL)
  10176. {
  10177. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  10178. }
  10179. // Optional data
  10180. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  10181. {
  10182. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  10183. }
  10184. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  10185. {
  10186. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  10187. {
  10188. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  10189. {
  10190. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  10191. {
  10192. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  10193. {
  10194. 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")));
  10195. }
  10196. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  10197. {
  10198. 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")));
  10199. }
  10200. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  10201. {
  10202. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "getVariableData"), idx), "component"), "evse"), "id") != NULL)
  10203. {
  10204. 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"), "instance"), "id"));
  10205. }
  10206. 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)
  10207. {
  10208. 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"), "instance"), "connectorId"));
  10209. }
  10210. }
  10211. }
  10212. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  10213. {
  10214. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  10215. {
  10216. 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")));
  10217. }
  10218. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  10219. {
  10220. 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")));
  10221. }
  10222. }
  10223. }
  10224. }
  10225. }
  10226. }
  10227. json_object_put(GetReport);
  10228. /*
  10229. * TODO:
  10230. * 1. Response result
  10231. */
  10232. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  10233. sendGetReportConfirmation(uuid);
  10234. return result;
  10235. }
  10236. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  10237. {
  10238. mtrace();
  10239. int result = FAIL;
  10240. int8_t gun_index = -1;
  10241. json_object *GetTransactionStatus;
  10242. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  10243. GetTransactionStatus = json_tokener_parse(payload);
  10244. if(!is_error(GetTransactionStatus))
  10245. {
  10246. /*
  10247. * TODO:
  10248. * 1. Check transaction locate which connector
  10249. */
  10250. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  10251. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  10252. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  10253. {
  10254. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  10255. }
  10256. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  10257. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  10258. }
  10259. json_object_put(GetTransactionStatus);
  10260. sendGetTransactionStatusConfirmation(uuid, gun_index);
  10261. return result;
  10262. }
  10263. int handleGetVariablesRequest(char *uuid, char *payload)
  10264. {
  10265. mtrace();
  10266. int result = FAIL;
  10267. json_object *GetVariables;
  10268. DEBUG_INFO("handleGetVariablesRequest...\n");
  10269. GetVariables = json_tokener_parse(payload);
  10270. if(!is_error(GetVariables))
  10271. {
  10272. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  10273. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  10274. // Required data
  10275. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  10276. {
  10277. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  10278. {
  10279. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  10280. {
  10281. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  10282. {
  10283. 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")));
  10284. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  10285. }
  10286. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  10287. {
  10288. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  10289. {
  10290. 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")));
  10291. }
  10292. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  10293. {
  10294. 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")));
  10295. }
  10296. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  10297. {
  10298. 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)
  10299. {
  10300. 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"));
  10301. }
  10302. 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)
  10303. {
  10304. 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"));
  10305. }
  10306. }
  10307. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  10308. }
  10309. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  10310. {
  10311. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  10312. {
  10313. 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")));
  10314. }
  10315. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  10316. {
  10317. 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")));
  10318. }
  10319. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  10320. }
  10321. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  10322. {
  10323. if((strstr((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != NULL) &&
  10324. (strlen((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance)>0?(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance) != NULL):TRUE) &&
  10325. (strstr((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) != NULL) &&
  10326. (strlen((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance)>0?(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance) != NULL):TRUE))
  10327. {
  10328. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  10329. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  10330. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  10331. }
  10332. else
  10333. {
  10334. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  10335. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10336. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10337. }
  10338. }
  10339. }
  10340. }
  10341. }
  10342. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  10343. }
  10344. json_object_put(GetVariables);
  10345. return result;
  10346. }
  10347. int handleInstallCertificateRequest(char *uuid, char *payload)
  10348. {
  10349. mtrace();
  10350. int result = FAIL;
  10351. json_object *InstallCertificate;
  10352. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10353. InstallCertificate = json_tokener_parse(payload);
  10354. if(!is_error(InstallCertificate))
  10355. {
  10356. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  10357. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  10358. // Required data
  10359. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  10360. {
  10361. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10362. }
  10363. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  10364. {
  10365. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10366. }
  10367. }
  10368. json_object_put(InstallCertificate);
  10369. /*
  10370. * TODO:
  10371. * 1. Install certification preocess and response
  10372. */
  10373. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  10374. sendInstallCertificateConfirmation(uuid);
  10375. return result;
  10376. }
  10377. int handlePublishFirmwareRequest(char *uuid, char *payload)
  10378. {
  10379. mtrace();
  10380. int result = FAIL;
  10381. json_object *PublishFirmware;
  10382. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  10383. PublishFirmware = json_tokener_parse(payload);
  10384. if(!is_error(PublishFirmware))
  10385. {
  10386. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  10387. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  10388. // Required data
  10389. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  10390. {
  10391. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  10392. }
  10393. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  10394. {
  10395. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  10396. }
  10397. // Optional data
  10398. if(json_object_object_get(PublishFirmware, "location") != NULL)
  10399. {
  10400. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  10401. }
  10402. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  10403. {
  10404. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  10405. }
  10406. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  10407. {
  10408. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  10409. }
  10410. }
  10411. json_object_put(PublishFirmware);
  10412. /*
  10413. * TODO:
  10414. * 1. Publish firmware preocess and response
  10415. */
  10416. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  10417. sendPublishFirmwareConfirmation(uuid);
  10418. return result;
  10419. }
  10420. int handleRemoteStartTransactionRequest(char *uuid, char *payload)
  10421. {
  10422. mtrace();
  10423. int result = FAIL;
  10424. int8_t gun_index = -1;
  10425. uint8_t isPeriodOverMax = FALSE;
  10426. uint8_t isProfileOverMax = FALSE;
  10427. uint8_t isConnectorMismatch = FALSE;
  10428. uint8_t isTxProfile = FALSE;
  10429. uint8_t existProfileQuantity = 0;
  10430. uint8_t filename[128]={0};
  10431. uint8_t word[2048]={0};
  10432. FILE *filePtr;
  10433. json_object *RemoteStartTransaction;
  10434. DEBUG_INFO("handleRemoteStartTransactionRequest...\n");
  10435. RemoteStartTransaction = json_tokener_parse(payload);
  10436. if(!is_error(RemoteStartTransaction))
  10437. {
  10438. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  10439. {
  10440. gun_index = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  10441. }
  10442. else
  10443. {
  10444. /*
  10445. * TODO:
  10446. * 1. Selected connector process
  10447. */
  10448. gun_index = 0;
  10449. }
  10450. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  10451. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  10452. // Required data
  10453. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  10454. {
  10455. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  10456. }
  10457. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  10458. {
  10459. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  10460. {
  10461. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  10462. }
  10463. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  10464. {
  10465. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  10466. }
  10467. }
  10468. // Optional data
  10469. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  10470. {
  10471. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  10472. {
  10473. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  10474. }
  10475. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  10476. {
  10477. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  10478. }
  10479. }
  10480. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10481. {
  10482. // Check periods is over max configuration
  10483. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > 10)
  10484. {
  10485. isPeriodOverMax = TRUE;
  10486. }
  10487. // Check periods is over max configuration
  10488. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  10489. {
  10490. if(gun_index > 0)
  10491. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  10492. else
  10493. isConnectorMismatch = TRUE;
  10494. if(!isConnectorMismatch)
  10495. {
  10496. filePtr = fopen((char*)filename, "r");
  10497. if (!filePtr)
  10498. {
  10499. DEBUG_INFO("%s not exist, create it.\n", filename);
  10500. filePtr = fopen((char*)filename, "w+");
  10501. }
  10502. else
  10503. {
  10504. //Check Charging Profile Count
  10505. while(fscanf(filePtr, "%s", word) != EOF)
  10506. {
  10507. //DEBUG_INFO("word=%s\n",word);
  10508. if(strstr((char*)word, "chargingProfileId")!= NULL)
  10509. {
  10510. existProfileQuantity += 1;
  10511. }
  10512. }
  10513. }
  10514. fclose(filePtr);
  10515. }
  10516. }
  10517. else
  10518. {
  10519. }
  10520. if(existProfileQuantity > 3)
  10521. isProfileOverMax = TRUE;
  10522. }
  10523. // Profile replace or add info
  10524. if((gun_index > 0) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTxProfile)
  10525. {
  10526. FILE *infile;
  10527. FILE *outfile;
  10528. char tmpProfileName[32];
  10529. char rmFileCmd[128];
  10530. char tempchargingProfilePurposeStr[30]={0};
  10531. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10532. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfileRemote");
  10533. infile = fopen ((char*)filename, "r");
  10534. outfile = fopen ((char*)tmpProfileName, "w");
  10535. int d = fgetc(infile);
  10536. rewind(infile);
  10537. if(d == EOF)
  10538. {
  10539. // Profile is empty
  10540. fprintf(outfile,"%s\n", payload);
  10541. fclose(infile);
  10542. fclose(outfile);
  10543. sprintf(rmFileCmd,"rm -f %s",filename);
  10544. system(rmFileCmd);
  10545. rename((char*)tmpProfileName, (char*)filename);
  10546. }
  10547. else
  10548. {
  10549. // Profile is not empty
  10550. char buf[2048]={0};
  10551. int ChargingProfileAdded = FALSE;
  10552. while (fgets(buf, sizeof(buf), infile) != NULL)
  10553. {
  10554. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10555. json_object *tmpChargingProfile;
  10556. tmpChargingProfile = json_tokener_parse(buf);
  10557. if(!is_error(tmpChargingProfile))
  10558. {
  10559. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  10560. {
  10561. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  10562. }
  10563. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10564. {
  10565. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10566. {
  10567. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10568. }
  10569. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10570. {
  10571. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10572. }
  10573. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10574. {
  10575. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10576. }
  10577. }
  10578. }
  10579. json_object_put(tmpChargingProfile);
  10580. if((tempconnectorIdInt == gun_index) &&
  10581. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfileId"))))
  10582. {
  10583. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel"))) &&
  10584. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  10585. {
  10586. if(ChargingProfileAdded == FALSE)
  10587. {
  10588. fprintf(outfile,"%s\n",payload);
  10589. ChargingProfileAdded = TRUE;
  10590. }
  10591. }
  10592. else
  10593. {
  10594. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel")))
  10595. {
  10596. if(ChargingProfileAdded == FALSE)
  10597. {
  10598. fprintf(outfile,"%s\n",buf);
  10599. fprintf(outfile,"%s\n",payload);
  10600. ChargingProfileAdded = TRUE;
  10601. }
  10602. else
  10603. {
  10604. fprintf(outfile,"%s\n",buf);
  10605. }
  10606. }
  10607. else
  10608. {
  10609. if(ChargingProfileAdded == FALSE)
  10610. {
  10611. fprintf(outfile,"%s\n",buf);
  10612. fprintf(outfile,"%s\n",payload);
  10613. ChargingProfileAdded = TRUE;
  10614. }
  10615. else
  10616. {
  10617. fprintf(outfile,"%s\n",buf);
  10618. }
  10619. }
  10620. }
  10621. }
  10622. else
  10623. {
  10624. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfileId")))
  10625. {
  10626. if(ChargingProfileAdded == FALSE)
  10627. {
  10628. fprintf(outfile,"%s\n",buf);
  10629. fprintf(outfile,"%s\n",payload);
  10630. ChargingProfileAdded = TRUE;
  10631. }
  10632. else
  10633. {
  10634. fprintf(outfile,"%s\n",buf);
  10635. }
  10636. }
  10637. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel")))
  10638. {
  10639. if(ChargingProfileAdded == FALSE)
  10640. {
  10641. fprintf(outfile,"%s\n",buf);
  10642. fprintf(outfile,"%s\n",payload);
  10643. ChargingProfileAdded = TRUE;
  10644. }
  10645. else
  10646. {
  10647. fprintf(outfile,"%s\n",buf);
  10648. }
  10649. }
  10650. else
  10651. {
  10652. if(ChargingProfileAdded == FALSE)
  10653. {
  10654. fprintf(outfile,"%s\n",buf);
  10655. fprintf(outfile,"%s\n",payload);
  10656. ChargingProfileAdded = TRUE;
  10657. }
  10658. else
  10659. {
  10660. fprintf(outfile,"%s\n",buf);
  10661. }
  10662. }
  10663. }
  10664. } // end of while loop
  10665. fclose(infile);
  10666. fclose(outfile);
  10667. sprintf(rmFileCmd,"rm -f %s",filename);
  10668. system(rmFileCmd);
  10669. rename((char*)tmpProfileName, (char*)filename);
  10670. }
  10671. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted] );
  10672. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_transactionId);
  10673. result = PASS;
  10674. }
  10675. else
  10676. {
  10677. if(gun_index <= 0)
  10678. DEBUG_WARN("Connector id is wrong.\n");
  10679. if(isConnectorMismatch)
  10680. DEBUG_WARN("Connector id is mismatch.\n");
  10681. if(isPeriodOverMax)
  10682. DEBUG_WARN("Profile periods quantity is over spec.\n");
  10683. if(isProfileOverMax)
  10684. DEBUG_WARN("Profile quantity is over spec.\n");
  10685. if(!isTxProfile)
  10686. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  10687. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  10688. }
  10689. }
  10690. json_object_put(RemoteStartTransaction);
  10691. sendRemoteStartTransactionConfirmation(uuid, gun_index);
  10692. return result;
  10693. }
  10694. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10695. {
  10696. mtrace();
  10697. int result = FAIL;
  10698. int match = FALSE;
  10699. int GunNO = 0;
  10700. int tempIndex = 0;
  10701. char transactionIdStr[37];
  10702. int transactionIdIsNULL= TRUE;
  10703. json_object *RemoteStopTransaction;
  10704. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10705. if(server_pending == TRUE)
  10706. {
  10707. return 0;
  10708. }
  10709. RemoteStopTransaction = json_tokener_parse(payload);
  10710. if(!is_error(RemoteStopTransaction))
  10711. {
  10712. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10713. {
  10714. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  10715. transactionIdIsNULL = FALSE;
  10716. }
  10717. }
  10718. json_object_put(RemoteStopTransaction);
  10719. if(transactionIdIsNULL == FALSE)
  10720. {
  10721. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10722. {
  10723. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  10724. {
  10725. //check Transaction active
  10726. if(gunType[gun_index] == 'J')
  10727. {
  10728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10729. {
  10730. tempIndex = ((gun_index==2) ? 1: 0);
  10731. }
  10732. else
  10733. {
  10734. tempIndex = gun_index;
  10735. }
  10736. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10737. {
  10738. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10739. {
  10740. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10741. {
  10742. match = TRUE;
  10743. GunNO = gun_index;
  10744. }
  10745. }
  10746. }// END FOR CHAdeMO_QUANTITY
  10747. }
  10748. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  10749. {
  10750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10751. {
  10752. tempIndex = ((gun_index==2) ? 1: 0);
  10753. }
  10754. else
  10755. {
  10756. tempIndex = gun_index;
  10757. }
  10758. for (int index = 0; index < CCS_QUANTITY; index++)
  10759. {
  10760. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10761. {
  10762. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10763. {
  10764. match = TRUE;
  10765. GunNO = gun_index;
  10766. }
  10767. }
  10768. }// END FOR CCS_QUANTITY
  10769. }
  10770. else if(gunType[gun_index] == 'G')
  10771. {
  10772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10773. {
  10774. tempIndex = ((gun_index==2) ? 1: 0);
  10775. }
  10776. else
  10777. {
  10778. tempIndex = gun_index;
  10779. }
  10780. for (int index = 0; index < GB_QUANTITY; index++)
  10781. {
  10782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10783. {
  10784. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10785. {
  10786. match = TRUE;
  10787. GunNO = gun_index;
  10788. }
  10789. }
  10790. }// END FOR GB_QUANTITY
  10791. }
  10792. else if(gunType[gun_index] == 'O')
  10793. {
  10794. tempIndex = gun_index;
  10795. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10796. {
  10797. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10798. {
  10799. 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
  10800. {
  10801. match = TRUE;
  10802. GunNO = gun_index;
  10803. }
  10804. }
  10805. }// END FOR GB_QUANTITY
  10806. }
  10807. else
  10808. {
  10809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10810. {
  10811. tempIndex = 2;
  10812. }
  10813. else
  10814. {
  10815. tempIndex = gun_index;
  10816. }
  10817. for (int index = 0; index < AC_QUANTITY; index++)
  10818. {
  10819. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10820. {
  10821. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10822. {
  10823. match = TRUE;
  10824. GunNO = gun_index;
  10825. }
  10826. }
  10827. }// END FOR CHAdeMO_QUANTITY
  10828. } // END FOR AC ELSE
  10829. }// CHECK IF ResponseTransactionId == transactionIdInt
  10830. }//END FOR
  10831. if( match == TRUE)
  10832. {
  10833. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  10834. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  10835. }
  10836. else
  10837. {
  10838. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  10839. }
  10840. }
  10841. else
  10842. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  10843. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  10844. return result;
  10845. }
  10846. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10847. {
  10848. mtrace();
  10849. int result = FAIL;
  10850. int connectorIdInt=0, reservationIdInt=0;
  10851. int tempIndex = 0;
  10852. json_object *ReserveNow;
  10853. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10854. ReserveNow = json_tokener_parse(payload);
  10855. if(!is_error(ReserveNow))
  10856. {
  10857. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  10858. {
  10859. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  10860. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  10861. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  10862. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  10863. }
  10864. // Required data
  10865. if(json_object_object_get(ReserveNow, "reservationId") != NULL)
  10866. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "reservationId"));
  10867. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  10868. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  10869. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  10870. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  10871. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  10872. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  10873. // Optional data
  10874. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  10875. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  10876. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  10877. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  10878. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  10879. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  10880. result = PASS;
  10881. }
  10882. json_object_put(ReserveNow);
  10883. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  10884. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10885. {
  10886. //check Transaction active
  10887. if(gunType[connectorIdInt -1] == 'J')
  10888. {
  10889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10890. {
  10891. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10892. }
  10893. else
  10894. {
  10895. tempIndex = connectorIdInt -1;
  10896. }
  10897. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10898. {
  10899. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10900. {
  10901. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10902. {
  10903. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10904. {
  10905. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10906. {
  10907. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  10908. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  10909. }
  10910. 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'))
  10911. {
  10912. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  10913. }
  10914. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10915. {
  10916. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  10917. }
  10918. else
  10919. {
  10920. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  10921. }
  10922. }
  10923. 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
  10924. {
  10925. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  10926. }
  10927. }
  10928. else
  10929. {
  10930. //replace reservation
  10931. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  10932. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  10933. }
  10934. }
  10935. } // END FOR CHAdeMO_QUANTITY
  10936. }
  10937. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  10938. {
  10939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10940. {
  10941. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10942. }
  10943. else
  10944. {
  10945. tempIndex = connectorIdInt -1;
  10946. }
  10947. for (int index = 0; index < CCS_QUANTITY; index++)
  10948. {
  10949. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10950. {
  10951. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10952. {
  10953. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10954. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10955. {
  10956. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10957. {
  10958. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  10959. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  10960. }
  10961. 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'))
  10962. {
  10963. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  10964. }
  10965. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10966. {
  10967. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  10968. }
  10969. else
  10970. {
  10971. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  10972. }
  10973. }
  10974. 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
  10975. {
  10976. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  10977. }
  10978. }
  10979. else
  10980. {
  10981. //replace reservation
  10982. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  10983. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  10984. }
  10985. }
  10986. } // END FOR CCS_QUANTITY
  10987. }
  10988. else if(gunType[connectorIdInt -1] == 'G')
  10989. {
  10990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10991. {
  10992. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10993. }
  10994. else
  10995. {
  10996. tempIndex = connectorIdInt -1;
  10997. }
  10998. for (int index = 0; index < GB_QUANTITY; index++)
  10999. {
  11000. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11001. {
  11002. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11003. {
  11004. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11005. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11006. {
  11007. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11008. {
  11009. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11010. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11011. }
  11012. 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'))
  11013. {
  11014. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11015. }
  11016. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11017. {
  11018. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11019. }
  11020. else
  11021. {
  11022. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11023. }
  11024. }
  11025. 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
  11026. {
  11027. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11028. }
  11029. }
  11030. else
  11031. {
  11032. //replace reservation
  11033. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11034. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11035. }
  11036. }
  11037. }// END FOR GB_QUANTITY
  11038. }
  11039. else
  11040. {
  11041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11042. {
  11043. tempIndex = 2;
  11044. }
  11045. else
  11046. {
  11047. tempIndex = (connectorIdInt -1);
  11048. }
  11049. for (int index = 0; index < AC_QUANTITY; index++)
  11050. {
  11051. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11052. {
  11053. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11054. {
  11055. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11056. {
  11057. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11058. {
  11059. 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))
  11060. {
  11061. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11062. }
  11063. else
  11064. {
  11065. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11066. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11067. }
  11068. }
  11069. 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'))
  11070. {
  11071. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11072. }
  11073. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11074. {
  11075. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11076. }
  11077. else
  11078. {
  11079. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11080. }
  11081. }
  11082. 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
  11083. {
  11084. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11085. }
  11086. }
  11087. else
  11088. {
  11089. //replace reservation
  11090. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11091. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11092. }
  11093. }
  11094. } // END FOR AC_QUANTITY
  11095. }
  11096. }
  11097. else if(connectorIdInt == 0)
  11098. {
  11099. //check Transaction active
  11100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11101. {
  11102. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11103. {
  11104. 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'))
  11105. {
  11106. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11107. goto end;
  11108. }
  11109. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11110. {
  11111. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11112. goto end;
  11113. }
  11114. 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
  11115. {
  11116. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11117. goto end;
  11118. }
  11119. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11120. {
  11121. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11122. goto end;
  11123. }
  11124. }
  11125. }// END FOR CHAdeMO_QUANTITY
  11126. for (int index = 0; index < CCS_QUANTITY; index++)
  11127. {
  11128. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11129. {
  11130. 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'))
  11131. {
  11132. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11133. goto end;
  11134. }
  11135. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11136. {
  11137. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11138. goto end;
  11139. }
  11140. 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
  11141. {
  11142. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11143. goto end;
  11144. }
  11145. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11146. {
  11147. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11148. goto end;
  11149. }
  11150. }
  11151. } // END FOR CCS_QUANTITY
  11152. for (int index = 0; index < GB_QUANTITY; index++)
  11153. {
  11154. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11155. {
  11156. 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'))
  11157. {
  11158. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11159. goto end;
  11160. }
  11161. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11162. {
  11163. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11164. goto end;
  11165. }
  11166. 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
  11167. {
  11168. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11169. goto end;
  11170. }
  11171. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11172. {
  11173. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11174. goto end;
  11175. }
  11176. }
  11177. } // END FOR GB_QUANTITY
  11178. for (int index = 0; index < AC_QUANTITY; index++)
  11179. {
  11180. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11181. {
  11182. 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'))
  11183. {
  11184. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11185. goto end;
  11186. }
  11187. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11188. {
  11189. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11190. goto end;
  11191. }
  11192. 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
  11193. {
  11194. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11195. goto end;
  11196. }
  11197. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11198. {
  11199. 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))
  11200. {
  11201. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11202. goto end;
  11203. }
  11204. }
  11205. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11206. {
  11207. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11208. goto end;
  11209. }
  11210. }
  11211. }// END FOR AC_QUANTITY
  11212. //The connectorId is 0
  11213. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  11214. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11215. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  11216. result = TRUE;
  11217. return result;
  11218. }
  11219. else
  11220. {
  11221. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11222. }
  11223. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReservationStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  11224. {
  11225. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11226. result = TRUE;
  11227. return result;
  11228. }
  11229. end:
  11230. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  11231. return result;
  11232. }
  11233. int handleResetRequest(char *uuid, char *payload)
  11234. {
  11235. mtrace();
  11236. int result = FAIL;
  11237. json_object *Reset = json_object_new_object();
  11238. DEBUG_INFO("handleResetRequest...\n");
  11239. Reset = json_tokener_parse(payload);
  11240. if(!is_error(Reset))
  11241. {
  11242. // Required data
  11243. if(json_object_object_get(Reset, "type") != NULL)
  11244. {
  11245. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  11246. }
  11247. if(json_object_object_get(Reset, "evseId") != NULL)
  11248. {
  11249. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  11250. }
  11251. }
  11252. json_object_put(Reset);
  11253. if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
  11254. {
  11255. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  11256. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  11257. result = TRUE;
  11258. return result;
  11259. }
  11260. else
  11261. {
  11262. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  11263. goto errorend;
  11264. }
  11265. errorend:
  11266. sendResetConfirmation(uuid);
  11267. return result;
  11268. }
  11269. int handleSendLocalListRequest(char *uuid, char *payload)
  11270. {
  11271. mtrace();
  11272. int result = FAIL;
  11273. char updateTypestr[15]={0};
  11274. int checkState_Faulted = FALSE;
  11275. json_object *SendLocalList;
  11276. DEBUG_INFO("handleSendLocalListRequest...\n");
  11277. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  11278. {
  11279. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  11280. goto end;
  11281. }
  11282. SendLocalList = json_tokener_parse(payload);
  11283. if(!is_error(SendLocalList))
  11284. {
  11285. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  11286. // Required data
  11287. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  11288. {
  11289. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  11290. }
  11291. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  11292. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11293. // Optional data
  11294. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11295. {
  11296. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11297. {
  11298. // Required data
  11299. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  11300. {
  11301. 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")));
  11302. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken"), "type")));
  11303. }
  11304. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11305. {
  11306. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  11307. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  11308. 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")));
  11309. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  11310. 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"));
  11311. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  11312. {
  11313. 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")));
  11314. 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")));
  11315. }
  11316. }
  11317. }
  11318. }
  11319. }
  11320. json_object_put(SendLocalList);
  11321. //check Charge Point state
  11322. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11323. {
  11324. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11325. {
  11326. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11327. }
  11328. }
  11329. for (int index = 0; index < CCS_QUANTITY; index++)
  11330. {
  11331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11332. {
  11333. checkState_Faulted = TRUE; //OCPP Status
  11334. }
  11335. }
  11336. for (int index = 0; index < GB_QUANTITY; index++)
  11337. {
  11338. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11339. {
  11340. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11341. }
  11342. }
  11343. for (int index = 0; index < AC_QUANTITY; index++)
  11344. {
  11345. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11346. {
  11347. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11348. }
  11349. }
  11350. if(checkState_Faulted == TRUE)
  11351. {
  11352. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  11353. goto end;
  11354. }
  11355. // Check update type
  11356. if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  11357. {
  11358. //Local list full update
  11359. DEBUG_INFO("Local list full update.\n");
  11360. DB_getListVerion();
  11361. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  11362. {
  11363. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  11364. goto end;
  11365. }
  11366. DB_cleanLocalList();
  11367. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  11368. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  11369. }
  11370. else if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  11371. {
  11372. //Local list different update
  11373. DEBUG_INFO("Local list different update.\n");
  11374. DB_getListVerion();
  11375. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  11376. {
  11377. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  11378. goto end;
  11379. }
  11380. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  11381. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  11382. }
  11383. else
  11384. {
  11385. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  11386. goto end;
  11387. }
  11388. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  11389. end:
  11390. sendSendLocalListConfirmation(uuid);
  11391. return result;
  11392. }
  11393. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11394. {
  11395. mtrace();
  11396. int result = FAIL;
  11397. int8_t gun_index = -1;
  11398. uint8_t isPeriodOverMax = FALSE;
  11399. uint8_t isProfileOverMax = FALSE;
  11400. uint8_t isConnectorMismatch = FALSE;
  11401. uint8_t existProfileQuantity = 0;
  11402. uint8_t filename[128]={0};
  11403. uint8_t word[2048]={0};
  11404. FILE *filePtr;
  11405. json_object *SetChargingProfile;
  11406. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  11407. SetChargingProfile = json_tokener_parse(payload);
  11408. if(!is_error(SetChargingProfile))
  11409. {
  11410. // Required data
  11411. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  11412. {
  11413. gun_index = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  11414. }
  11415. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  11416. {
  11417. // Check periods is over max configuration
  11418. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > 10)
  11419. {
  11420. isPeriodOverMax = TRUE;
  11421. }
  11422. // Check periods is over max configuration
  11423. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  11424. {
  11425. if(gun_index == 0)
  11426. {
  11427. sprintf((char*)filename, ChargePointMaxProfile_JSON);
  11428. filePtr = fopen((char*)filename, "r");
  11429. if (!filePtr)
  11430. {
  11431. DEBUG_INFO("%s not exist, create it.\n", ChargePointMaxProfile_JSON);
  11432. filePtr = fopen((char*)filename, "w+");
  11433. }
  11434. else
  11435. {
  11436. //Check Charging Profile Count
  11437. while(fscanf(filePtr, "%s", word) != EOF)
  11438. {
  11439. //DEBUG_INFO("word=%s\n",word);
  11440. if(strstr((char*)word, "chargingProfileId")!= NULL)
  11441. {
  11442. existProfileQuantity += 1;
  11443. }
  11444. }
  11445. }
  11446. fclose(filePtr);
  11447. }
  11448. else
  11449. isConnectorMismatch = TRUE;
  11450. }
  11451. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  11452. {
  11453. if(gun_index < 5)
  11454. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", gun_index);
  11455. else
  11456. isConnectorMismatch = TRUE;
  11457. if(!isConnectorMismatch)
  11458. {
  11459. filePtr = fopen((char*)filename, "r");
  11460. if (!filePtr)
  11461. {
  11462. DEBUG_INFO("%s not exist, create it.\n", filename);
  11463. filePtr = fopen((char*)filename, "w+");
  11464. }
  11465. else
  11466. {
  11467. //Check Charging Profile Count
  11468. while(fscanf(filePtr, "%s", word) != EOF)
  11469. {
  11470. //DEBUG_INFO("word=%s\n",word);
  11471. if(strstr((char*)word, "chargingProfileId")!= NULL)
  11472. {
  11473. existProfileQuantity += 1;
  11474. }
  11475. }
  11476. }
  11477. fclose(filePtr);
  11478. }
  11479. }
  11480. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  11481. {
  11482. if(gun_index>0)
  11483. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  11484. else
  11485. isConnectorMismatch = TRUE;
  11486. if(!isConnectorMismatch)
  11487. {
  11488. filePtr = fopen((char*)filename, "r");
  11489. if (!filePtr)
  11490. {
  11491. DEBUG_INFO("%s not exist, create it.\n", filename);
  11492. filePtr = fopen((char*)filename, "w+");
  11493. }
  11494. else
  11495. {
  11496. //Check Charging Profile Count
  11497. while(fscanf(filePtr, "%s", word) != EOF)
  11498. {
  11499. //DEBUG_INFO("word=%s\n",word);
  11500. if(strstr((char*)word, "chargingProfileId")!= NULL)
  11501. {
  11502. existProfileQuantity += 1;
  11503. }
  11504. }
  11505. }
  11506. fclose(filePtr);
  11507. }
  11508. }
  11509. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  11510. {
  11511. }
  11512. else
  11513. {
  11514. }
  11515. if(existProfileQuantity > 3)
  11516. isProfileOverMax = TRUE;
  11517. }
  11518. // Profile replace or add info
  11519. if((gun_index > -1) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch)
  11520. {
  11521. FILE *infile;
  11522. FILE *outfile;
  11523. char tmpProfileName[32];
  11524. char rmFileCmd[128];
  11525. char tempchargingProfilePurposeStr[30]={0};
  11526. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  11527. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfile");
  11528. infile = fopen ((char*)filename, "r");
  11529. outfile = fopen ((char*)tmpProfileName, "w");
  11530. int d = fgetc(infile);
  11531. rewind(infile);
  11532. if(d == EOF)
  11533. {
  11534. // Profile is empty
  11535. fprintf(outfile,"%s\n", payload);
  11536. fclose(infile);
  11537. fclose(outfile);
  11538. sprintf(rmFileCmd,"rm -f %s",filename);
  11539. system(rmFileCmd);
  11540. rename((char*)tmpProfileName, (char*)filename);
  11541. }
  11542. else
  11543. {
  11544. // Profile is not empty
  11545. char buf[2048]={0};
  11546. int ChargingProfileAdded = FALSE;
  11547. while (fgets(buf, sizeof(buf), infile) != NULL)
  11548. {
  11549. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11550. json_object *tmpChargingProfile;
  11551. tmpChargingProfile = json_tokener_parse(buf);
  11552. if(!is_error(tmpChargingProfile))
  11553. {
  11554. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  11555. {
  11556. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  11557. }
  11558. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11559. {
  11560. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11561. {
  11562. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11563. }
  11564. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11565. {
  11566. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11567. }
  11568. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11569. {
  11570. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11571. }
  11572. }
  11573. }
  11574. json_object_put(tmpChargingProfile);
  11575. if((tempconnectorIdInt == gun_index) &&
  11576. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"))))
  11577. {
  11578. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"))) &&
  11579. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  11580. {
  11581. //DEBUG_INFO("update set chargingProfile to file -0\n");
  11582. if(ChargingProfileAdded == FALSE)
  11583. {
  11584. fprintf(outfile,"%s\n",payload);
  11585. ChargingProfileAdded = TRUE;
  11586. }
  11587. }
  11588. else
  11589. {
  11590. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  11591. {
  11592. if(ChargingProfileAdded == FALSE)
  11593. {
  11594. fprintf(outfile,"%s\n",buf);
  11595. fprintf(outfile,"%s\n",payload);
  11596. ChargingProfileAdded = TRUE;
  11597. }
  11598. else
  11599. {
  11600. fprintf(outfile,"%s\n",buf);
  11601. }
  11602. }
  11603. else
  11604. {
  11605. if(ChargingProfileAdded == FALSE)
  11606. {
  11607. fprintf(outfile,"%s\n",buf);
  11608. fprintf(outfile,"%s\n",payload);
  11609. ChargingProfileAdded = TRUE;
  11610. }
  11611. else
  11612. {
  11613. fprintf(outfile,"%s\n",buf);
  11614. }
  11615. }
  11616. }
  11617. }
  11618. else
  11619. {
  11620. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId")))
  11621. {
  11622. if(ChargingProfileAdded == FALSE)
  11623. {
  11624. fprintf(outfile,"%s\n",buf);
  11625. fprintf(outfile,"%s\n",payload);
  11626. ChargingProfileAdded = TRUE;
  11627. }
  11628. else
  11629. {
  11630. fprintf(outfile,"%s\n",buf);
  11631. }
  11632. }
  11633. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  11634. {
  11635. if(ChargingProfileAdded == FALSE)
  11636. {
  11637. fprintf(outfile,"%s\n",buf);
  11638. fprintf(outfile,"%s\n",payload);
  11639. ChargingProfileAdded = TRUE;
  11640. }
  11641. else
  11642. {
  11643. fprintf(outfile,"%s\n",buf);
  11644. }
  11645. }
  11646. else
  11647. {
  11648. if(ChargingProfileAdded == FALSE)
  11649. {
  11650. fprintf(outfile,"%s\n",buf);
  11651. fprintf(outfile,"%s\n",payload);
  11652. ChargingProfileAdded = TRUE;
  11653. }
  11654. else
  11655. {
  11656. fprintf(outfile,"%s\n",buf);
  11657. }
  11658. }
  11659. }
  11660. } // end of while loop
  11661. fclose(infile);
  11662. fclose(outfile);
  11663. sprintf(rmFileCmd,"rm -f %s",filename);
  11664. system(rmFileCmd);
  11665. rename((char*)tmpProfileName, (char*)filename);
  11666. }
  11667. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  11668. result = PASS;
  11669. }
  11670. else
  11671. {
  11672. if(gun_index == -1)
  11673. DEBUG_WARN("Connector id is wrong.\n");
  11674. if(isConnectorMismatch)
  11675. DEBUG_WARN("Connector id is mismatch.\n");
  11676. if(isPeriodOverMax)
  11677. DEBUG_WARN("Profile periods quantity is over spec.\n");
  11678. if(isProfileOverMax)
  11679. DEBUG_WARN("Profile quantity is over spec.\n");
  11680. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  11681. }
  11682. }
  11683. json_object_put(SetChargingProfile);
  11684. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  11685. {
  11686. if(gun_index == 0)
  11687. {
  11688. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11689. {
  11690. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx]);
  11691. }
  11692. }
  11693. else
  11694. checkCompositeSchedule(gun_index, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index-1]);
  11695. }
  11696. sendSetChargingProfileConfirmation(uuid, (gun_index==0?gun_index:gun_index-1));
  11697. return result;
  11698. }
  11699. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  11700. {
  11701. mtrace();
  11702. int result = FAIL;
  11703. json_object *SetDisplayMessage;
  11704. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  11705. SetDisplayMessage = json_tokener_parse(payload);
  11706. if(!is_error(SetDisplayMessage))
  11707. {
  11708. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  11709. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  11710. // Required data
  11711. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  11712. {
  11713. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  11714. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  11715. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  11716. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  11717. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  11718. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  11719. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  11720. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  11721. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  11722. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  11723. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  11724. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  11725. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  11726. {
  11727. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  11728. 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"), "transactionId"), "format")));
  11729. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  11730. 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"), "transactionId"), "language")));
  11731. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  11732. 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"), "transactionId"), "content")));
  11733. }
  11734. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  11735. {
  11736. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  11737. 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")));
  11738. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  11739. 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")));
  11740. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  11741. {
  11742. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  11743. 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"));
  11744. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  11745. 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"));
  11746. }
  11747. }
  11748. }
  11749. }
  11750. json_object_put(SetDisplayMessage);
  11751. /*
  11752. * TODO:
  11753. * 1. Configure display message and response
  11754. */
  11755. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  11756. sendSetMonitoringBaseConfirmation(uuid);
  11757. return result;
  11758. }
  11759. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  11760. {
  11761. mtrace();
  11762. int result = FAIL;
  11763. json_object *SetMonitoringBase;
  11764. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  11765. SetMonitoringBase = json_tokener_parse(payload);
  11766. if(!is_error(SetMonitoringBase))
  11767. {
  11768. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  11769. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  11770. // Required data
  11771. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  11772. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  11773. }
  11774. json_object_put(SetMonitoringBase);
  11775. /*
  11776. * TODO:
  11777. * 1. Configure monitor base and response
  11778. */
  11779. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11780. sendSetMonitoringBaseConfirmation(uuid);
  11781. return result;
  11782. }
  11783. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  11784. {
  11785. mtrace();
  11786. int result = FAIL;
  11787. json_object *SetMonitoringLevel;
  11788. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  11789. SetMonitoringLevel = json_tokener_parse(payload);
  11790. if(!is_error(SetMonitoringLevel))
  11791. {
  11792. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  11793. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  11794. // Required data
  11795. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  11796. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  11797. }
  11798. json_object_put(SetMonitoringLevel);
  11799. /*
  11800. * TODO:
  11801. * Configure monitor status and response
  11802. */
  11803. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  11804. sendSetMonitoringLevelConfirmation(uuid);
  11805. return result;
  11806. }
  11807. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  11808. {
  11809. mtrace();
  11810. int result = FAIL;
  11811. json_object *SetNetworkProfile;
  11812. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  11813. SetNetworkProfile = json_tokener_parse(payload);
  11814. if(!is_error(SetNetworkProfile))
  11815. {
  11816. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  11817. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  11818. // Required data
  11819. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  11820. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  11821. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  11822. {
  11823. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  11824. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  11825. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  11826. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  11827. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  11828. {
  11829. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  11830. memcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  11831. }
  11832. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  11833. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  11834. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  11835. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  11836. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  11837. {
  11838. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  11839. 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")));
  11840. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  11841. 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")));
  11842. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  11843. 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")));
  11844. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  11845. 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")));
  11846. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  11847. 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")));
  11848. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  11849. 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")));
  11850. }
  11851. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  11852. {
  11853. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  11854. {
  11855. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  11856. 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")));
  11857. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  11858. }
  11859. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  11860. {
  11861. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  11862. 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")));
  11863. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  11864. }
  11865. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  11866. {
  11867. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  11868. 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")));
  11869. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  11870. }
  11871. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  11872. 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"));
  11873. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  11874. 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")));
  11875. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  11876. 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"));
  11877. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  11878. 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")));
  11879. }
  11880. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  11881. }
  11882. }
  11883. json_object_put(SetNetworkProfile);
  11884. /*
  11885. * TODO:
  11886. * 1. Process network configuration and response
  11887. */
  11888. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  11889. {
  11890. }
  11891. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  11892. {
  11893. }
  11894. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  11895. {
  11896. }
  11897. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  11898. {
  11899. }
  11900. else
  11901. {
  11902. }
  11903. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  11904. {
  11905. }
  11906. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  11907. {
  11908. }
  11909. else
  11910. {
  11911. }
  11912. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  11913. {
  11914. }
  11915. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  11916. {
  11917. }
  11918. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  11919. {
  11920. }
  11921. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  11922. {
  11923. }
  11924. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  11925. {
  11926. }
  11927. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  11928. {
  11929. }
  11930. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  11931. {
  11932. }
  11933. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  11934. {
  11935. }
  11936. else
  11937. {
  11938. }
  11939. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  11940. {
  11941. }
  11942. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  11943. {
  11944. }
  11945. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  11946. {
  11947. }
  11948. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  11949. {
  11950. }
  11951. else
  11952. {
  11953. }
  11954. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  11955. {
  11956. }
  11957. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  11958. {
  11959. }
  11960. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  11961. {
  11962. }
  11963. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  11964. {
  11965. }
  11966. else
  11967. {
  11968. }
  11969. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  11970. sendSetNetworkProfileConfirmation(uuid);
  11971. return result;
  11972. }
  11973. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  11974. {
  11975. mtrace();
  11976. int result = FAIL;
  11977. json_object *SetVariableMonitoring;
  11978. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  11979. SetVariableMonitoring = json_tokener_parse(payload);
  11980. if(!is_error(SetVariableMonitoring))
  11981. {
  11982. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  11983. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  11984. // Required data
  11985. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  11986. {
  11987. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  11988. {
  11989. 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"));
  11990. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  11991. }
  11992. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  11993. {
  11994. 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"));
  11995. /*
  11996. * TODO:
  11997. * 1. Check monitor value status
  11998. */
  11999. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, MonitorEnumTypeStr[MonitorEnumType_Delta]);
  12000. }
  12001. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  12002. {
  12003. 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")));
  12004. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  12005. }
  12006. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  12007. {
  12008. 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"));
  12009. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  12010. }
  12011. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  12012. {
  12013. 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"));
  12014. }
  12015. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component") != NULL)
  12016. {
  12017. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "name") != NULL)
  12018. {
  12019. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[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, "json_object_array_get_idx"), idx), "component"), "name")));
  12020. }
  12021. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "instance") != NULL)
  12022. {
  12023. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[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, "json_object_array_get_idx"), idx), "component"), "instance")));
  12024. }
  12025. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "evse") != NULL)
  12026. {
  12027. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "evse"), "id") != NULL)
  12028. {
  12029. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[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, "json_object_array_get_idx"), idx), "component"), "instance"), "id"));
  12030. }
  12031. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "evse"), "connectorId") != NULL)
  12032. {
  12033. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[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, "json_object_array_get_idx"), idx), "component"), "instance"), "connectorId"));
  12034. }
  12035. }
  12036. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  12037. }
  12038. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable") != NULL)
  12039. {
  12040. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable"), "name") != NULL)
  12041. {
  12042. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[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, "json_object_array_get_idx"), idx), "variable"), "name")));
  12043. }
  12044. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable"), "instance") != NULL)
  12045. {
  12046. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[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, "json_object_array_get_idx"), idx), "variable"), "instance")));
  12047. }
  12048. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  12049. }
  12050. }
  12051. }
  12052. json_object_put(SetVariableMonitoring);
  12053. return result;
  12054. }
  12055. int handleSetVariablesRequest(char *uuid, char *payload)
  12056. {
  12057. mtrace();
  12058. int result = FAIL;
  12059. json_object *SetVariables;
  12060. DEBUG_INFO("handleSetVariablesRequest...\n");
  12061. SetVariables = json_tokener_parse(payload);
  12062. if(!is_error(SetVariables))
  12063. {
  12064. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  12065. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  12066. // Required data
  12067. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  12068. {
  12069. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  12070. {
  12071. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  12072. {
  12073. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  12074. {
  12075. 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")));
  12076. }
  12077. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  12078. {
  12079. 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")));
  12080. }
  12081. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  12082. {
  12083. 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)
  12084. {
  12085. 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"), "instance"), "id"));
  12086. }
  12087. 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)
  12088. {
  12089. 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"), "instance"), "connectorId"));
  12090. }
  12091. }
  12092. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  12093. }
  12094. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  12095. {
  12096. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  12097. {
  12098. 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")));
  12099. }
  12100. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  12101. {
  12102. 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")));
  12103. }
  12104. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  12105. }
  12106. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  12107. {
  12108. 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")));
  12109. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  12110. }
  12111. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  12112. {
  12113. 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")));
  12114. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  12115. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  12116. {
  12117. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  12118. (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) &&
  12119. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  12120. (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))
  12121. {
  12122. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  12123. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  12124. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  12125. {
  12126. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  12127. }
  12128. else
  12129. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  12130. }
  12131. }
  12132. }
  12133. }
  12134. }
  12135. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  12136. }
  12137. json_object_put(SetVariables);
  12138. return result;
  12139. }
  12140. int handleTriggerMessageRequest(char *uuid, char *payload)
  12141. {
  12142. mtrace();
  12143. int result = FAIL;
  12144. int connectorIdIsNULL = FALSE;
  12145. int connectorIdInt =0;
  12146. char requestedMessagestr[40]={0};
  12147. json_object *TriggerMessage;
  12148. DEBUG_INFO("handleTriggerMessageRequest\n");
  12149. TriggerMessage = json_tokener_parse(payload);
  12150. if(!is_error(TriggerMessage))
  12151. {
  12152. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  12153. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  12154. // Required data
  12155. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  12156. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  12157. // Optional data
  12158. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  12159. {
  12160. // Required data
  12161. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  12162. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  12163. // Optional data
  12164. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  12165. {
  12166. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  12167. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  12168. }
  12169. else
  12170. connectorIdIsNULL = TRUE;
  12171. }
  12172. }
  12173. json_object_put(TriggerMessage);
  12174. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12175. {
  12176. if((strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  12177. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  12178. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  12179. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  12180. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  12181. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  12182. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  12183. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  12184. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  12185. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  12186. (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  12187. {
  12188. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  12189. sendTriggerMessageConfirmation(uuid);
  12190. return TRUE;
  12191. }
  12192. else
  12193. {
  12194. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  12195. sendTriggerMessageConfirmation(uuid);
  12196. }
  12197. }
  12198. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12199. {
  12200. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  12201. sendTriggerMessageConfirmation(uuid);
  12202. return TRUE;
  12203. }
  12204. //==========================
  12205. // Trigger message
  12206. //==========================
  12207. if( strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  12208. {
  12209. if((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) &&
  12210. (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) &&
  12211. (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) &&
  12212. (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing) )
  12213. {
  12214. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  12215. }
  12216. sendFirmwareStatusNotificationRequest(FirmwareStatusEnumTypeStr[FirmwareStatusNotificationStatus]);
  12217. }
  12218. else if(strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  12219. {
  12220. sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[LogStatusNotificationStatus]);
  12221. }
  12222. else if(strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  12223. {
  12224. if(DB_updateBootType(BootReasonEnumType_Triggered))
  12225. server_sign = FALSE;
  12226. }
  12227. else if(strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  12228. {
  12229. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval);
  12230. }
  12231. else if (strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  12232. {
  12233. if(connectorIdIsNULL == FALSE)
  12234. {
  12235. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12236. {
  12237. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12238. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValueReq = ON;
  12239. }
  12240. }
  12241. else
  12242. {
  12243. for(int idx=0;idx< gunTotalNumber;idx++)
  12244. {
  12245. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12246. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  12247. }
  12248. }
  12249. }
  12250. else if(strcmp(requestedMessagestr, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  12251. {
  12252. if(connectorIdIsNULL == FALSE)
  12253. {
  12254. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12255. {
  12256. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = ON;
  12257. }
  12258. }
  12259. else
  12260. {
  12261. for(int idx=0;idx< gunTotalNumber;idx++)
  12262. cpinitateMsg.bits[idx].StatusNotificationReq = ON;
  12263. }
  12264. }
  12265. return result;
  12266. }
  12267. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12268. {
  12269. mtrace();
  12270. int result = FAIL;
  12271. int connectorIdInt =0;
  12272. int tempIndex = 0;
  12273. json_object *UnlockConnector;
  12274. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12275. UnlockConnector = json_tokener_parse(payload);
  12276. if(!is_error(UnlockConnector))
  12277. {
  12278. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12279. {
  12280. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12281. }
  12282. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  12283. {
  12284. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  12285. }
  12286. }
  12287. json_object_put(UnlockConnector);
  12288. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12289. if(gunTotalNumber == 0)
  12290. {
  12291. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  12292. goto end;
  12293. }
  12294. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12295. {
  12296. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  12297. goto end;
  12298. }
  12299. else
  12300. {
  12301. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  12302. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  12303. //check Transaction active
  12304. if(gunType[connectorIdInt-1] == 'J')
  12305. {
  12306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12307. {
  12308. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12309. }
  12310. else
  12311. {
  12312. tempIndex = connectorIdInt -1;
  12313. }
  12314. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12315. {
  12316. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  12317. {
  12318. //stop Transaction
  12319. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  12320. }
  12321. }
  12322. }
  12323. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  12324. {
  12325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12326. {
  12327. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12328. }
  12329. else
  12330. {
  12331. tempIndex = connectorIdInt -1;
  12332. }
  12333. for (int index = 0; index < CCS_QUANTITY; index++)
  12334. {
  12335. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  12336. {
  12337. //stop Transaction
  12338. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  12339. }
  12340. }
  12341. }
  12342. else if(gunType[connectorIdInt-1] == 'G')
  12343. {
  12344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12345. {
  12346. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12347. }
  12348. else
  12349. {
  12350. tempIndex = connectorIdInt -1;
  12351. }
  12352. for (int index = 0; index < GB_QUANTITY; index++)
  12353. {
  12354. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  12355. {
  12356. //stop Transaction
  12357. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  12358. }
  12359. }
  12360. }
  12361. else
  12362. {
  12363. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12364. {
  12365. tempIndex = 2;
  12366. }
  12367. else
  12368. {
  12369. tempIndex = connectorIdInt-1;
  12370. }
  12371. for (int index = 0; index < AC_QUANTITY; index++)
  12372. {
  12373. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  12374. {
  12375. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  12376. }
  12377. }
  12378. }
  12379. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  12380. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12381. result = TRUE;
  12382. return result;
  12383. }
  12384. end:
  12385. //json_object_put(obj); --- remove temporally
  12386. sendUnlockConnectorConfirmation(uuid, connectorIdInt-1);
  12387. return result;
  12388. }
  12389. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  12390. {
  12391. mtrace();
  12392. int result = FAIL;
  12393. json_object *UnpublishFirmware;
  12394. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  12395. UnpublishFirmware = json_tokener_parse(payload);
  12396. if(!is_error(UnpublishFirmware))
  12397. {
  12398. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  12399. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  12400. // Required data
  12401. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  12402. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  12403. }
  12404. json_object_put(UnpublishFirmware);
  12405. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  12406. /*
  12407. * TODO:
  12408. * 1. Check unpublished status
  12409. */
  12410. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  12411. sendUnpublishFirmwareConfirmation(uuid);
  12412. return result;
  12413. }
  12414. static char UpdateFirmwarepayloadData[512]={0};
  12415. void *UpdateFirmwareProcess(void *data)
  12416. {
  12417. pthread_detach(pthread_self());
  12418. mtrace();
  12419. int retriesInt =0, retryIntervalInt=0;
  12420. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12421. int port=0;
  12422. char locationstr[160]={0}, retrieveDatestr[30]={0};
  12423. int isSuccess = 0;
  12424. char ftpbuf[200];
  12425. char temp[100];
  12426. char * pch;
  12427. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12428. json_object *UpdateFirmware;
  12429. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12430. if(!is_error(UpdateFirmware))
  12431. {
  12432. // Required data
  12433. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12434. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12435. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12436. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12437. // Optional data
  12438. if(json_object_object_get(UpdateFirmware, "retries"))
  12439. {
  12440. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12441. }
  12442. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12443. {
  12444. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12445. }
  12446. }
  12447. json_object_put(UpdateFirmware);
  12448. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12449. memset(path, 0, ARRAY_SIZE(path));
  12450. system("rm -f /mnt/*");
  12451. if(strncmp(locationstr,"http", 4) == 0)
  12452. {
  12453. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12454. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  12455. // protocol, user, password, host, path);
  12456. sprintf(ftppath,"/%s", path);
  12457. DEBUG_INFO("locationstr: %s\n", locationstr);
  12458. DEBUG_INFO("protocol: %s\n",protocol);
  12459. DEBUG_INFO("host: %s\n",host);
  12460. DEBUG_INFO("path: %s\n",path);
  12461. DEBUG_INFO("ftppath: %s\n",ftppath);
  12462. int ftppathlen=strlen(ftppath);
  12463. int i=1;
  12464. char filenametemp[50];
  12465. while(i < ftppathlen)
  12466. {
  12467. int len=ftppathlen-i;
  12468. if(ftppath[len]== 47) // '/' ascll code: 47
  12469. {
  12470. DEBUG_INFO("compare '/' all right\n");
  12471. break;
  12472. }
  12473. i=i+1;
  12474. }
  12475. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12476. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12477. filenametemp[i+1] = 0;
  12478. do
  12479. {
  12480. sendFirmwareStatusNotificationRequest(FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  12481. sleep(3);
  12482. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12483. if(!isSuccess)
  12484. {
  12485. sendFirmwareStatusNotificationRequest(FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  12486. sleep(retryIntervalInt);
  12487. }
  12488. else
  12489. {
  12490. sendFirmwareStatusNotificationRequest(FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  12491. }
  12492. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  12493. }
  12494. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12495. {
  12496. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12497. memset(temp, 0, ARRAY_SIZE(temp));
  12498. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12499. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12500. int ftppathlen=strlen(ftpbuf);
  12501. int i=1;
  12502. char filenametemp[50];
  12503. while(i < ftppathlen)
  12504. {
  12505. int len=ftppathlen-i;
  12506. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12507. {
  12508. DEBUG_INFO(" compare '/' all right\n");
  12509. break;
  12510. }
  12511. i=i+1;
  12512. }
  12513. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12514. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12515. filenametemp[i+1] = 0;
  12516. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12517. pch=strchr(temp,'@');
  12518. if(pch==NULL)
  12519. {
  12520. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12521. protocol, host, &port, path);
  12522. strcpy(user,"anonymous");
  12523. strcpy(password,"");
  12524. }
  12525. else
  12526. {
  12527. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12528. protocol, user, password, host, &port, path);
  12529. }
  12530. sscanf(host,"%[^/]%s",host1, path1);
  12531. sprintf(ftppath,"%s", path1);
  12532. //DEBUG_INFO("protocol =%s\n",protocol);
  12533. //DEBUG_INFO("user =%s\n",user);
  12534. //DEBUG_INFO("password =%s\n",password);
  12535. //DEBUG_INFO("host1 =%s\n",host1);
  12536. //DEBUG_INFO("port =%d\n",port);
  12537. //DEBUG_INFO("path1 =%s\n",path1);
  12538. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12539. //ftpFile(host, user, password, port, ftppath, fname);
  12540. //download firmware pthred
  12541. if(port == 0)
  12542. {
  12543. port = 21;
  12544. }
  12545. do
  12546. {
  12547. sendFirmwareStatusNotificationRequest(FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  12548. sleep(3);
  12549. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12550. if(!isSuccess)
  12551. {
  12552. //BulldogUtil.sleepMs(interval*1000);
  12553. DEBUG_INFO("Update firmware request and download file fail.\n");
  12554. sendFirmwareStatusNotificationRequest(FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  12555. sleep(retryIntervalInt);
  12556. }
  12557. else
  12558. {
  12559. sendFirmwareStatusNotificationRequest(FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  12560. }
  12561. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  12562. }
  12563. else
  12564. {
  12565. sendFirmwareStatusNotificationRequest(FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  12566. }
  12567. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  12568. pthread_exit(NULL);
  12569. }
  12570. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12571. {
  12572. mtrace();
  12573. int result = FAIL;
  12574. pthread_t t;
  12575. sendUpdateFirmwareConfirmation(uuid);
  12576. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  12577. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12578. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  12579. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12580. ////pthread_join(t, NULL); //
  12581. //pthread_detach(t);
  12582. //sendUpdateFirmwareConfirmation(uuid);
  12583. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  12584. return result;
  12585. }
  12586. //==========================================
  12587. // Handle server response routine
  12588. //==========================================
  12589. void handleAuthorizeResponse(char *payload, int gun_index)
  12590. {
  12591. mtrace();
  12592. DEBUG_INFO("handleAuthorizeResponse...\n");
  12593. json_object *Authorize;
  12594. Authorize = json_tokener_parse(payload);
  12595. if(!is_error(Authorize))
  12596. {
  12597. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  12598. {
  12599. // Required data
  12600. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  12601. // Optional data
  12602. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "cacheExpiryDateTime") != NULL)
  12603. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  12604. else
  12605. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  12606. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "chargingPriority") != NULL)
  12607. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  12608. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language1") != NULL)
  12609. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  12610. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "evseId") != NULL)
  12611. {
  12612. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTagInfo"), "evseId"));idx++)
  12613. {
  12614. 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));
  12615. }
  12616. }
  12617. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language2") != NULL)
  12618. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  12619. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "groupIdToken") != NULL)
  12620. {
  12621. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  12622. 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")));
  12623. else
  12624. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  12625. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  12626. 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")));
  12627. }
  12628. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "personalMessage") != NULL)
  12629. {
  12630. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  12631. 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")));
  12632. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  12633. 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")));
  12634. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  12635. 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")));
  12636. }
  12637. }
  12638. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  12639. {
  12640. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  12641. }
  12642. }
  12643. json_object_put(Authorize);
  12644. //Update idTag information to authorization cache if supported
  12645. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  12646. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  12647. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&
  12648. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  12649. {
  12650. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  12651. }
  12652. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  12653. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  12654. authorizeRetryTimes = 0;
  12655. }
  12656. void handleBootNotificationResponse(char *payload, int gun_index)
  12657. {
  12658. mtrace();
  12659. char statusStr[12]={0};
  12660. char currentTimeStr[30]={0};
  12661. int intervalInt = 0;
  12662. struct tm tp;
  12663. char buf[28]={0};
  12664. char timebuf[50]={0};
  12665. DEBUG_INFO("handleBootNotificationResponse...\n");
  12666. json_object *BootNotification;
  12667. BootNotification = json_tokener_parse(payload);
  12668. if(!is_error(BootNotification))
  12669. {
  12670. // Required data
  12671. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12672. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12673. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12674. }
  12675. json_object_put(BootNotification);
  12676. DEBUG_INFO("statusStr: %s\n", statusStr);
  12677. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  12678. BootNotificationInterval = intervalInt;
  12679. HeartBeatWaitTime = intervalInt;
  12680. //write back to ShmOCPP20Data->BootNotification
  12681. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  12682. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  12683. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  12684. {
  12685. server_sign = TRUE;
  12686. server_pending =FALSE;
  12687. DB_updateBootType(BootReasonEnumType_PowerUp);
  12688. }
  12689. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  12690. {
  12691. server_pending = TRUE;
  12692. }
  12693. strptime((const char *)ShmOCPP20Data->BootNotification.Response_currentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  12694. tp.tm_isdst = -1;
  12695. //time_t utc = mktime(&tp);
  12696. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  12697. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  12698. sprintf(timebuf,"date -s '%s'",buf);
  12699. system(timebuf);
  12700. srand(time(NULL));
  12701. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  12702. //==============================================
  12703. // RTC sync
  12704. //==============================================
  12705. system("/sbin/hwclock -w --systohc");
  12706. SetOcppConnStatus(TRUE);
  12707. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  12708. }
  12709. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  12710. {
  12711. mtrace();
  12712. json_object *ClearedChargingLimit;
  12713. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  12714. ClearedChargingLimit = json_tokener_parse(payload);
  12715. if(!is_error(ClearedChargingLimit))
  12716. {
  12717. // Required data
  12718. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  12719. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  12720. }
  12721. json_object_put(ClearedChargingLimit);
  12722. ShmOCPP20Data->MsMsg.bits.ClearedChargingLimitReq = OFF;
  12723. ShmOCPP20Data->MsMsg.bits.ClearedChargingLimitConf = ON;
  12724. }
  12725. void handleDataTransferResponse(char *payload, int gun_index)
  12726. {
  12727. mtrace();
  12728. json_object *DataTrans;
  12729. DEBUG_INFO("handleDataTransferResponse...\n");
  12730. DataTrans = json_tokener_parse(payload);
  12731. if(!is_error(DataTrans))
  12732. {
  12733. // Required data
  12734. if(json_object_object_get(DataTrans,"status") != NULL)
  12735. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  12736. // Optional data
  12737. if(json_object_object_get(DataTrans,"data") != NULL)
  12738. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  12739. }
  12740. json_object_put(DataTrans);
  12741. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  12742. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  12743. }
  12744. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12745. {
  12746. mtrace();
  12747. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12748. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  12749. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  12750. }
  12751. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  12752. {
  12753. mtrace();
  12754. json_object *Get15118EVCertificate;
  12755. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  12756. Get15118EVCertificate = json_tokener_parse(payload);
  12757. if(!is_error(Get15118EVCertificate))
  12758. {
  12759. // Required data
  12760. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  12761. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  12762. // Optional data
  12763. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  12764. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  12765. }
  12766. json_object_put(Get15118EVCertificate);
  12767. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  12768. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  12769. }
  12770. void hanldeGetCertificateStatusResponse(char *payload, int gun_index)
  12771. {
  12772. mtrace();
  12773. json_object *GetCertificateStatus;
  12774. DEBUG_INFO("hanldeGetCertificateStatusResponse...\n");
  12775. GetCertificateStatus = json_tokener_parse(payload);
  12776. if(!is_error(GetCertificateStatus))
  12777. {
  12778. // Required data
  12779. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  12780. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  12781. // Optional data
  12782. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  12783. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  12784. }
  12785. json_object_put(GetCertificateStatus);
  12786. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  12787. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  12788. }
  12789. void handleHeartbeatResponse(char *payload, int gun_index)
  12790. {
  12791. mtrace();
  12792. struct tm tp;
  12793. char buf[28]={0};
  12794. char timebuf[128]={0};
  12795. DEBUG_INFO("handleHeartbeatResponse...\n");
  12796. json_object *Heartbeat;
  12797. Heartbeat = json_tokener_parse(payload);
  12798. if(!is_error(Heartbeat))
  12799. {
  12800. // Required data
  12801. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  12802. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12803. }
  12804. json_object_put(Heartbeat);
  12805. if(FirstHeartBeat == OFF)
  12806. {
  12807. FirstHeartBeat = ON;
  12808. DEBUG_INFO("FirstHeartBeat \n");
  12809. }
  12810. HeartBeatWithNOResponse = 0;
  12811. clientTime.Heartbeat=time((time_t*)NULL);
  12812. strptime((const char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  12813. tp.tm_isdst = -1;
  12814. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  12815. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  12816. sprintf(timebuf,"date -s '%s'",buf);
  12817. system(timebuf);
  12818. //==============================================
  12819. // RTC sync
  12820. //==============================================
  12821. system("/sbin/hwclock -w --systohc");
  12822. }
  12823. void hanldeLogStatusNotificationResponse(char *payload, int gun_index)
  12824. {
  12825. mtrace();
  12826. DEBUG_INFO("hanldeLogStatusNotificationResponse...\n");
  12827. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  12828. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  12829. }
  12830. void handleMeterValuesResponse(char *payload, int gun_index)
  12831. {
  12832. mtrace();
  12833. DEBUG_INFO("handleMeterValuesResponse...\n");
  12834. }
  12835. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  12836. {
  12837. mtrace();
  12838. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  12839. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  12840. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  12841. }
  12842. void hanldeNotifyCustomerInformationResponse(char *payload, int gun_index)
  12843. {
  12844. mtrace();
  12845. DEBUG_INFO("hanldeNotifyCustomerInformationResponse...\n");
  12846. }
  12847. void hanldeNotifyDisplayMessagesResponse(char *payload, int gun_index)
  12848. {
  12849. mtrace();
  12850. DEBUG_INFO("hanldeNotifyDisplayMessagesResponse...\n");
  12851. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  12852. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  12853. }
  12854. void hanldeNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  12855. {
  12856. mtrace();
  12857. json_object *NotifyEVChargingNeeds;
  12858. DEBUG_INFO("hanldeNotifyEVChargingNeedsResponse...\n");
  12859. NotifyEVChargingNeeds = json_tokener_parse(payload);
  12860. if(!is_error(NotifyEVChargingNeeds))
  12861. {
  12862. // Required data
  12863. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  12864. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  12865. }
  12866. json_object_put(NotifyEVChargingNeeds);
  12867. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  12868. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  12869. }
  12870. void hanldeNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  12871. {
  12872. mtrace();
  12873. json_object *NotifyEVChargingSchedule;
  12874. DEBUG_INFO("hanldeNotifyEVChargingScheduleResponse...\n");
  12875. NotifyEVChargingSchedule = json_tokener_parse(payload);
  12876. if(!is_error(NotifyEVChargingSchedule))
  12877. {
  12878. // Required data
  12879. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  12880. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  12881. }
  12882. json_object_put(NotifyEVChargingSchedule);
  12883. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleReq = OFF;
  12884. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleConf = ON;
  12885. }
  12886. void hanldeNotifyEventResponse(char *payload, int gun_index)
  12887. {
  12888. mtrace();
  12889. DEBUG_INFO("hanldeNotifyEventResponse...\n");
  12890. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  12891. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  12892. }
  12893. void hanldeNotifyMonitoringReportResponse(char *payload, int gun_index)
  12894. {
  12895. mtrace();
  12896. DEBUG_INFO("hanldeNotifyMonitoringReportResponse...\n");
  12897. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  12898. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  12899. }
  12900. void hanldeNotifyReportResponse(char *payload, int gun_index)
  12901. {
  12902. mtrace();
  12903. DEBUG_INFO("hanldeNotifyReportResponse...\n");
  12904. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  12905. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  12906. }
  12907. void hanldePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12908. {
  12909. mtrace();
  12910. DEBUG_INFO("hanldePublishFirmwareStatusNotificationResponse...\n");
  12911. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  12912. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  12913. }
  12914. void hanldeReportChargingProfilesResponse(char *payload, int gun_index)
  12915. {
  12916. mtrace();
  12917. DEBUG_INFO("hanldeReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  12918. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  12919. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  12920. }
  12921. void hanldeReservationStatusUpdateResponse(char *payload, int gun_index)
  12922. {
  12923. mtrace();
  12924. DEBUG_INFO("hanldeReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  12925. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  12926. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  12927. }
  12928. void hanldeSecurityEventNotificationResponse(char *payload, int gun_index)
  12929. {
  12930. mtrace();
  12931. DEBUG_INFO("hanldeSecurityEventNotificationResponse...\n");
  12932. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  12933. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  12934. }
  12935. void hanldeSignCertificateResponse(char *payload, int gun_index)
  12936. {
  12937. mtrace();
  12938. json_object *SignCertificate;
  12939. DEBUG_INFO("hanldeSignCertificateResponse...\n");
  12940. SignCertificate = json_tokener_parse(payload);
  12941. if(!is_error(SignCertificate))
  12942. {
  12943. // Required data
  12944. if(json_object_object_get(SignCertificate,"status") != NULL)
  12945. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  12946. }
  12947. json_object_put(SignCertificate);
  12948. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  12949. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  12950. }
  12951. void handleStatusNotificationResponse(char *payload, int gun_index)
  12952. {
  12953. mtrace();
  12954. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  12955. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  12956. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  12957. }
  12958. void hanldeTransactionEvenResponse(char *payload, int gun_index)
  12959. {
  12960. mtrace();
  12961. json_object *TransactionEven;
  12962. DEBUG_INFO("hanldeTransactionEvenResponse...\n");
  12963. TransactionEven = json_tokener_parse(payload);
  12964. if(!is_error(TransactionEven))
  12965. {
  12966. // Required data
  12967. // Optional data
  12968. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  12969. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  12970. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  12971. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  12972. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  12973. {
  12974. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  12975. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  12976. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  12977. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  12978. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  12979. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  12980. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  12981. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  12982. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  12983. {
  12984. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  12985. 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")));
  12986. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  12987. 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")));
  12988. }
  12989. }
  12990. }
  12991. json_object_put(TransactionEven);
  12992. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  12993. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  12994. }
  12995. //==========================================
  12996. // Handle Error routine
  12997. //==========================================
  12998. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12999. {
  13000. mtrace();
  13001. #ifdef SystemLogMessage
  13002. DEBUG_INFO("errorCode: %s\n", errorCode);
  13003. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13004. DEBUG_INFO("errorDetails: %s\n", payload);
  13005. #endif
  13006. }
  13007. //===============================================
  13008. // Common routine
  13009. //===============================================
  13010. int initialConfigurationTable(void)
  13011. {
  13012. DEBUG_INFO("initialConfigurationTable...\n");
  13013. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  13014. DB_variableIsCreate();
  13015. DB_variableLoadFromDb();
  13016. DB_getNetworkProfileFromDb();
  13017. return 0;
  13018. }
  13019. int TransactionMessageAttemptsGet(void)
  13020. {
  13021. return TransactionMessageAttemptsValue;
  13022. }
  13023. int FirstHeartBeatResponse(void)
  13024. {
  13025. return FirstHeartBeat;
  13026. }
  13027. int TransactionMessageRetryIntervalGet(void)
  13028. {
  13029. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13030. }
  13031. int ReadHttpStatus(int sock)
  13032. {
  13033. //char c;
  13034. char buff[1024]="",*ptr=buff+1;
  13035. int bytes_received, status;
  13036. DEBUG_INFO("Begin Response ..\n");
  13037. while((bytes_received = recv(sock, ptr, 1, 0))){
  13038. if(bytes_received==-1){
  13039. perror("ReadHttpStatus");
  13040. exit(1);
  13041. }
  13042. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13043. ptr++;
  13044. }
  13045. *ptr=0;
  13046. ptr=buff+1;
  13047. sscanf(ptr,"%*s %d ", &status);
  13048. DEBUG_INFO("%s\n",ptr);
  13049. DEBUG_INFO("status=%d\n",status);
  13050. DEBUG_INFO("End Response ..\n");
  13051. return (bytes_received>0)?status:0;
  13052. }
  13053. //the only filed that it parsed is 'Content-Length'
  13054. int ParseHeader(int sock)
  13055. {
  13056. //char c;
  13057. char buff[1024]="",*ptr=buff+4;
  13058. int bytes_received;
  13059. DEBUG_INFO("Begin HEADER ..\n");
  13060. while((bytes_received = recv(sock, ptr, 1, 0))){
  13061. if(bytes_received==-1){
  13062. perror("Parse Header");
  13063. exit(1);
  13064. }
  13065. if(
  13066. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13067. (ptr[-1]=='\r') && (*ptr=='\n' )
  13068. ) break;
  13069. ptr++;
  13070. }
  13071. *ptr=0;
  13072. ptr=buff+4;
  13073. //printf("%s",ptr);
  13074. if(bytes_received){
  13075. ptr=strstr(ptr,"Content-Length:");
  13076. if(ptr){
  13077. sscanf(ptr,"%*s %d",&bytes_received);
  13078. }else
  13079. bytes_received=-1; //unknown size
  13080. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13081. }
  13082. DEBUG_INFO("End HEADER ..\n");
  13083. return bytes_received ;
  13084. }
  13085. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13086. {
  13087. char rmFileCmd[100]={0};
  13088. char FilePath[100]={0};
  13089. char ftpbuf[200];
  13090. int systemresult;
  13091. //DEBUG_INFO("filename=%s\n",filename);
  13092. //DEBUG_INFO("url=%s\n",url);
  13093. sprintf(FilePath,"/mnt/%s",filename);
  13094. system("ping 8.8.8.8 &");
  13095. if((access(FilePath,F_OK))!=-1)
  13096. {
  13097. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13098. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13099. system(rmFileCmd);
  13100. }
  13101. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13102. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13103. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13104. systemresult = system(ftpbuf);
  13105. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13106. if(systemresult != 0)
  13107. {
  13108. DEBUG_INFO("http DownLoad error!\n");
  13109. return FALSE;
  13110. }
  13111. system("pkill ping");
  13112. return TRUE;
  13113. }
  13114. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13115. {
  13116. char rmFileCmd[100]={0};
  13117. char FilePath[100]={0};
  13118. char ftpbuf[200];
  13119. int systemresult;
  13120. //char temp[100];
  13121. sprintf(FilePath,"/mnt/%s",filename);
  13122. system("ping 8.8.8.8 &");
  13123. if((access(FilePath,F_OK))!=-1)
  13124. {
  13125. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13126. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13127. system(rmFileCmd);
  13128. }
  13129. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13130. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13131. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13132. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13133. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13134. systemresult = system(ftpbuf);
  13135. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13136. if(systemresult != 0)
  13137. {
  13138. printf("wget error!\n");
  13139. return FALSE;
  13140. }
  13141. system("pkill ping");
  13142. return TRUE;
  13143. }
  13144. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13145. {
  13146. char rmFileCmd[100]={0};
  13147. char FilePath[100]={0};
  13148. char ftpbuf[200];
  13149. int systemresult;
  13150. //DEBUG_INFO("filename=%s\n",filename);
  13151. //DEBUG_INFO("url=%s\n",url);
  13152. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13153. if((access(FilePath,F_OK))!=-1)
  13154. {
  13155. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13156. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13157. system(rmFileCmd);
  13158. }
  13159. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13160. if(fp == NULL)
  13161. {
  13162. DEBUG_INFO("log is NULL\n");
  13163. return FALSE;
  13164. }
  13165. else
  13166. {
  13167. fprintf(fp, "%s\n", url);
  13168. fprintf(fp, "%s\n", filename);
  13169. fclose(fp);
  13170. }
  13171. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13172. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13173. systemresult = system(ftpbuf);
  13174. DEBUG_INFO("systemresult = %d\n",systemresult);
  13175. if(systemresult != 0)
  13176. {
  13177. DEBUG_INFO("http upload error!\n");
  13178. return FALSE;
  13179. }
  13180. return TRUE;
  13181. }
  13182. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13183. {
  13184. struct hostent* server;
  13185. char *IPbuffer;
  13186. char ftpbuf[200];
  13187. int systemresult;
  13188. // To retrieve host information
  13189. server = gethostbyname(location);
  13190. // To convert an Internet network
  13191. // address into ASCII string
  13192. IPbuffer = inet_ntoa(*((struct in_addr*)
  13193. server->h_addr_list[0]));
  13194. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13195. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13196. /* format : ftpput -u username -p passwd IP target source*/
  13197. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13198. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13199. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13200. systemresult = system(ftpbuf);
  13201. DEBUG_INFO("systemresult=%d\n",systemresult);
  13202. if(systemresult != 0)
  13203. {
  13204. DEBUG_INFO("ftpput error!\n");
  13205. return FALSE;
  13206. }
  13207. return TRUE;
  13208. }
  13209. //=========================================
  13210. // Routine
  13211. //=========================================
  13212. int GetOcppServerURL()
  13213. {
  13214. int result = FALSE;
  13215. struct yuarel url;
  13216. char urlStr[512];
  13217. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13218. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13219. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13220. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13221. {
  13222. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13223. if(yuarel_parse(&url, urlStr) != -1)
  13224. {
  13225. sprintf(OcppProtocol, "%s", url.scheme);
  13226. sprintf(OcppHost, "%s", url.host);
  13227. if(url.path == NULL)
  13228. OcppTempPath[0] = '\0';
  13229. else
  13230. {
  13231. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13232. {
  13233. sprintf(OcppTempPath, "%s/", url.path);
  13234. }
  13235. else
  13236. {
  13237. sprintf(OcppTempPath, "%s", url.path);
  13238. }
  13239. }
  13240. if(url.port == 0)
  13241. {
  13242. if(strcmp(OcppProtocol, "wss") == 0)
  13243. OcppPort = 443;
  13244. else
  13245. OcppPort = 80;
  13246. }
  13247. else
  13248. OcppPort = url.port;
  13249. result = TRUE;
  13250. }
  13251. }
  13252. else if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  13253. {
  13254. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  13255. if(yuarel_parse(&url, urlStr) != -1)
  13256. {
  13257. sprintf(OcppProtocol, "%s", url.scheme);
  13258. sprintf(OcppHost, "%s", url.host);
  13259. if(url.path == NULL)
  13260. OcppTempPath[0] = '\0';
  13261. else
  13262. sprintf(OcppTempPath, "%s", url.path);
  13263. if(url.port == 0)
  13264. {
  13265. if(strcmp(OcppProtocol, "wss") == 0)
  13266. OcppPort = 443;
  13267. else
  13268. OcppPort = 80;
  13269. }
  13270. else
  13271. OcppPort = url.port;
  13272. result = TRUE;
  13273. }
  13274. }
  13275. else
  13276. {
  13277. strcpy(OcppHost,"");
  13278. }
  13279. return result;
  13280. }
  13281. int GetOcppPath()
  13282. {
  13283. int result = FALSE;
  13284. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13285. {
  13286. if(OcppTempPath == NULL)
  13287. {
  13288. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13289. }
  13290. else
  13291. {
  13292. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13293. }
  13294. result = TRUE;
  13295. }
  13296. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  13297. {
  13298. if(OcppTempPath == NULL)
  13299. {
  13300. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  13301. }
  13302. else
  13303. {
  13304. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  13305. }
  13306. result = TRUE;
  13307. }
  13308. else
  13309. {
  13310. strcpy(OcppPath,"");
  13311. }
  13312. return result;
  13313. }
  13314. int GetOcppPort()
  13315. {
  13316. return OcppPort;
  13317. }
  13318. int GetOcppConnStatus(void)
  13319. {
  13320. return ShmOCPP20Data->OcppConnStatus;
  13321. }
  13322. void SetOcppConnStatus(uint8_t status)
  13323. {
  13324. ShmOCPP20Data->OcppConnStatus = status;
  13325. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13326. }
  13327. int GetHeartBeatWithNOResponse(void)
  13328. {
  13329. return HeartBeatWithNOResponse;
  13330. }
  13331. void SetHeartBeatWithNOResponse(void)
  13332. {
  13333. HeartBeatWithNOResponse = 0;
  13334. }
  13335. void GetStartTransactionIdTag(int gun_index)
  13336. {
  13337. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13338. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken);
  13339. }
  13340. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13341. {
  13342. char ch;
  13343. FILE *fptr1;
  13344. int temptransactionId;
  13345. char str[100]={0};
  13346. temptransactionId = 0;
  13347. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13348. {
  13349. DEBUG_INFO("IdTag is empty.\n");
  13350. return temptransactionId;
  13351. }
  13352. /*------ Read the file ----------------*/
  13353. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13354. if (!fptr1)
  13355. {
  13356. DEBUG_INFO("QueueTransactionId file open error.\n");
  13357. //printf(" File not found or unable to open the input file!!\n");
  13358. return temptransactionId;
  13359. }
  13360. ch=fgetc(fptr1);
  13361. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13362. rewind(fptr1);
  13363. if(ch!=EOF)
  13364. {
  13365. // printf("%c",ch);
  13366. while (fgets(str, 100, fptr1) != NULL)
  13367. {
  13368. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13369. if(str[0]=='\0')
  13370. {
  13371. break;
  13372. }
  13373. char *revbuf[8] = {0}; // Variable store string split
  13374. int num = 0;// Quantity after string split
  13375. DEBUG_INFO("Transaction queue data= %s\n", str);
  13376. splitstring(str,",",revbuf,&num); // String split
  13377. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13378. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13379. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13380. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13381. {
  13382. if(isStopTransaction)
  13383. {
  13384. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13385. {
  13386. temptransactionId = atoi(revbuf[2]);
  13387. break;
  13388. }
  13389. }
  13390. else
  13391. {
  13392. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13393. {
  13394. temptransactionId = atoi(revbuf[2]);
  13395. break;
  13396. }
  13397. }
  13398. }
  13399. }
  13400. }
  13401. else
  13402. DEBUG_INFO("EOF\n");
  13403. fclose(fptr1);
  13404. /*------- End of reading ---------------*/
  13405. return temptransactionId;
  13406. }
  13407. void SetTransactionIdZero(int transactionId)
  13408. {
  13409. char ch;
  13410. FILE *fptr1, *fptr2;
  13411. int temptransactionId = 0;
  13412. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13413. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13414. if (!fptr1)
  13415. {
  13416. //printf(" File not found or unable to open the input file!!\n");
  13417. return ;
  13418. }
  13419. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13420. if (!fptr2)
  13421. {
  13422. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13423. fclose(fptr1);
  13424. return ;
  13425. }
  13426. ch=fgetc(fptr1);
  13427. rewind(fptr1);
  13428. if(ch!=EOF)
  13429. {
  13430. // copy all contents to the temporary file except the specific line
  13431. while (fgets(str, 100, fptr1) != NULL)
  13432. {
  13433. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13434. if(str[0]=='\0')
  13435. {
  13436. break;
  13437. }
  13438. char *revbuf[8] = {0};
  13439. int num = 0;
  13440. strcpy(strtemp, str);
  13441. splitstring(str,",",revbuf,&num);
  13442. if(revbuf[2][0] != '\0')
  13443. {
  13444. temptransactionId = atoi(revbuf[2]);
  13445. if(transactionId != temptransactionId)
  13446. {
  13447. fprintf(fptr2, "%s\n", strtemp);
  13448. }
  13449. }
  13450. }
  13451. }
  13452. fclose(fptr1);
  13453. fclose(fptr2);
  13454. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13455. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13456. /*------ Read the file ----------------*/
  13457. }
  13458. int InternetDisconnect(void)
  13459. {
  13460. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13461. }
  13462. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13463. void storeTempStopTransaction(int gun_index)
  13464. {
  13465. }
  13466. void checkTempStopTransaction(int gun_index)
  13467. {
  13468. FILE *fptr1;
  13469. char ch;
  13470. char str[QUEUE_MESSAGE_LENGTH]={0};
  13471. char guid[37]={0};
  13472. char tempdata[65]={0};
  13473. char connectorStr[2]={0};
  13474. char TempStopTransaction[256];
  13475. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13476. fptr1 = fopen(TempStopTransaction, "r");
  13477. //TempStopTransaction格式: 槍號,StopTransaction封包
  13478. if (!fptr1)
  13479. {
  13480. //printf(" File not found or unable to open the input file!!\n");
  13481. return ;
  13482. }
  13483. ch=fgetc(fptr1);
  13484. //printf(" Now the content of the file %s is : \n",fname);
  13485. rewind(fptr1);
  13486. if(ch!=EOF)
  13487. {
  13488. // copy all contents to the temporary file except the specific line
  13489. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13490. {
  13491. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13492. if(str[0]=='\0')
  13493. {
  13494. break;
  13495. }
  13496. //TempStopTransaction格式: 槍號,StopTransaction封包
  13497. strncpy(connectorStr, str, 1);
  13498. if(atoi(connectorStr) != (gun_index+1))
  13499. {
  13500. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  13501. fclose(fptr1);
  13502. return ;
  13503. }
  13504. //random_uuid(guid);
  13505. strncpy(guid, str+6, 36); //copy guid
  13506. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13507. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13508. {
  13509. //DEBUG_INFO("StopTransaction mapitem pass\n");
  13510. }
  13511. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13512. memset(str,0,ARRAY_SIZE(str));
  13513. }
  13514. }
  13515. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13516. fclose(fptr1);
  13517. remove(TempStopTransaction); // remove the original file
  13518. }
  13519. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13520. {
  13521. ShmOCPP20Data->TransactionEvent[ConnectorId-1].evse.connectorId = ConnectorId;
  13522. ShmOCPP20Data->TransactionEvent[ConnectorId-1].reservationId = ReservationId;
  13523. //ShmOCPP20Data->TransactionEvent[ConnectorId-1].MeterStart = MeterStart;
  13524. strcpy((char *)ShmOCPP20Data->TransactionEvent[ConnectorId-1].idToken.idToken, (char *)IdTag);
  13525. strcpy((char *)ShmOCPP20Data->TransactionEvent[ConnectorId-1].timestamp,(char *) Timestamp);
  13526. }
  13527. int GetWebSocketPingInterval(void)
  13528. {
  13529. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  13530. }
  13531. int GetServerSign(void)
  13532. {
  13533. return server_sign;
  13534. }
  13535. uint8_t GetOcppSecurityProfile()
  13536. {
  13537. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  13538. }
  13539. void GetOcppChargerBoxId(uint8_t *data)
  13540. {
  13541. sprintf((char*)data, "%s", ShmOCPP20Data->ChargeBoxId);
  13542. }
  13543. void GetOcppSecurityPassword(uint8_t *data)
  13544. {
  13545. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  13546. }
  13547. void SetServerSign(int value)
  13548. {
  13549. server_sign = value;
  13550. }
  13551. int GetBootNotificationInterval(void)
  13552. {
  13553. return BootNotificationInterval;
  13554. }
  13555. int GetInternetConn(void)
  13556. {
  13557. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13558. }
  13559. void InitialSystemValue(void)
  13560. {
  13561. int connectorIndex = 0;
  13562. gunTotalNumber=0;
  13563. SystemInitial = 0;
  13564. localversion=0;
  13565. BootNotificationInterval = 10;
  13566. authorizeRetryTimes = 0;
  13567. GunStatusInterval = 10;
  13568. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  13569. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  13570. //Hear Beat
  13571. HeartBeatWithNOResponse = 0;
  13572. HeartBeatCountPerHour = 0;
  13573. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  13574. FirstHeartBeat = 0;
  13575. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  13576. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  13577. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  13578. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  13579. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  13580. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  13581. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  13582. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  13583. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  13584. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  13585. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  13586. memset(gunType, 0, ARRAY_SIZE(gunType));
  13587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13588. {
  13589. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  13590. {
  13591. // DO series
  13592. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  13593. {
  13594. SystemInitial = SystemInitial + 1;
  13595. gunTotalNumber = gunTotalNumber + 1;
  13596. gunType[connectorIndex] = 'O';
  13597. connectorIndex = connectorIndex + 1;
  13598. }
  13599. }
  13600. else
  13601. {
  13602. // DM, DW, DS series
  13603. //check connector / socket type (index: 8, 9, 10)
  13604. for(int index=7; index <10 ; index++)
  13605. {
  13606. if(index != 8)
  13607. {
  13608. // DC Connector
  13609. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13610. {
  13611. SystemInitial = SystemInitial + 1;
  13612. gunTotalNumber = gunTotalNumber + 1;
  13613. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13614. connectorIndex = connectorIndex + 1;
  13615. }
  13616. }
  13617. else
  13618. {
  13619. // AC Connector
  13620. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13621. {
  13622. SystemInitial = SystemInitial + 1;
  13623. gunTotalNumber = gunTotalNumber + 1;
  13624. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13625. connectorIndex = connectorIndex + 1;
  13626. }
  13627. }
  13628. }
  13629. }
  13630. //DEBUG_INFO("DC ...\n");
  13631. }
  13632. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  13633. {
  13634. //check connector / socket type (index: 8, 9, 10)
  13635. for(int index=7; index <10 ; index++)
  13636. {
  13637. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13638. {
  13639. SystemInitial = SystemInitial + 1;
  13640. gunTotalNumber = gunTotalNumber + 1;
  13641. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13642. connectorIndex = connectorIndex + 1;
  13643. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  13644. }
  13645. }
  13646. }
  13647. //Status && ConnectorPlugIn Setting
  13648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13649. {
  13650. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  13651. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  13652. }
  13653. for (int index = 0; index < CCS_QUANTITY; index++)
  13654. {
  13655. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  13656. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  13657. }
  13658. for (int index = 0; index < GB_QUANTITY; index++)
  13659. {
  13660. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  13661. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  13662. }
  13663. for (int index = 0; index < AC_QUANTITY; index++)
  13664. {
  13665. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  13666. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  13667. }
  13668. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13669. {
  13670. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  13671. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  13672. }
  13673. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  13674. {
  13675. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  13676. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  13677. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  13678. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  13679. }
  13680. clientTime.Heartbeat=time((time_t*)NULL);
  13681. sleep(1);
  13682. }
  13683. void LWS_Send(char * str)
  13684. {
  13685. //=====================================================
  13686. // Check InternetConn 0: disconnected, 1: connected
  13687. //====================================================
  13688. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13689. {
  13690. DEBUG_INFO("offline now !!!\n");
  13691. return;
  13692. }
  13693. pthread_mutex_lock(&lock_send);
  13694. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  13695. sprintf((char *)SendBuffer, "%s", str);
  13696. SendBufLen = strlen(str);
  13697. pthread_mutex_unlock(&lock_send);
  13698. lws_callback_on_writable(wsi_client);
  13699. //lws_service(context, 0);
  13700. //sleep(1);
  13701. }
  13702. void LWS_SendNow(char * str)
  13703. {
  13704. //=====================================================
  13705. // Check InternetConn 0: disconnected, 1: connected
  13706. //====================================================
  13707. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13708. {
  13709. DEBUG_INFO("offline now !!!\n");
  13710. return;
  13711. }
  13712. pthread_mutex_lock(&lock_send);
  13713. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  13714. sprintf((char *)SendBuffer, "%s", str);
  13715. SendBufLen = strlen(str);
  13716. pthread_mutex_unlock(&lock_send);
  13717. lws_callback_on_writable(wsi_client);
  13718. lws_service(context, 0);
  13719. //sleep(1);
  13720. }