MessageHandler.c 973 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *CancelReservationStatusEnumTypeStr[] = {
  50. MACROSTR(Accepted),
  51. MACROSTR(Rejected)
  52. };
  53. static char *CertificateActionEnumTypeStr[] = {
  54. MACROSTR(Install),
  55. MACROSTR(Update)
  56. };
  57. static char *CertificateSignedStatusEnumTypeStr[] = {
  58. MACROSTR(Accepted),
  59. MACROSTR(Rejected)
  60. };
  61. static char *CertificateSigningUseEnumTypeStr[] = {
  62. MACROSTR(ChargingStationCertificate),
  63. MACROSTR(V2GCertificate)
  64. };
  65. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  66. MACROSTR(Accepted),
  67. MACROSTR(Rejected),
  68. MACROSTR(Scheduled)
  69. };
  70. #if 0
  71. static char *ChargingLimitSourceEnumTypeStr[] = {
  72. MACROSTR(EMS),
  73. MACROSTR(Other),
  74. MACROSTR(SO),
  75. MACROSTR(CSO)
  76. };
  77. #endif
  78. static char *ChargingProfileKindEnumTypeStr[] = {
  79. MACROSTR(Absolute),
  80. MACROSTR(Recurring),
  81. MACROSTR(Relative)
  82. };
  83. static char *ChargingProfilePurposeEnumTypeStr[] = {
  84. MACROSTR(ChargingStationExternalConstraints),
  85. MACROSTR(ChargingStationMaxProfile),
  86. MACROSTR(TxDefaultProfile),
  87. MACROSTR(TxProfile)
  88. };
  89. static char *ChargingProfileStatusEnumTypeStr[] = {
  90. MACROSTR(Accepted),
  91. MACROSTR(Rejected)
  92. };
  93. static char *ChargingRateUnitEnumTypeStr[] = {
  94. MACROSTR(W),
  95. MACROSTR(A)
  96. };
  97. static char *ChargingStateEnumTypeStr[] = {
  98. MACROSTR(Charging),
  99. MACROSTR(EVConnected),
  100. MACROSTR(SuspendedEV),
  101. MACROSTR(SuspendedEVSE),
  102. MACROSTR(Idle)
  103. };
  104. static char *ClearCacheStatusEnumTypeStr[] = {
  105. MACROSTR(Accepted),
  106. MACROSTR(Rejected)
  107. };
  108. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  109. MACROSTR(Accepted),
  110. MACROSTR(Unknown)
  111. };
  112. static char *ClearMessageStatusEnumTypeStr[] = {
  113. MACROSTR(Accepted),
  114. MACROSTR(Unknown)
  115. };
  116. static char *ClearMonitoringStatusEnumTypeStr[] = {
  117. MACROSTR(Accepted),
  118. MACROSTR(Rejected),
  119. MACROSTR(NotFound)
  120. };
  121. static char *ComponentCriterionEnumTypeStr[] = {
  122. MACROSTR(Active),
  123. MACROSTR(Available),
  124. MACROSTR(Enabled),
  125. MACROSTR(Problem)
  126. };
  127. #if 0
  128. static char *ConnectorEnumTypeStr[] = {
  129. MACROSTR(cCCS1),
  130. MACROSTR(cCCS2),
  131. MACROSTR(cG105),
  132. MACROSTR(cTesla),
  133. MACROSTR(cType1),
  134. MACROSTR(cType2),
  135. MACROSTR(s309-1P-16A),
  136. MACROSTR(s309-1P-32A),
  137. MACROSTR(s309-3P-16A),
  138. MACROSTR(s309-3P-32A),
  139. MACROSTR(sBS1361),
  140. MACROSTR(sCEE-7-7),
  141. MACROSTR(sType2),
  142. MACROSTR(sType3),
  143. MACROSTR(Other1PhMax16A),
  144. MACROSTR(Other1PhOver16A),
  145. MACROSTR(Other3Ph),
  146. MACROSTR(Pan),
  147. MACROSTR(wInductive),
  148. MACROSTR(wResonant),
  149. MACROSTR(Undetermined),
  150. MACROSTR(Unknown)
  151. };
  152. #endif
  153. static char *ConnectorStatusEnumTypeStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Occupied),
  156. MACROSTR(Reserved),
  157. MACROSTR(Unavailable),
  158. MACROSTR(Faulted)
  159. };
  160. #if 0
  161. static char *CostKindEnumTypeStr[] = {
  162. MACROSTR(CarbonDioxideEmission),
  163. MACROSTR(RelativePricePercentage),
  164. MACROSTR(RenewableGenerationPercentage)
  165. };
  166. #endif
  167. static char *CustomerInformationStatusEnumTypeStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Invalid)
  171. };
  172. static char *DataEnumTypeStr[] = {
  173. MACROSTR(string),
  174. MACROSTR(decimal),
  175. MACROSTR(integer),
  176. MACROSTR(dateTime),
  177. MACROSTR(boolean),
  178. MACROSTR(OptionList),
  179. MACROSTR(SequenceList),
  180. MACROSTR(MemberList)
  181. };
  182. static char *DataTransferStatusEnumTypeStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(UnknownMessageId),
  186. MACROSTR(UnknownVendorId)
  187. };
  188. static char *DeleteCertificateStatusEnumTypeStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Failed),
  191. MACROSTR(NotFound)
  192. };
  193. static char *DisplayMessageStatusEnumTypeStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(NotSupportedMessageFormat),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupportedPriority),
  198. MACROSTR(NotSupportedState),
  199. MACROSTR(UnknownTransaction)
  200. };
  201. #if 0
  202. static char *EnergyTransferModeEnumTypeStr[] = {
  203. MACROSTR(DC),
  204. MACROSTR(AC_single_phase),
  205. MACROSTR(AC_two_phase),
  206. MACROSTR(AC_three_phase)
  207. };
  208. #endif
  209. static char *EventNotificationEnumTypeStr[] = {
  210. MACROSTR(HardWiredNotification),
  211. MACROSTR(HardWiredMonitor),
  212. MACROSTR(PreconfiguredMonitor),
  213. MACROSTR(CustomMonitor)
  214. };
  215. static char *EventTriggerEnumTypeStr[] = {
  216. MACROSTR(Alerting),
  217. MACROSTR(Delta),
  218. MACROSTR(Periodic)
  219. };
  220. static char *FirmwareStatusEnumTypeStr[] = {
  221. MACROSTR(Downloaded),
  222. MACROSTR(DownloadFailed),
  223. MACROSTR(Downloading),
  224. MACROSTR(DownloadScheduled),
  225. MACROSTR(DownloadPaused),
  226. MACROSTR(Idle),
  227. MACROSTR(InstallationFailed),
  228. MACROSTR(Installing),
  229. MACROSTR(Installed),
  230. MACROSTR(InstallRebooting),
  231. MACROSTR(InstallScheduled),
  232. MACROSTR(InstallVerificationFailed),
  233. MACROSTR(InvalidSignature),
  234. MACROSTR(SignatureVerified)
  235. };
  236. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected),
  239. MACROSTR(NotSupported),
  240. MACROSTR(EmptyResultSet)
  241. };
  242. static char *GenericStatusEnumTypeStr[] = {
  243. MACROSTR(Accepted),
  244. MACROSTR(Rejected)
  245. };
  246. static char *GetCertificateIdUseEnumTypeStr[] = {
  247. MACROSTR(V2GRootCertificate),
  248. MACROSTR(MORootCertificate),
  249. MACROSTR(CSMSRootCertificate),
  250. MACROSTR(V2GCertificateChain),
  251. MACROSTR(ManufacturerRootCertificate)
  252. };
  253. static char *GetCertificateStatusEnumTypeStr[] = {
  254. MACROSTR(Accepted),
  255. MACROSTR(Failed)
  256. };
  257. static char *GetChargingProfileStatusEnumTypeStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(NoProfiles)
  260. };
  261. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Unknown)
  264. };
  265. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(NotFound)
  268. };
  269. static char *GetVariableStatusEnumTypeStr[] = {
  270. MACROSTR(Accepted),
  271. MACROSTR(Rejected),
  272. MACROSTR(UnknownComponent),
  273. MACROSTR(UnknownVariable),
  274. MACROSTR(NotSupportedAttributeType)
  275. };
  276. static char *HashAlgorithmEnumTypeStr[] = {
  277. MACROSTR(SHA256),
  278. MACROSTR(SHA384),
  279. MACROSTR(SHA512)
  280. };
  281. static char *IdTokenEnumTypeStr[] = {
  282. MACROSTR(Central),
  283. MACROSTR(eMAID),
  284. MACROSTR(ISO14443),
  285. MACROSTR(KeyCode),
  286. MACROSTR(Local),
  287. MACROSTR(NoAuthorization),
  288. MACROSTR(ISO15693)
  289. };
  290. static char *InstallCertificateUseEnumTypeStr[] = {
  291. MACROSTR(V2GRootCertificate),
  292. MACROSTR(MORootCertificate),
  293. MACROSTR(CSMSRootCertificate),
  294. MACROSTR(ManufacturerRootCertificate)
  295. };
  296. static char *InstallCertificateStatusEnumTypeStr[]={
  297. MACROSTR(Accepted),
  298. MACROSTR(Failed),
  299. MACROSTR(Rejected)
  300. };
  301. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  302. MACROSTR(Accepted),
  303. MACROSTR(Failed)
  304. };
  305. static char *LocationEnumTypeStr[] = {
  306. MACROSTR(Body),
  307. MACROSTR(Cable),
  308. MACROSTR(EV),
  309. MACROSTR(Inlet),
  310. MACROSTR(Outlet)
  311. };
  312. static char *LogEnumTypeStr[] = {
  313. MACROSTR(DiagnosticsLog),
  314. MACROSTR(SecurityLog)
  315. };
  316. static char *LogStatusEnumTypeStr[] = {
  317. MACROSTR(Accepted),
  318. MACROSTR(Rejected),
  319. MACROSTR(AcceptedCanceled)
  320. };
  321. static char *MeasurandEnumTypeStr[] = {
  322. MACROSTR(Current.Export),
  323. MACROSTR(Current.Import),
  324. MACROSTR(Current.Offered),
  325. MACROSTR(Energy.Active.Export.Register),
  326. MACROSTR(Energy.Active.Import.Register),
  327. MACROSTR(Energy.Reactive.Export.Register),
  328. MACROSTR(Energy.Reactive.Import.Register),
  329. MACROSTR(Energy.Active.Export.Interval),
  330. MACROSTR(Energy.Active.Import.Interval),
  331. MACROSTR(Energy.Active.Net),
  332. MACROSTR(Energy.Reactive.Export.Interval),
  333. MACROSTR(Energy.Reactive.Import.Interval),
  334. MACROSTR(Energy.Reactive.Net),
  335. MACROSTR(Energy.Apparent.Net),
  336. MACROSTR(Energy.Apparent.Import),
  337. MACROSTR(Energy.Apparent.Export),
  338. MACROSTR(Frequency),
  339. MACROSTR(Power.Active.Export),
  340. MACROSTR(Power.Active.Import),
  341. MACROSTR(Power.Factor),
  342. MACROSTR(Power.Offered),
  343. MACROSTR(Power.Reactive.Export),
  344. MACROSTR(Power.Reactive.Import),
  345. MACROSTR(SoC),
  346. MACROSTR(Voltage)
  347. };
  348. static char *MessageFormatEnumTypeStr[] = {
  349. MACROSTR(ASCII),
  350. MACROSTR(HTML),
  351. MACROSTR(URI),
  352. MACROSTR(UTF8)
  353. };
  354. static char *MessagePriorityEnumTypeStr[] = {
  355. MACROSTR(AlwaysFront),
  356. MACROSTR(InFront),
  357. MACROSTR(NormalCycle)
  358. };
  359. static char *MessageStateEnumTypeStr[] = {
  360. MACROSTR(Charging),
  361. MACROSTR(Faulted),
  362. MACROSTR(Idle),
  363. MACROSTR(Unavailable)
  364. };
  365. static char *MessageTriggerEnumTypeStr[] = {
  366. MACROSTR(BootNotification),
  367. MACROSTR(LogStatusNotification),
  368. MACROSTR(FirmwareStatusNotification),
  369. MACROSTR(Heartbeat),
  370. MACROSTR(MeterValues),
  371. MACROSTR(SignChargingStationCertificate),
  372. MACROSTR(SignV2GCertificate),
  373. MACROSTR(StatusNotification),
  374. MACROSTR(TransactionEvent),
  375. MACROSTR(SignCombinedCertificate),
  376. MACROSTR(PublishFirmwareStatusNotification)
  377. };
  378. static char *MonitorEnumTypeStr[] = {
  379. MACROSTR(UpperThreshold),
  380. MACROSTR(LowerThreshold),
  381. MACROSTR(Delta),
  382. MACROSTR(Periodic),
  383. MACROSTR(PeriodicClockAligned)
  384. };
  385. static char *MonitoringBaseEnumTypeStr[] = {
  386. MACROSTR(All),
  387. MACROSTR(FactoryDefault),
  388. MACROSTR(HardWiredOnly)
  389. };
  390. static char *MonitoringCriterionEnumTypeStr[] = {
  391. MACROSTR(ThresholdMonitoring),
  392. MACROSTR(DeltaMonitoring),
  393. MACROSTR(PeriodicMonitoring)
  394. };
  395. static char *MutabilityEnumTypeStr[] = {
  396. MACROSTR(ReadOnly),
  397. MACROSTR(WriteOnly),
  398. MACROSTR(ReadWrite)
  399. };
  400. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Rejected),
  403. MACROSTR(Processing)
  404. };
  405. static char *OCPPInterfaceEnumTypeStr[] = {
  406. MACROSTR(Wired0),
  407. MACROSTR(Wired1),
  408. MACROSTR(Wired2),
  409. MACROSTR(Wired3),
  410. MACROSTR(Wireless0),
  411. MACROSTR(Wireless1),
  412. MACROSTR(Wireless2),
  413. MACROSTR(Wireless3)
  414. };
  415. static char *OCPPTransportEnumTypeStr[] = {
  416. MACROSTR(JSON),
  417. MACROSTR(SOAP)
  418. };
  419. static char *OCPPVersionEnumTypeStr[] = {
  420. MACROSTR(OCPP12),
  421. MACROSTR(OCPP15),
  422. MACROSTR(OCPP16),
  423. MACROSTR(OCPP20)
  424. };
  425. static char *OperationalStatusEnumTypeStr[] = {
  426. MACROSTR(Inoperative),
  427. MACROSTR(Operative)
  428. };
  429. static char *PhaseEnumTypeStr[] = {
  430. MACROSTR(L1),
  431. MACROSTR(L2),
  432. MACROSTR(L3),
  433. MACROSTR(N),
  434. MACROSTR(L1-N),
  435. MACROSTR(L2-N),
  436. MACROSTR(L3-N),
  437. MACROSTR(L1-L2),
  438. MACROSTR(L2-L3),
  439. MACROSTR(L3-L1)
  440. };
  441. static char *PublishFirmwareStatusEnumTypeStr[] = {
  442. MACROSTR(Downloaded),
  443. MACROSTR(DownloadFailed),
  444. MACROSTR(Downloading),
  445. MACROSTR(DownloadScheduled),
  446. MACROSTR(DownloadPaused),
  447. MACROSTR(PublishFailed),
  448. MACROSTR(Published),
  449. MACROSTR(InvalidChecksum),
  450. MACROSTR(ChecksumVerified)
  451. };
  452. static char *ReadingContextEnumTypeStr[] = {
  453. MACROSTR(Interruption.Begin),
  454. MACROSTR(Interruption.End),
  455. MACROSTR(Other),
  456. MACROSTR(Sample.Clock),
  457. MACROSTR(Sample.Periodic),
  458. MACROSTR(Transaction.Begin),
  459. MACROSTR(Transaction.End),
  460. MACROSTR(Trigger)
  461. };
  462. #if 0
  463. static char *ReasonEnumTypeStr[] = {
  464. MACROSTR(DeAuthorized),
  465. MACROSTR(EmergencyStop),
  466. MACROSTR(EnergyLimitReached),
  467. MACROSTR(EVDisconnected),
  468. MACROSTR(GroundFault),
  469. MACROSTR(ImmediateReset),
  470. MACROSTR(Local),
  471. MACROSTR(LocalOutOfCredit),
  472. MACROSTR(MasterPass),
  473. MACROSTR(Other),
  474. MACROSTR(OvercurrentFault),
  475. MACROSTR(PowerLoss),
  476. MACROSTR(PowerQuality),
  477. MACROSTR(Reboot),
  478. MACROSTR(Remote),
  479. MACROSTR(SOCLimitReached),
  480. MACROSTR(StoppedByEV),
  481. MACROSTR(TimeLimitReached),
  482. MACROSTR(TimeLimitReached)
  483. };
  484. #endif
  485. static char *RecurrencyKindEnumTypeStr[] = {
  486. MACROSTR(Daily),
  487. MACROSTR(Weekly)
  488. };
  489. static char *RegistrationStatusEnumTypeStr[] = {
  490. MACROSTR(Accepted),
  491. MACROSTR(Pending),
  492. MACROSTR(Rejected)
  493. };
  494. static char *ReportBaseEnumTypeStr[] = {
  495. MACROSTR(ConfigurationInventory),
  496. MACROSTR(FullInventory),
  497. MACROSTR(SummaryInventory)
  498. };
  499. static char *RequestStartStopStatusEnumTypeStr[] = {
  500. MACROSTR(Accepted),
  501. MACROSTR(Rejected)
  502. };
  503. static char *ReservationUpdateStatusEnumTypeStr[] = {
  504. MACROSTR(Expired),
  505. MACROSTR(Removed)
  506. };
  507. static char *ReserveNowStatusEnumTypeStr[] = {
  508. MACROSTR(Accepted),
  509. MACROSTR(Faulted),
  510. MACROSTR(Occupied),
  511. MACROSTR(Rejected),
  512. MACROSTR(Unavailable)
  513. };
  514. static char *ResetEnumTypeStr[] = {
  515. MACROSTR(Immediate),
  516. MACROSTR(OnIdle)
  517. };
  518. static char *ResetStatusEnumTypeStr[] = {
  519. MACROSTR(Accepted),
  520. MACROSTR(Rejected),
  521. MACROSTR(Scheduled)
  522. };
  523. static char *SetMonitoringStatusEnumTypeStr[] = {
  524. MACROSTR(Accepted),
  525. MACROSTR(UnknownComponent),
  526. MACROSTR(UnknownVariable),
  527. MACROSTR(UnsupportedMonitorType),
  528. MACROSTR(Rejected),
  529. MACROSTR(OutOfRange),
  530. MACROSTR(Duplicate)
  531. };
  532. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  533. MACROSTR(Accepted),
  534. MACROSTR(Rejected),
  535. MACROSTR(Failed)
  536. };
  537. static char *SetVariableStatusEnumTypeStr[] = {
  538. MACROSTR(Accepted),
  539. MACROSTR(Rejected),
  540. MACROSTR(InvalidValue),
  541. MACROSTR(UnknownComponent),
  542. MACROSTR(UnknownVariable),
  543. MACROSTR(NotSupportedAttributeType),
  544. MACROSTR(OutOfRange),
  545. MACROSTR(RebootRequired)
  546. };
  547. static char *TransactionEventEnumTypeStr[] = {
  548. MACROSTR(Ended),
  549. MACROSTR(Started),
  550. MACROSTR(Updated)
  551. };
  552. static char *TriggerMessageStatusEnumTypeStr[] = {
  553. MACROSTR(Accepted),
  554. MACROSTR(Rejected),
  555. MACROSTR(NotImplemented)
  556. };
  557. static char *TriggerReasonEnumTypeStr[] = {
  558. MACROSTR(Authorized),
  559. MACROSTR(CablePluggedIn),
  560. MACROSTR(ChargingRateChanged),
  561. MACROSTR(ChargingStateChanged),
  562. MACROSTR(Deauthorized),
  563. MACROSTR(EnergyLimitReached),
  564. MACROSTR(EVCommunicationLost),
  565. MACROSTR(EVConnectTimeout),
  566. MACROSTR(MeterValueClock),
  567. MACROSTR(MeterValuePeriodic),
  568. MACROSTR(TimeLimitReached),
  569. MACROSTR(Trigger),
  570. MACROSTR(UnlockCommand),
  571. MACROSTR(StopAuthorized),
  572. MACROSTR(EVDeparted),
  573. MACROSTR(EVDetected),
  574. MACROSTR(RemoteStop),
  575. MACROSTR(RemoteStart),
  576. MACROSTR(AbnormalCondition),
  577. MACROSTR(SignedDataReceived),
  578. MACROSTR(ResetCommand)
  579. };
  580. static char *UnlockStatusEnumTypeStr[] = {
  581. MACROSTR(Unlocked),
  582. MACROSTR(UnlockFailed),
  583. MACROSTR(OngoingAuthorizedTransaction),
  584. MACROSTR(UnknownConnector)
  585. };
  586. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  587. MACROSTR(DownloadOngoing),
  588. MACROSTR(NoFirmware),
  589. MACROSTR(Unpublished)
  590. };
  591. static char *UpdateEnumTypeStr[] = {
  592. MACROSTR(Differential),
  593. MACROSTR(Full)
  594. };
  595. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  596. MACROSTR(Accepted),
  597. MACROSTR(Rejected),
  598. MACROSTR(AcceptedCanceled),
  599. MACROSTR(InvalidCertificate),
  600. MACROSTR(RevokedCertificate)
  601. };
  602. static char *UpdateStatusEnumTypeStr[] = {
  603. MACROSTR(Accepted),
  604. MACROSTR(Failed),
  605. MACROSTR(VersionMismatch)
  606. };
  607. static char *UploadLogStatusEnumTypeStr[] = {
  608. MACROSTR(BadMessage),
  609. MACROSTR(Idle),
  610. MACROSTR(NotSupportedOperation),
  611. MACROSTR(PermissionDenied),
  612. MACROSTR(Uploaded),
  613. MACROSTR(UploadFailure),
  614. MACROSTR(Uploading)
  615. };
  616. static char *VPNEnumTypeStr[] = {
  617. MACROSTR(IKEv2),
  618. MACROSTR(IPSec),
  619. MACROSTR(L2TP),
  620. MACROSTR(PPTP)
  621. };
  622. #if 0
  623. static char *ChargePointErrorCodeEnumTypeStr[] = {
  624. MACROSTR(ConnectorLockFailure),
  625. MACROSTR(EVCommunicationError),
  626. MACROSTR(GroundFailure),
  627. MACROSTR(HighTemperature),
  628. MACROSTR(InternalError),
  629. MACROSTR(LocalListConflict),
  630. MACROSTR(NoError),
  631. MACROSTR(OtherError),
  632. MACROSTR(OverCurrentFailure),
  633. MACROSTR(OverVoltage),
  634. MACROSTR(PowerMeterFailure),
  635. MACROSTR(PowerSwitchFailure),
  636. MACROSTR(ReaderFailure),
  637. MACROSTR(ResetFailure),
  638. MACROSTR(UnderVoltage),
  639. MACROSTR(WeakSignal)
  640. };
  641. #endif
  642. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  643. MACROSTR(Accepted),
  644. MACROSTR(Rejected)
  645. };
  646. static char *RemoteStartStopStatusEnumTypeStr[] = {
  647. MACROSTR(Accepted),
  648. MACROSTR(Rejected)
  649. };
  650. #if 0
  651. static char * StopTransactionReasonEnumTypeStr[] = {
  652. MACROSTR(EmergencyStop),
  653. MACROSTR(EVDisconnected),
  654. MACROSTR(HardReset),
  655. MACROSTR(Local),
  656. MACROSTR(Other),
  657. MACROSTR(PowerLoss),
  658. MACROSTR(Reboot),
  659. MACROSTR(Remote),
  660. MACROSTR(SoftReset),
  661. MACROSTR(UnlockCommand),
  662. MACROSTR(DeAuthorized)
  663. };
  664. #endif
  665. //ChargePointMaxProfile
  666. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile_OCPP20.json"
  667. //TxDefaultProfile
  668. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  669. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  670. struct StatusCodeData *ShmStatusCodeData;
  671. struct PsuData *ShmPsuData ;
  672. struct OCPP20Data *ShmOCPP20Data;
  673. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  674. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  675. //===============================
  676. // Gun Total Numbers
  677. //===============================
  678. static int gunTotalNumber = 0;
  679. static uint8_t gunType[4] = {0};
  680. //===============================
  681. // Local List Version
  682. //===============================
  683. static int localversion=0;
  684. //===============================
  685. // Variable Version
  686. //===============================
  687. static int variableVersion=1;
  688. //===============================
  689. // OCPP sign variable
  690. //===============================
  691. static int server_sign = FALSE;
  692. int server_pending = FALSE;
  693. static int BootNotificationInterval = 10;
  694. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  695. //===============================
  696. // OCPP auth variable
  697. //===============================
  698. static int authorizeRetryTimes = 0; //number of Retry times
  699. //===============================
  700. // OCPP other variables
  701. //===============================
  702. static int HeartBeatWaitTime = 10;
  703. static int FirstHeartBeat = 0;
  704. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  705. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  706. static char CurrentChargingProfileScheduleStr[30] = {0};
  707. //========================================
  708. // OCPP status/previous related variables
  709. //========================================
  710. static int GunStatusInterval = 10;
  711. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  712. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  713. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  714. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  715. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  716. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  717. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  718. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  719. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  720. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  721. static int TransactionMessageAttemptsValue = 0;
  722. static int TransactionMessageRetryIntervalValue = 0;
  723. static struct AuthorizationData idTagQuery;
  724. //=============================================
  725. // OCPP HeartBeat Response Not Receive Counts
  726. //============================================
  727. static int HeartBeatWithNOResponse = 0;
  728. static int HeartBeatCountPerHour = 0;
  729. sqlite3 *db;
  730. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  731. int TransactionMessageAttemptsGet(void);
  732. int TransactionMessageRetryIntervalGet(void);
  733. int GetOcppConnStatus(void);
  734. void SetOcppConnStatus(uint8_t status);
  735. int setKeyValue(char *key, char *value);
  736. void OCPP_get_TableAuthlocalAllData(void);
  737. void processUnkownKey(void);
  738. struct InterLock
  739. {
  740. unsigned char isGetLogGoing:1;
  741. unsigned char isUpdateFirmwareGoing:1;
  742. }interLock;
  743. struct ClientTime
  744. {
  745. unsigned int Heartbeat;
  746. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  747. unsigned int StartTransaction;
  748. unsigned int StopTransaction;
  749. unsigned int MeterValues[CONNECTOR_QUANTITY];
  750. }clientTime;
  751. typedef union
  752. {
  753. //Operations Initiated by Central System
  754. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  755. struct
  756. {
  757. //CsMsgValue[0]
  758. unsigned char StatusNotificationReq:1; //bit 0,
  759. unsigned char StatusNotificationConf:1; //bit 1,
  760. unsigned char TriggerMeterValueReq:1; //bit 2,
  761. unsigned char TransactionEventReq:1; //bit 3,
  762. unsigned char SampleMeterReq:1; //bit 4,
  763. unsigned char ClockAlignMeterReq:1; //bit 5,
  764. unsigned char TriggerStatusNotificationReq:1; //bit 6,
  765. unsigned char isOnCharging:1; //bit7
  766. }bits[CONNECTOR_QUANTITY];
  767. }CpinitiateMsg;
  768. CpinitiateMsg cpinitateMsg;
  769. //=========================================
  770. // Save configuration
  771. //=========================================
  772. int runShellCmd(const char*cmd)
  773. {
  774. int result = FAIL;
  775. char buf[256];
  776. FILE *fp;
  777. fp = popen(cmd, "r");
  778. if(fp != NULL)
  779. {
  780. while(fgets(buf, sizeof(buf), fp) != NULL)
  781. {
  782. DEBUG_INFO("%s\n", buf);
  783. }
  784. result = PASS;
  785. }
  786. pclose(fp);
  787. return result;
  788. }
  789. int StoreUsrConfigData(struct SysConfigData *UsrData)
  790. {
  791. int result = PASS;
  792. int fd,wrd;
  793. unsigned int i,Chk;
  794. unsigned char *ptr, *BufTmp;
  795. int MtdBlockSize = 0x300000;
  796. Chk=0;
  797. ptr=(unsigned char *)UsrData;
  798. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  799. {
  800. memset(BufTmp,0,MtdBlockSize);
  801. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  802. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  803. Chk+=*(BufTmp+i);
  804. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  805. // Output configuration to file.
  806. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  807. if (fd < 0)
  808. {
  809. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  810. free(BufTmp);
  811. return 0;
  812. }
  813. wrd=write(fd, BufTmp, MtdBlockSize);
  814. close(fd);
  815. if(wrd<MtdBlockSize)
  816. {
  817. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  818. free(BufTmp);
  819. return 0;
  820. }
  821. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  822. DEBUG_INFO("Erase /dev/mtd10.\n");
  823. runShellCmd("flash_erase /dev/mtd10 0 0");
  824. DEBUG_INFO("Write /dev/mtd10.\n");
  825. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  826. DEBUG_INFO("Erase /dev/mtd11.\n");
  827. runShellCmd("flash_erase /dev/mtd11 0 0");
  828. DEBUG_INFO("Write /dev/mtd11.\n");
  829. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  830. system("rm -f /mnt/EvseConfig.bin");
  831. DEBUG_INFO("EvseConfig write to flash OK\n");
  832. }
  833. else
  834. {
  835. DEBUG_ERROR("alloc BlockSize NG\r\n");
  836. result = FAIL;
  837. }
  838. if(BufTmp!=NULL)
  839. free(BufTmp);
  840. return result;
  841. }
  842. //=========================================
  843. // Date time related function
  844. //=========================================
  845. void getNowDatetime(uint8_t *data)
  846. {
  847. time_t t = time(NULL);
  848. struct tm tm = *localtime(&t);
  849. 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);
  850. }
  851. //=========================================
  852. // Sqlite3 related function
  853. //=========================================
  854. int DB_Initial()
  855. {
  856. int result = PASS;
  857. char* errMsg = NULL;
  858. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  859. "idToken text UNIQUE,"
  860. "type text,"
  861. "status text,"
  862. "cacheExpiryDateTime text,"
  863. "chargingPriority integer,"
  864. "language1 text,"
  865. "evseId text,"
  866. "language2 text,"
  867. "groupIdToken_idToken text,"
  868. "groupIdToken_type text,"
  869. "personalMessage text);";
  870. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  871. "idToken text UNIQUE,"
  872. "type text,"
  873. "status text,"
  874. "cacheExpiryDateTime text,"
  875. "chargingPriority integer,"
  876. "language1 text,"
  877. "evseId text,"
  878. "language2 text,"
  879. "groupIdToken_idToken text,"
  880. "groupIdToken_type text,"
  881. "personalMessage text,"
  882. "version text);";
  883. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  884. "componentName text NOT NULL ,"
  885. "componentInstance text, "
  886. "variableName text NOT NULL, "
  887. "variableInstance text, "
  888. "variableCharacteristicsDataType integer, "
  889. "variableCharacteristicsUnit text, "
  890. "variableCharacteristicsMaxLimit real,"
  891. "variableAttributesType text, "
  892. "variableAttributesTypeMutability text, "
  893. "variableAttributesTypeValue text, "
  894. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  895. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  896. "type text);";
  897. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  898. "slot integer UNIQUE, connectionData text);";
  899. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  900. "occurDatetime text,"
  901. "message_type text,"
  902. "message_content text)";
  903. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  904. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  905. {
  906. result = FAIL;
  907. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  908. sqlite3_close(db);
  909. }
  910. else
  911. {
  912. DEBUG_INFO( "OCPP local database open successfully.\n");
  913. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  914. {
  915. result = FAIL;
  916. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  917. }
  918. else
  919. {
  920. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  921. }
  922. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  926. }
  927. else
  928. {
  929. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  930. }
  931. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  932. {
  933. result = FAIL;
  934. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  935. }
  936. else
  937. {
  938. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  939. }
  940. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  941. {
  942. result = FAIL;
  943. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  944. }
  945. else
  946. {
  947. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  948. }
  949. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  950. {
  951. result = FAIL;
  952. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  953. }
  954. else
  955. {
  956. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  957. }
  958. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  959. {
  960. result = FAIL;
  961. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  962. }
  963. else
  964. {
  965. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  966. }
  967. //sqlite3_close(db);
  968. }
  969. return result;
  970. }
  971. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  972. {
  973. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  974. return 0;
  975. }
  976. void DB_getListVerion()
  977. {
  978. char sql[256];
  979. char* errMsg = NULL;
  980. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  981. /* Execute SQL statement */
  982. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  983. {
  984. DEBUG_INFO("SQL error: %s", errMsg);
  985. }
  986. }
  987. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  988. {
  989. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  990. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  991. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  992. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  993. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  994. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  995. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  996. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  997. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  998. return 0;
  999. }
  1000. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1001. {
  1002. char sql[256];
  1003. char* errMsg = NULL;
  1004. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1005. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1006. if(isQueryFromCache)
  1007. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1008. else
  1009. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1010. /* Execute SQL statement */
  1011. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1012. {
  1013. DEBUG_INFO("SQL error: %s", errMsg);
  1014. }
  1015. }
  1016. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1017. {
  1018. for (int i = 0; i < columnCount; i++)
  1019. {
  1020. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1021. }
  1022. return 0;
  1023. }
  1024. void DB_get_TableAuthlocalAllData(void)
  1025. {
  1026. char sql[256];
  1027. char* errMsg = NULL;
  1028. sprintf(sql,"select * from ocpp20_auth_local;");
  1029. /* Execute SQL statement */
  1030. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1031. {
  1032. DEBUG_INFO("SQL error: %s", errMsg);
  1033. }
  1034. }
  1035. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1036. {
  1037. for(int i = 0; i<columnCount; i++)
  1038. {
  1039. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1040. }
  1041. return 0;
  1042. }
  1043. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1044. {
  1045. int result = PASS;
  1046. char sql[512];
  1047. char* errMsg = NULL;
  1048. 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;",
  1049. data->idToken.idToken,
  1050. data->idToken.type,
  1051. data->idTokenInfo.status,
  1052. data->idTokenInfo.cacheExpiryDateTime,
  1053. data->idTokenInfo.chargingPriority,
  1054. data->idTokenInfo.language1,
  1055. data->idTokenInfo.language2,
  1056. data->idTokenInfo.groupIdToken.idToken,
  1057. data->idTokenInfo.groupIdToken.type,
  1058. listVersion);
  1059. //* Execute SQL statement */
  1060. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1061. {
  1062. DEBUG_INFO("SQL error: %s\n", errMsg);
  1063. result = FAIL;
  1064. }
  1065. else
  1066. {
  1067. memset(sql, 0, ARRAY_SIZE(sql));
  1068. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1069. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1070. {
  1071. DEBUG_INFO("SQL error: %s\n", errMsg);
  1072. result = FAIL;
  1073. }
  1074. }
  1075. return result;
  1076. }
  1077. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1078. {
  1079. int result = PASS;
  1080. char sql[512];
  1081. char* errMsg = NULL;
  1082. 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;",
  1083. idToken->idToken,
  1084. idToken->type,
  1085. idTokenInfo->status,
  1086. idTokenInfo->cacheExpiryDateTime,
  1087. idTokenInfo->chargingPriority,
  1088. idTokenInfo->language1,
  1089. idTokenInfo->language2,
  1090. idTokenInfo->groupIdToken.idToken,
  1091. idTokenInfo->groupIdToken.type);
  1092. //* Execute SQL statement */
  1093. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1094. {
  1095. DEBUG_INFO("SQL error: %s\n", errMsg);
  1096. result = FAIL;
  1097. }
  1098. return result;
  1099. }
  1100. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1101. {
  1102. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1103. // printf("localversion=%d\n", localversion);
  1104. return 0;
  1105. }
  1106. void DB_deleteIdTag(char idTag[])
  1107. {
  1108. char sql[512];
  1109. char* errMsg = NULL;
  1110. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1111. //* Execute SQL statement */
  1112. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1113. {
  1114. DEBUG_INFO("SQL error: %s", errMsg);
  1115. }
  1116. }
  1117. int DB_cleanLocalList()
  1118. {
  1119. int result = PASS;
  1120. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1121. char *errMsg = 0;
  1122. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1123. {
  1124. DEBUG_INFO("%s\n", errMsg);
  1125. result = FAIL;
  1126. }
  1127. return result;
  1128. }
  1129. int DB_cleanLocalCache()
  1130. {
  1131. int result = PASS;
  1132. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1133. char *errMsg = 0;
  1134. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1135. {
  1136. DEBUG_INFO("%s\n", errMsg);
  1137. result = FAIL;
  1138. }
  1139. return result;
  1140. }
  1141. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1142. {
  1143. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1144. return 0;
  1145. }
  1146. void DB_getBooType()
  1147. {
  1148. char sql[256];
  1149. char* errMsg = NULL;
  1150. sprintf(sql,"select * from ocpp20_boot_type;");
  1151. /* Execute SQL statement */
  1152. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1153. {
  1154. DEBUG_INFO("SQL error: %s\n", errMsg);
  1155. }
  1156. }
  1157. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1158. {
  1159. for(int i = 0; i<columnCount; i++)
  1160. {
  1161. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1162. }
  1163. return 0;
  1164. }
  1165. int DB_updateBootType(BootReasonEnumType reason)
  1166. {
  1167. int result = PASS;
  1168. char sql[512];
  1169. char* errMsg = NULL;
  1170. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1171. //* Execute SQL statement */
  1172. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1173. {
  1174. DEBUG_INFO("SQL error: %s\n", errMsg);
  1175. result = FAIL;
  1176. }
  1177. return result;
  1178. }
  1179. int DB_variableClear()
  1180. {
  1181. int result = PASS;
  1182. char * sqlcleanLocalList = "delete from ocpp20_variable";
  1183. char *errMsg = 0;
  1184. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1185. {
  1186. DEBUG_INFO("%s\n", errMsg);
  1187. result = FAIL;
  1188. }
  1189. return result;
  1190. }
  1191. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1192. {
  1193. for(int i = 0; i<columnCount; i++)
  1194. {
  1195. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1196. }
  1197. return 0;
  1198. }
  1199. int DB_variableSaveToDb(struct ReportDataType *variable)
  1200. {
  1201. int result = FAIL;
  1202. char sql[4096];
  1203. char* errMsg = NULL;
  1204. 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;",
  1205. variable->component.name,
  1206. variable->component.instance,
  1207. variable->variable.name,
  1208. variable->variable.instance,
  1209. variable->variableCharacteristics.dataType,
  1210. variable->variableCharacteristics.unit,
  1211. variable->variableCharacteristics.maxLimit,
  1212. variable->variableAttribute[0].type,
  1213. variable->variableAttribute[0].mutability,
  1214. variable->variableAttribute[0].value);
  1215. //* Execute SQL statement */
  1216. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1217. {
  1218. DEBUG_INFO("SQL error: %s\n", errMsg);
  1219. result = FAIL;
  1220. }
  1221. return result;
  1222. }
  1223. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1224. {
  1225. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1226. if(atoi(columnValue[0]) == 0)
  1227. {
  1228. DB_updateBootType(BootReasonEnumType_PowerUp);
  1229. // Create variable table content
  1230. /* AlignedDataCtrlr Required item */
  1231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1237. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1244. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1248. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1251. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered");
  1253. else
  1254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered");
  1255. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1260. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 10;
  1261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1264. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "TRUE");
  1271. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1278. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1282. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC");
  1287. else
  1288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1289. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1297. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1298. /* AuthCtrlrVariable Required item */
  1299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1305. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  1307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1312. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "FALSE");
  1319. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "FALSE");
  1326. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE");
  1333. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE");
  1340. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1344. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1348. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1349. /* AuthCacheCtrlr Variable Required item*/
  1350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1356. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "TRUE");
  1363. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "TRUE");
  1371. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1375. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "TRUE");
  1379. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1386. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1387. /* ClockCtrlr Variable Required item */
  1388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1393. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1394. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1401. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1409. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1416. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1423. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1431. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1438. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1445. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1446. /* ChargingStation Required item */
  1447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "FALSE");
  1453. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1460. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1467. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1468. /* Connector Required item */
  1469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "FALSE");
  1475. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1482. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1489. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1490. /* CustomizationCtrlr Required item */
  1491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "FALSE");
  1497. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1498. /* DeviceDataCtrlr Required item */
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1506. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1514. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1522. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1530. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1533. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1538. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1541. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1546. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1554. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1562. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1563. /* DisplayMessageCtrlr Required item */
  1564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1570. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "FALSE");
  1577. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1581. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1585. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1592. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1599. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1600. /* EVSE Required item */
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "FALSE");
  1607. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1614. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1621. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1628. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1629. /* LocalAuthListCtrlr Required item */
  1630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1636. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1640. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1644. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "TRUE");
  1651. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  1659. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  1667. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1671. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  1675. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1676. /* MonitoringCtrlr Required item */
  1677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1683. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "FALSE");
  1690. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1698. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1706. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1708. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1714. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1722. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1724. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1729. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1730. /* OCPPCommCtrlr Required item */
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1737. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1746. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1753. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1761. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1768. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1775. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1783. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "FALSE");
  1790. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1799. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "3");
  1808. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  1815. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1823. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1830. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1837. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  1844. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  1845. /* ReservationCtrlr Required item */
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1852. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "TRUE");
  1859. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "FALSE");
  1866. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  1867. /* SampledDataCtrlr Required item */
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1874. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1881. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1888. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1892. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC");
  1897. else
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1899. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1907. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1911. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  1915. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1919. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 0;
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered");
  1924. else
  1925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered");
  1926. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1931. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 10;
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  1935. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  1936. /* SecurityCtrlr Required item */
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1940. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  1944. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1948. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  1952. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  1955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1959. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  1962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1963. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  1967. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  1974. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "FALSE");
  1981. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1985. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  1989. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  1990. /* SmartChargingCtrlr Required item */
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1997. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "TRUE");
  2004. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "FALSE");
  2011. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "0");
  2018. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2025. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2032. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "FALSE");
  2039. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "FALSE");
  2046. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "FALSE");
  2053. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2057. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2061. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2068. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2069. /* TariffCostCtrlr Required item */
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "FALSE");
  2077. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "FALSE");
  2085. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2089. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2093. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "FALSE");
  2101. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "FALSE");
  2109. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2113. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2117. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2121. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2125. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2126. /* TxCtrlr Required item */
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2133. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2141. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  2148. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2155. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2162. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2169. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2177. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "FALSE");
  2184. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2185. }
  2186. else
  2187. {
  2188. // Variable name init
  2189. /* AlignedDataCtrlr Required item */
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2206. /* AuthCtrlrVariable Required item */
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2221. /* AuthCacheCtrlr Variable Required item */
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2232. /* ClockCtrlr Variable Required item */
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2251. /* ChargingStation Required item */
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2258. /* Connector Required item */
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2265. /* CustomizationCtrlr Required item */
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2268. /* DeviceDataCtrlr Required item */
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2291. /* DisplayMessageCtrlr Required item */
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2302. /* EVSE Required item */
  2303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2311. /* LocalAuthListCtrlr Required item */
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2326. /* MonitoringCtrlr Required item */
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2345. /* OCPPCommCtrlr Required item */
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2379. /* ReservationCtrlr Required item */
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2386. /* SampledDataCtrlr Required item */
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2403. /* SecurityCtrlr Required item */
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2418. /* SmartChargingCtrlr Required item */
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2441. /* TariffCostCtrlr Required item */
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2460. /* TxCtrlr Required item */
  2461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2477. }
  2478. return 0;
  2479. }
  2480. void DB_variableIsCreate()
  2481. {
  2482. char sql[512];
  2483. char* errMsg = NULL;
  2484. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2485. /* Execute SQL statement */
  2486. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2487. {
  2488. DEBUG_INFO("SQL error: %s\n", errMsg);
  2489. }
  2490. }
  2491. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2492. {
  2493. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2494. {
  2495. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2496. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2497. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2498. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2499. {
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2502. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2506. }
  2507. }
  2508. return 0;
  2509. }
  2510. void DB_variableLoadFromDb()
  2511. {
  2512. char sql[512];
  2513. char* errMsg = NULL;
  2514. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2515. /* Execute SQL statement */
  2516. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2517. {
  2518. DEBUG_INFO("SQL error: %s\n", errMsg);
  2519. }
  2520. }
  2521. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2522. {
  2523. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2524. if(columnCount > 0)
  2525. {
  2526. for(int idx=0;idx<columnCount;idx++)
  2527. {
  2528. json_object *SetNetworkProfile;
  2529. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2530. if(!is_error(SetNetworkProfile))
  2531. {
  2532. // Required data
  2533. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2534. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2535. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2536. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2537. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2538. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2539. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2540. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2541. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2542. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2543. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2544. {
  2545. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2546. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2547. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2548. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2549. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2550. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2551. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2552. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2553. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2554. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2555. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2556. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2557. }
  2558. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2559. {
  2560. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2561. {
  2562. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2563. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2564. }
  2565. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2566. {
  2567. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2568. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2569. }
  2570. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2571. {
  2572. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2573. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2574. }
  2575. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2576. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2577. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2578. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2579. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2580. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2581. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2582. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2583. }
  2584. }
  2585. json_object_put(SetNetworkProfile);
  2586. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2587. }
  2588. }
  2589. return 0;
  2590. }
  2591. void DB_getNetworkProfileFromDb()
  2592. {
  2593. char sql[512];
  2594. char* errMsg = NULL;
  2595. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2596. /* Execute SQL statement */
  2597. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2598. {
  2599. DEBUG_INFO("SQL error: %s\n", errMsg);
  2600. }
  2601. }
  2602. int DB_addNetworkProfile(int slot, char *data)
  2603. {
  2604. int result = PASS;
  2605. char sql[512];
  2606. char* errMsg = NULL;
  2607. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2608. slot,
  2609. data);
  2610. //* Execute SQL statement */
  2611. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2612. {
  2613. DEBUG_INFO("SQL error: %s\n", errMsg);
  2614. result = FAIL;
  2615. }
  2616. return result;
  2617. }
  2618. int DB_deleteNetworkProfile(int slot)
  2619. {
  2620. int result = PASS;
  2621. char sql[512];
  2622. char* errMsg = NULL;
  2623. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2624. //* Execute SQL statement */
  2625. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2626. {
  2627. DEBUG_INFO("SQL error: %s", errMsg);
  2628. result = FAIL;
  2629. }
  2630. return result;
  2631. }
  2632. int getCurrentYear()
  2633. {
  2634. int result = 0;
  2635. time_t CurrentTime;
  2636. struct tm *tm;
  2637. CurrentTime = time(NULL);
  2638. tm=localtime(&CurrentTime);
  2639. result = (tm->tm_year + 1900);
  2640. return result;
  2641. }
  2642. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2643. {
  2644. int result = PASS;
  2645. char* errMsg = NULL;
  2646. char sqlStr[8192];
  2647. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2648. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2649. {
  2650. result = FAIL;
  2651. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  2652. }
  2653. sprintf(sqlStr, "delete from ocpp20_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  2654. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2655. {
  2656. result = FAIL;
  2657. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  2658. }
  2659. return result;
  2660. }
  2661. //==========================================
  2662. // Check time passed since today
  2663. //==========================================
  2664. long long DiffTimebWithNow(struct timeb ST)
  2665. {
  2666. //return milli-second
  2667. struct timeb ET;
  2668. long long StartTime,StopTime;
  2669. ftime(&ET);
  2670. StartTime=(long long)ST.time;
  2671. StopTime=(long long)ET.time;
  2672. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2673. }
  2674. int getTimePassSinceToday(uint8_t gun_index)
  2675. {
  2676. int result = -1;
  2677. static time_t lastTime[4];
  2678. time_t t;
  2679. struct tm *tmStartToday;
  2680. struct timeb tbStartToday;
  2681. t=time(NULL);
  2682. if(difftime(t, lastTime[gun_index])>0)
  2683. {
  2684. tmStartToday=localtime(&t);
  2685. tmStartToday->tm_hour = 0;
  2686. tmStartToday->tm_min = 0;
  2687. tmStartToday->tm_sec = 0;
  2688. tbStartToday.time = mktime(tmStartToday);
  2689. tbStartToday.millitm = 0;
  2690. result = DiffTimebWithNow(tbStartToday)/1000;
  2691. lastTime[gun_index] = t;
  2692. }
  2693. return result;
  2694. }
  2695. int syncDateTimeRTC(uint8_t *data)
  2696. {
  2697. struct ParsingResult
  2698. {
  2699. int result;
  2700. int scanedElement;
  2701. int year;
  2702. int month;
  2703. int mday;
  2704. int hour;
  2705. int min;
  2706. int sec;
  2707. int tz_hour;
  2708. int tz_min;
  2709. float minSec;
  2710. }result;
  2711. struct tm tmOrg;
  2712. struct tm *tmTarget;
  2713. struct timeb tbTarget;
  2714. char buf[128];
  2715. memset(&result, 0x00, sizeof(struct ParsingResult));
  2716. result.result = PASS;
  2717. if(strstr((char*)data, ".") != NULL)
  2718. {
  2719. // Original data with mini second
  2720. if(strstr((char*)data, "Z") != NULL)
  2721. {
  2722. // Original data with Z
  2723. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  2724. &result.year,
  2725. &result.month,
  2726. &result.mday,
  2727. &result.hour,
  2728. &result.min,
  2729. &result.sec,
  2730. &result.minSec);
  2731. }
  2732. else
  2733. {
  2734. // Original data without Z
  2735. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2736. &result.year,
  2737. &result.month,
  2738. &result.mday,
  2739. &result.hour,
  2740. &result.min,
  2741. &result.sec,
  2742. &result.minSec,
  2743. &result.tz_hour,
  2744. &result.tz_min);
  2745. }
  2746. }
  2747. else
  2748. {
  2749. // Original data without mini second
  2750. if(strstr((char*)data, "Z") != NULL)
  2751. {
  2752. // Original data with Z
  2753. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  2754. &result.year,
  2755. &result.month,
  2756. &result.mday,
  2757. &result.hour,
  2758. &result.min,
  2759. &result.sec);
  2760. }
  2761. else
  2762. {
  2763. // Original data without Z
  2764. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  2765. &result.year,
  2766. &result.month,
  2767. &result.mday,
  2768. &result.hour,
  2769. &result.min,
  2770. &result.sec,
  2771. &result.tz_hour,
  2772. &result.tz_min);
  2773. }
  2774. }
  2775. tmOrg.tm_year = result.year - 1900;
  2776. tmOrg.tm_mon = result.month - 1;
  2777. tmOrg.tm_mday = result.mday;
  2778. tmOrg.tm_hour = result.hour;
  2779. tmOrg.tm_min = result.min;
  2780. tmOrg.tm_sec = result.sec;
  2781. tmOrg.tm_gmtoff = 0;
  2782. tbTarget.time = mktime(&tmOrg);
  2783. tbTarget.timezone = 0;
  2784. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  2785. tmTarget = gmtime(&tbTarget.time);
  2786. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  2787. //DEBUG_INFO(" org date time: %s\n", data);
  2788. //DEBUG_INFO("parse date time: %s\n", buf);
  2789. system(buf);
  2790. system("/sbin/hwclock -w --systohc");
  2791. if(result.scanedElement < 6)
  2792. result.result = FAIL;
  2793. return result.result;
  2794. }
  2795. //==========================================
  2796. // GetCompositeSchedule logic related function
  2797. //==========================================
  2798. int DiffTimebSec(struct timeb ST, struct timeb ET)
  2799. {
  2800. //return milli-second
  2801. unsigned int StartTime,StopTime;
  2802. StartTime=(unsigned int)ST.time;
  2803. StopTime=(unsigned int)ET.time;
  2804. return (StopTime-StartTime);
  2805. }
  2806. int DiffTimebWithNowSec(struct timeb ST)
  2807. {
  2808. //return milli-second
  2809. struct timeb ET;
  2810. unsigned int StartTime,StopTime;
  2811. ftime(&ET);
  2812. StartTime=(unsigned int)ST.time;
  2813. StopTime=(unsigned int)ET.time;
  2814. return (StopTime-StartTime);
  2815. }
  2816. int getStartStop(uint8_t *start, uint8_t *stop)
  2817. {
  2818. int result = -1;
  2819. struct tm tmStart;
  2820. struct timeb tbStart;
  2821. struct tm tmStop;
  2822. struct timeb tbStop;
  2823. 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) &&
  2824. (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))
  2825. {
  2826. //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);
  2827. //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);
  2828. tmStart.tm_year -= 1900;
  2829. tmStart.tm_mon -= 1;
  2830. tbStart.time = mktime(&tmStart);
  2831. tbStart.millitm = 0;
  2832. tmStop.tm_year -= 1900;
  2833. tmStop.tm_mon -= 1;
  2834. tbStop.time = mktime(&tmStop);
  2835. tbStop.millitm = 0;
  2836. result = DiffTimebSec(tbStart, tbStop);
  2837. //DEBUG_INFO("getStartStop(): %d\n", result);
  2838. }
  2839. else
  2840. {
  2841. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2842. }
  2843. return result;
  2844. }
  2845. int isOvertNow(uint8_t *start)
  2846. {
  2847. int result = NO;
  2848. struct ParsingResult
  2849. {
  2850. int result;
  2851. int scanedElement;
  2852. int year;
  2853. int month;
  2854. int mday;
  2855. int hour;
  2856. int min;
  2857. int sec;
  2858. int tz_hour;
  2859. int tz_min;
  2860. float minSec;
  2861. }parsingResult;
  2862. struct tm tmStart;
  2863. struct timeb tbStart;
  2864. if(strstr((char*)start, ".") != NULL)
  2865. {
  2866. // Original data with mini second
  2867. if(strstr((char*)start, "Z") != NULL)
  2868. {
  2869. // Original data with Z
  2870. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2871. &parsingResult.year,
  2872. &parsingResult.month,
  2873. &parsingResult.mday,
  2874. &parsingResult.hour,
  2875. &parsingResult.min,
  2876. &parsingResult.sec,
  2877. &parsingResult.minSec);
  2878. }
  2879. else
  2880. {
  2881. // Original data without Z
  2882. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2883. &parsingResult.year,
  2884. &parsingResult.month,
  2885. &parsingResult.mday,
  2886. &parsingResult.hour,
  2887. &parsingResult.min,
  2888. &parsingResult.sec,
  2889. &parsingResult.minSec,
  2890. &parsingResult.tz_hour,
  2891. &parsingResult.tz_min);
  2892. }
  2893. }
  2894. else
  2895. {
  2896. // Original data without mini second
  2897. if(strstr((char*)start, "Z") != NULL)
  2898. {
  2899. // Original data with Z
  2900. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2901. &parsingResult.year,
  2902. &parsingResult.month,
  2903. &parsingResult.mday,
  2904. &parsingResult.hour,
  2905. &parsingResult.min,
  2906. &parsingResult.sec);
  2907. }
  2908. else
  2909. {
  2910. // Original data without Z
  2911. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2912. &parsingResult.year,
  2913. &parsingResult.month,
  2914. &parsingResult.mday,
  2915. &parsingResult.hour,
  2916. &parsingResult.min,
  2917. &parsingResult.sec,
  2918. &parsingResult.tz_hour,
  2919. &parsingResult.tz_min);
  2920. }
  2921. }
  2922. if(parsingResult.scanedElement >= 6)
  2923. {
  2924. tmStart.tm_year = parsingResult.year - 1900;
  2925. tmStart.tm_mon = parsingResult.month - 1;
  2926. tmStart.tm_mday = parsingResult.mday;
  2927. tmStart.tm_hour = parsingResult.hour;
  2928. tmStart.tm_min = parsingResult.min;
  2929. tmStart.tm_sec = parsingResult.sec;
  2930. tmStart.tm_gmtoff = 0;
  2931. tbStart.time = mktime(&tmStart);
  2932. tbStart.timezone = 0;
  2933. tbStart.millitm = 0;
  2934. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  2935. if(DiffTimebWithNowSec(tbStart) <= 0)
  2936. result = NO;
  2937. else
  2938. result = YES;
  2939. }
  2940. else
  2941. {
  2942. DEBUG_WARN("Start date parsing error.\n");
  2943. }
  2944. return result;
  2945. }
  2946. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2947. {
  2948. int result = -1;
  2949. struct tm tmStart;
  2950. struct timeb tbStart;
  2951. struct tm tmStop;
  2952. struct timeb tbStop;
  2953. 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) &&
  2954. (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))
  2955. {
  2956. tmStart.tm_year -= 1900;
  2957. tmStart.tm_mon -= 1;
  2958. tbStart.time = mktime(&tmStart);
  2959. tbStart.millitm = 0;
  2960. tmStop.tm_year -= 1900;
  2961. tmStop.tm_mon -= 1;
  2962. tbStop.time = mktime(&tmStop);
  2963. tbStop.millitm = 0;
  2964. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2965. }
  2966. return result;
  2967. }
  2968. void checkChargePointMaxProfile(uint32_t durationReq, struct ChargingProfileType *compositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  2969. {
  2970. FILE *fp;
  2971. char profileFileName[128];
  2972. char *line = NULL;
  2973. size_t len = 0;
  2974. time_t CurrentTime;
  2975. struct tm *tmComposite;
  2976. struct ChargingProfileType maxProfile;
  2977. uint8_t limitMax=0;
  2978. int compositePeriodIdx = 0;
  2979. CurrentTime = time(NULL);
  2980. tmComposite=localtime(&CurrentTime);
  2981. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].startSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  2982. if(isUnitA)
  2983. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "A");
  2984. else
  2985. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "W");
  2986. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  2987. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  2988. {
  2989. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2990. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  2991. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2992. }
  2993. compositeProfile->id = 0;
  2994. compositeProfile->stackLevel = 99 ;
  2995. sprintf((char*)compositeProfile->chargingProfileKind ,"Absolute");
  2996. maxProfile.id = -1;
  2997. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  2998. system("rm -f /tmp/*.json");
  2999. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3000. // Search max profile
  3001. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3002. if((access(profileFileName, F_OK))!=-1)
  3003. {
  3004. fp = fopen(profileFileName, "r");
  3005. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3006. {
  3007. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3008. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3009. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3010. }
  3011. maxProfile.id = -1;
  3012. maxProfile.stackLevel = -1;
  3013. while(getline(&line, &len, fp) != -1)
  3014. {
  3015. json_object *obj = NULL;
  3016. obj = json_tokener_parse(line);
  3017. if(is_error(obj))
  3018. {
  3019. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3020. }
  3021. else
  3022. {
  3023. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.id) &&
  3024. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.stackLevel)
  3025. )
  3026. {
  3027. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3028. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3029. )
  3030. {
  3031. struct tm tmFrom, tmTo;
  3032. struct timeb tbFrom, tbTo;
  3033. 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) &&
  3034. (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))
  3035. {
  3036. tmFrom.tm_year -= 1900;
  3037. tmFrom.tm_mon -= 1;
  3038. tbFrom.time = mktime(&tmFrom);
  3039. tmTo.tm_year -= 1900;
  3040. tmTo.tm_mon -= 1;
  3041. tbTo.time = mktime(&tmTo);
  3042. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3043. {
  3044. if(maxProfile.id == -1)
  3045. DEBUG_INFO("MaxProfile found.\n");
  3046. else
  3047. DEBUG_INFO("MaxProfile updated.\n");
  3048. // Required item
  3049. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3050. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3051. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3052. if(isUnitA)
  3053. {
  3054. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3055. 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++)
  3056. {
  3057. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3058. maxProfile.chargingSchedule[idxSchedule].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?
  3059. 3:
  3060. 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")));
  3061. maxProfile.chargingSchedule[idxSchedule].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*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3062. }
  3063. }
  3064. else
  3065. {
  3066. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3067. 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++)
  3068. {
  3069. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3070. maxProfile.chargingSchedule[idxSchedule].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?
  3071. 3:
  3072. 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")));
  3073. maxProfile.chargingSchedule[idxSchedule].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")):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*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3074. }
  3075. }
  3076. // Optional item
  3077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3078. {
  3079. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3080. }
  3081. else
  3082. {
  3083. sprintf((char*)maxProfile.validFrom, " ");
  3084. }
  3085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3086. {
  3087. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3088. }
  3089. else
  3090. {
  3091. sprintf((char*)maxProfile.validTo, " ");
  3092. }
  3093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3094. {
  3095. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3096. }
  3097. else
  3098. {
  3099. sprintf((char*)maxProfile.recurrencyKind, " ");
  3100. }
  3101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3102. {
  3103. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3104. }
  3105. else
  3106. {
  3107. sprintf((char*)maxProfile.transactionId, " ");
  3108. }
  3109. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3110. {
  3111. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3112. }
  3113. else
  3114. {
  3115. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3116. }
  3117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3118. {
  3119. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3120. }
  3121. else
  3122. {
  3123. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3124. }
  3125. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3126. {
  3127. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3128. }
  3129. else
  3130. {
  3131. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3132. }
  3133. }
  3134. }
  3135. }
  3136. else
  3137. {
  3138. if(maxProfile.id == -1)
  3139. DEBUG_INFO("MaxProfile found.\n");
  3140. else
  3141. DEBUG_INFO("MaxProfile updated.\n");
  3142. // Required item
  3143. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3144. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3145. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3146. if(isUnitA)
  3147. {
  3148. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3149. 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++)
  3150. {
  3151. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3152. maxProfile.chargingSchedule[idxSchedule].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?
  3153. 3:
  3154. 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")));
  3155. maxProfile.chargingSchedule[idxSchedule].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*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3156. }
  3157. }
  3158. else
  3159. {
  3160. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3161. 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++)
  3162. {
  3163. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3164. maxProfile.chargingSchedule[idxSchedule].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?
  3165. 3:
  3166. 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")));
  3167. maxProfile.chargingSchedule[idxSchedule].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")):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*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3168. }
  3169. }
  3170. // Optional item
  3171. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3172. {
  3173. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3174. }
  3175. else
  3176. {
  3177. sprintf((char*)maxProfile.validFrom, " ");
  3178. }
  3179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3180. {
  3181. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3182. }
  3183. else
  3184. {
  3185. sprintf((char*)maxProfile.validTo, " ");
  3186. }
  3187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3188. {
  3189. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3190. }
  3191. else
  3192. {
  3193. sprintf((char*)maxProfile.recurrencyKind, " ");
  3194. }
  3195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3196. {
  3197. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3198. }
  3199. else
  3200. {
  3201. sprintf((char*)maxProfile.transactionId, " ");
  3202. }
  3203. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3204. {
  3205. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3206. }
  3207. else
  3208. {
  3209. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3210. }
  3211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3212. {
  3213. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3214. }
  3215. else
  3216. {
  3217. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3218. }
  3219. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3220. {
  3221. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3222. }
  3223. else
  3224. {
  3225. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3226. }
  3227. }
  3228. }
  3229. }
  3230. json_object_put(obj);
  3231. }
  3232. fclose(fp);
  3233. /*
  3234. if(maxProfile.ChargingProfileId !=-1)
  3235. {
  3236. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3237. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3238. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3239. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3240. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3241. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3242. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3243. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3244. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3245. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3246. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3247. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3248. {
  3249. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3250. {
  3251. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3252. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3253. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3254. }
  3255. }
  3256. }
  3257. else
  3258. DEBUG_INFO("MaxProfile not found.\n");
  3259. DEBUG_INFO("------------------------------------\n");*/
  3260. }
  3261. if(maxProfile.id != -1)
  3262. {
  3263. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3264. {
  3265. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3266. {
  3267. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3268. 0:
  3269. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3270. }
  3271. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3272. {
  3273. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3274. {
  3275. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3276. 0:
  3277. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3278. if(idxPeriod > 0)
  3279. {
  3280. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3281. {
  3282. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3283. }
  3284. }
  3285. }
  3286. }
  3287. }
  3288. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3289. {
  3290. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3291. {
  3292. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  3293. }
  3294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3295. {
  3296. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3297. {
  3298. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  3299. if(idxPeriod > 0)
  3300. {
  3301. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3302. {
  3303. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3304. }
  3305. }
  3306. }
  3307. }
  3308. }
  3309. else
  3310. {
  3311. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3312. {
  3313. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3314. {
  3315. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3316. 0:
  3317. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3318. }
  3319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3320. {
  3321. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3322. {
  3323. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3324. 0:
  3325. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3326. if(idxPeriod > 0)
  3327. {
  3328. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3329. {
  3330. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3331. }
  3332. }
  3333. }
  3334. }
  3335. }
  3336. else
  3337. {
  3338. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3339. {
  3340. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3341. 0:
  3342. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3343. }
  3344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3345. {
  3346. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3347. {
  3348. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3349. 0:
  3350. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3351. if(idxPeriod > 0)
  3352. {
  3353. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3354. {
  3355. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3356. }
  3357. }
  3358. }
  3359. }
  3360. }
  3361. }
  3362. /*
  3363. DEBUG_INFO("MaxProfile after align.\n");
  3364. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3365. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3366. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3367. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3368. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3369. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3370. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3371. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3372. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3373. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3374. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3376. {
  3377. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3378. {
  3379. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3380. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3381. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3382. }
  3383. }
  3384. DEBUG_INFO("------------------------------------\n");*/
  3385. }
  3386. // Find each profile period quantity
  3387. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  3388. {
  3389. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  3390. limitMax = idx+1;
  3391. }
  3392. if(maxProfile.id != -1)
  3393. {
  3394. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3395. {
  3396. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  3397. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  3398. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  3399. {
  3400. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3401. {
  3402. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3403. compositePeriodIdx++;
  3404. }
  3405. else
  3406. {
  3407. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3408. }
  3409. }
  3410. }
  3411. }
  3412. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  3413. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3414. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[idxSchedule].duration);
  3415. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit);
  3416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3417. {
  3418. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  3419. {
  3420. compositeProfile->id = 1;
  3421. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3422. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  3423. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  3424. }
  3425. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  3426. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  3427. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  3428. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  3429. }
  3430. if(line)
  3431. free(line);
  3432. }
  3433. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *compositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3434. {
  3435. FILE *fp;
  3436. char profileFileName[128];
  3437. char *line = NULL;
  3438. size_t len = 0;
  3439. time_t CurrentTime;
  3440. struct tm *tmComposite;
  3441. struct ChargingProfileType maxProfile;
  3442. struct ChargingProfileType defaultTxProfile;
  3443. struct ChargingProfileType txProfile;
  3444. struct ChargingSchedulePeriodType tmpPeriod;
  3445. uint8_t limitMax=0;
  3446. uint8_t limitDef=0;
  3447. uint8_t limitTx=0;
  3448. int compositePeriodIdx = 0;
  3449. CurrentTime = time(NULL);
  3450. tmComposite=localtime(&CurrentTime);
  3451. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].startSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  3452. if(isUnitA)
  3453. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3454. else
  3455. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3456. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  3457. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3458. {
  3459. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3460. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3461. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3462. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  3463. }
  3464. compositeProfile->id = 0;
  3465. compositeProfile->stackLevel = 99 ;
  3466. sprintf((char*)compositeProfile->chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  3467. maxProfile.id = -1;
  3468. defaultTxProfile.id = -1;
  3469. txProfile.id = -1;
  3470. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3471. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  3472. txProfile.chargingSchedule[idxSchedule].duration = -1;
  3473. system("rm -f /tmp/*.json");
  3474. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3475. /*
  3476. * Search valid charging profile
  3477. */
  3478. //DEBUG_INFO("====================================\n");
  3479. // Search tx profile
  3480. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  3481. if((access(profileFileName, F_OK))!=-1)
  3482. {
  3483. fp = fopen(profileFileName, "r");
  3484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3485. {
  3486. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3487. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3488. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3489. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3490. }
  3491. txProfile.id = -1;
  3492. txProfile.stackLevel = -1;
  3493. while(getline(&line, &len, fp) != -1)
  3494. {
  3495. json_object *obj = NULL;
  3496. obj = json_tokener_parse(line);
  3497. if(is_error(obj))
  3498. {
  3499. DEBUG_ERROR("Parse txProfile from file error.\n");
  3500. }
  3501. else
  3502. {
  3503. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.id) &&
  3504. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.stackLevel)
  3505. )
  3506. {
  3507. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3508. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3509. )
  3510. {
  3511. struct tm tmFrom, tmTo;
  3512. struct timeb tbFrom, tbTo;
  3513. 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) &&
  3514. (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))
  3515. {
  3516. tmFrom.tm_year -= 1900;
  3517. tmFrom.tm_mon -= 1;
  3518. tbFrom.time = mktime(&tmFrom);
  3519. tmTo.tm_year -= 1900;
  3520. tmTo.tm_mon -= 1;
  3521. tbTo.time = mktime(&tmTo);
  3522. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3523. {
  3524. if(txProfile.id == -1)
  3525. DEBUG_INFO("TxProfile found.\n");
  3526. else
  3527. DEBUG_INFO("TxProfile updated.\n");
  3528. // Required item
  3529. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3530. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3531. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3532. if(isUnitA)
  3533. {
  3534. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3535. 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++)
  3536. {
  3537. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3538. txProfile.chargingSchedule[idxSchedule].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?
  3539. 3:
  3540. 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")));
  3541. txProfile.chargingSchedule[idxSchedule].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*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3542. }
  3543. }
  3544. else
  3545. {
  3546. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3547. 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++)
  3548. {
  3549. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3550. txProfile.chargingSchedule[idxSchedule].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?
  3551. 3:
  3552. 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")));
  3553. txProfile.chargingSchedule[idxSchedule].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")):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*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3554. }
  3555. }
  3556. // Optional item
  3557. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3558. {
  3559. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3560. }
  3561. else
  3562. {
  3563. sprintf((char*)txProfile.validFrom, " ");
  3564. }
  3565. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3566. {
  3567. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3568. }
  3569. else
  3570. {
  3571. sprintf((char*)txProfile.validTo, " ");
  3572. }
  3573. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3574. {
  3575. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3576. }
  3577. else
  3578. {
  3579. sprintf((char*)txProfile.recurrencyKind, " ");
  3580. }
  3581. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3582. {
  3583. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3584. }
  3585. else
  3586. {
  3587. sprintf((char*)txProfile.transactionId, " ");
  3588. }
  3589. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3590. {
  3591. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3592. }
  3593. else
  3594. {
  3595. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3596. }
  3597. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3598. {
  3599. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3600. }
  3601. else
  3602. {
  3603. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3604. }
  3605. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3606. {
  3607. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3608. }
  3609. else
  3610. {
  3611. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3612. }
  3613. }
  3614. }
  3615. }
  3616. else
  3617. {
  3618. if(txProfile.id == -1)
  3619. DEBUG_INFO("TxProfile found.\n");
  3620. else
  3621. DEBUG_INFO("TxProfile updated.\n");
  3622. // Required item
  3623. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3624. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3625. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3626. if(isUnitA)
  3627. {
  3628. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3629. 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++)
  3630. {
  3631. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3632. txProfile.chargingSchedule[idxSchedule].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?
  3633. 3:
  3634. 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")));
  3635. txProfile.chargingSchedule[idxSchedule].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*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3636. }
  3637. }
  3638. else
  3639. {
  3640. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3641. 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++)
  3642. {
  3643. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3644. txProfile.chargingSchedule[idxSchedule].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?
  3645. 3:
  3646. 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")));
  3647. txProfile.chargingSchedule[idxSchedule].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")):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*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3648. }
  3649. }
  3650. // Optional item
  3651. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3652. {
  3653. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3654. }
  3655. else
  3656. {
  3657. sprintf((char*)txProfile.validFrom, " ");
  3658. }
  3659. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3660. {
  3661. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3662. }
  3663. else
  3664. {
  3665. sprintf((char*)txProfile.validTo, " ");
  3666. }
  3667. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3668. {
  3669. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3670. }
  3671. else
  3672. {
  3673. sprintf((char*)txProfile.recurrencyKind, " ");
  3674. }
  3675. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3676. {
  3677. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3678. }
  3679. else
  3680. {
  3681. sprintf((char*)txProfile.transactionId, " ");
  3682. }
  3683. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3684. {
  3685. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3686. }
  3687. else
  3688. {
  3689. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3690. }
  3691. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3692. {
  3693. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3694. }
  3695. else
  3696. {
  3697. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3698. }
  3699. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3700. {
  3701. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3702. }
  3703. else
  3704. {
  3705. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3706. }
  3707. }
  3708. }
  3709. }
  3710. json_object_put(obj);
  3711. }
  3712. fclose(fp);
  3713. /*
  3714. if(txProfile.ChargingProfileId != -1)
  3715. {
  3716. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3717. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3718. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3719. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3720. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3721. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3722. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  3723. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  3724. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  3725. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3726. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3727. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3728. {
  3729. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3730. {
  3731. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3732. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3733. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3734. }
  3735. }
  3736. }
  3737. else
  3738. DEBUG_INFO("TxProfile not found.\n");*/
  3739. }
  3740. // Search default tx profile
  3741. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  3742. if((access(profileFileName, F_OK))==-1)
  3743. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  3744. if((access(profileFileName, F_OK))!=-1)
  3745. {
  3746. fp = fopen(profileFileName, "r");
  3747. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3748. {
  3749. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3750. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3751. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3752. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3753. }
  3754. defaultTxProfile.id = -1;
  3755. defaultTxProfile.stackLevel = -1;
  3756. while(getline(&line, &len, fp) != -1)
  3757. {
  3758. json_object *obj = NULL;
  3759. obj = json_tokener_parse(line);
  3760. if(is_error(obj))
  3761. {
  3762. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  3763. }
  3764. else
  3765. {
  3766. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.id) &&
  3767. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.stackLevel)
  3768. )
  3769. {
  3770. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3771. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3772. )
  3773. {
  3774. struct tm tmFrom, tmTo;
  3775. struct timeb tbFrom, tbTo;
  3776. 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) &&
  3777. (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))
  3778. {
  3779. tmFrom.tm_year -= 1900;
  3780. tmFrom.tm_mon -= 1;
  3781. tbFrom.time = mktime(&tmFrom);
  3782. tmTo.tm_year -= 1900;
  3783. tmTo.tm_mon -= 1;
  3784. tbTo.time = mktime(&tmTo);
  3785. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3786. {
  3787. if(defaultTxProfile.id == -1)
  3788. DEBUG_INFO("TxDefaultProfile found.\n");
  3789. else
  3790. DEBUG_INFO("TxDefaultProfile updated.\n");
  3791. // Required item
  3792. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3793. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3794. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3795. if(isUnitA)
  3796. {
  3797. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3798. 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++)
  3799. {
  3800. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3801. defaultTxProfile.chargingSchedule[idxSchedule].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?
  3802. 3:
  3803. 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")));
  3804. defaultTxProfile.chargingSchedule[idxSchedule].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*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3805. }
  3806. }
  3807. else
  3808. {
  3809. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3810. 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++)
  3811. {
  3812. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3813. defaultTxProfile.chargingSchedule[idxSchedule].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?
  3814. 3:
  3815. 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")));
  3816. defaultTxProfile.chargingSchedule[idxSchedule].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")):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*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3817. }
  3818. }
  3819. // Optional item
  3820. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3821. {
  3822. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3823. }
  3824. else
  3825. {
  3826. sprintf((char*)defaultTxProfile.validFrom, " ");
  3827. }
  3828. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3829. {
  3830. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3831. }
  3832. else
  3833. {
  3834. sprintf((char*)defaultTxProfile.validTo, " ");
  3835. }
  3836. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3837. {
  3838. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3839. }
  3840. else
  3841. {
  3842. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3843. }
  3844. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3845. {
  3846. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3847. }
  3848. else
  3849. {
  3850. sprintf((char*)defaultTxProfile.transactionId, " ");
  3851. }
  3852. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3853. {
  3854. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3855. }
  3856. else
  3857. {
  3858. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3859. }
  3860. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3861. {
  3862. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3863. }
  3864. else
  3865. {
  3866. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3867. }
  3868. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3869. {
  3870. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3871. }
  3872. else
  3873. {
  3874. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3875. }
  3876. }
  3877. }
  3878. }
  3879. else
  3880. {
  3881. if(defaultTxProfile.id == -1)
  3882. DEBUG_INFO("TxDefaultProfile found.\n");
  3883. else
  3884. DEBUG_INFO("TxDefaultProfile updated.\n");
  3885. // Required item
  3886. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3887. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3888. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3889. if(isUnitA)
  3890. {
  3891. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3892. 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++)
  3893. {
  3894. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3895. defaultTxProfile.chargingSchedule[idxSchedule].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?
  3896. 3:
  3897. 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")));
  3898. defaultTxProfile.chargingSchedule[idxSchedule].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*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3899. }
  3900. }
  3901. else
  3902. {
  3903. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3904. 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++)
  3905. {
  3906. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3907. defaultTxProfile.chargingSchedule[idxSchedule].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?
  3908. 3:
  3909. 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")));
  3910. defaultTxProfile.chargingSchedule[idxSchedule].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")):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*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3911. }
  3912. }
  3913. // Optional item
  3914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3915. {
  3916. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3917. }
  3918. else
  3919. {
  3920. sprintf((char*)defaultTxProfile.validFrom, " ");
  3921. }
  3922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3923. {
  3924. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3925. }
  3926. else
  3927. {
  3928. sprintf((char*)defaultTxProfile.validTo, " ");
  3929. }
  3930. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3931. {
  3932. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3933. }
  3934. else
  3935. {
  3936. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3937. }
  3938. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3939. {
  3940. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3941. }
  3942. else
  3943. {
  3944. sprintf((char*)defaultTxProfile.transactionId, " ");
  3945. }
  3946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3947. {
  3948. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3949. }
  3950. else
  3951. {
  3952. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3953. }
  3954. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3955. {
  3956. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3957. }
  3958. else
  3959. {
  3960. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3961. }
  3962. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3963. {
  3964. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3965. }
  3966. else
  3967. {
  3968. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3969. }
  3970. }
  3971. }
  3972. }
  3973. json_object_put(obj);
  3974. }
  3975. fclose(fp);
  3976. /*
  3977. if(defaultTxProfile.ChargingProfileId != -1)
  3978. {
  3979. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3980. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3981. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3982. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3983. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3984. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3985. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3986. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3987. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  3988. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3989. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3991. {
  3992. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3993. {
  3994. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3995. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3996. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3997. }
  3998. }
  3999. }
  4000. else
  4001. DEBUG_INFO("TxDefaultProfile not found.\n");
  4002. DEBUG_INFO("------------------------------------\n");*/
  4003. }
  4004. // Search max profile
  4005. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  4006. if((access(profileFileName, F_OK))!=-1)
  4007. {
  4008. fp = fopen(profileFileName, "r");
  4009. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4010. {
  4011. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4012. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4013. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4014. }
  4015. maxProfile.id = -1;
  4016. maxProfile.stackLevel = -1;
  4017. while(getline(&line, &len, fp) != -1)
  4018. {
  4019. json_object *obj = NULL;
  4020. obj = json_tokener_parse(line);
  4021. if(is_error(obj))
  4022. {
  4023. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4024. }
  4025. else
  4026. {
  4027. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.id) &&
  4028. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.stackLevel)
  4029. )
  4030. {
  4031. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  4032. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  4033. )
  4034. {
  4035. struct tm tmFrom, tmTo;
  4036. struct timeb tbFrom, tbTo;
  4037. 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) &&
  4038. (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))
  4039. {
  4040. tmFrom.tm_year -= 1900;
  4041. tmFrom.tm_mon -= 1;
  4042. tbFrom.time = mktime(&tmFrom);
  4043. tmTo.tm_year -= 1900;
  4044. tmTo.tm_mon -= 1;
  4045. tbTo.time = mktime(&tmTo);
  4046. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4047. {
  4048. if(maxProfile.id == -1)
  4049. DEBUG_INFO("MaxProfile found.\n");
  4050. else
  4051. DEBUG_INFO("MaxProfile updated.\n");
  4052. // Required item
  4053. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  4054. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  4055. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  4056. if(isUnitA)
  4057. {
  4058. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4059. 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++)
  4060. {
  4061. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4062. maxProfile.chargingSchedule[idxSchedule].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?
  4063. 3:
  4064. 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")));
  4065. maxProfile.chargingSchedule[idxSchedule].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*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4066. }
  4067. }
  4068. else
  4069. {
  4070. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4071. 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++)
  4072. {
  4073. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4074. maxProfile.chargingSchedule[idxSchedule].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?
  4075. 3:
  4076. 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")));
  4077. maxProfile.chargingSchedule[idxSchedule].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")):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*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4078. }
  4079. }
  4080. // Optional item
  4081. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  4082. {
  4083. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  4084. }
  4085. else
  4086. {
  4087. sprintf((char*)maxProfile.validFrom, " ");
  4088. }
  4089. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  4090. {
  4091. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  4092. }
  4093. else
  4094. {
  4095. sprintf((char*)maxProfile.validTo, " ");
  4096. }
  4097. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  4098. {
  4099. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  4100. }
  4101. else
  4102. {
  4103. sprintf((char*)maxProfile.recurrencyKind, " ");
  4104. }
  4105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  4106. {
  4107. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  4108. }
  4109. else
  4110. {
  4111. sprintf((char*)maxProfile.transactionId, " ");
  4112. }
  4113. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  4114. {
  4115. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  4116. }
  4117. else
  4118. {
  4119. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4120. }
  4121. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  4122. {
  4123. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  4124. }
  4125. else
  4126. {
  4127. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4128. }
  4129. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  4130. {
  4131. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  4132. }
  4133. else
  4134. {
  4135. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4136. }
  4137. }
  4138. }
  4139. }
  4140. else
  4141. {
  4142. if(maxProfile.id == -1)
  4143. DEBUG_INFO("MaxProfile found.\n");
  4144. else
  4145. DEBUG_INFO("MaxProfile updated.\n");
  4146. // Required item
  4147. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  4148. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  4149. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  4150. if(isUnitA)
  4151. {
  4152. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4153. 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++)
  4154. {
  4155. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4156. maxProfile.chargingSchedule[idxSchedule].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?
  4157. 3:
  4158. 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")));
  4159. maxProfile.chargingSchedule[idxSchedule].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*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4160. }
  4161. }
  4162. else
  4163. {
  4164. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4165. 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++)
  4166. {
  4167. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4168. maxProfile.chargingSchedule[idxSchedule].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?
  4169. 3:
  4170. 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")));
  4171. maxProfile.chargingSchedule[idxSchedule].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")):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*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4172. }
  4173. }
  4174. // Optional item
  4175. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  4176. {
  4177. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  4178. }
  4179. else
  4180. {
  4181. sprintf((char*)maxProfile.validFrom, " ");
  4182. }
  4183. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  4184. {
  4185. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  4186. }
  4187. else
  4188. {
  4189. sprintf((char*)maxProfile.validTo, " ");
  4190. }
  4191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  4192. {
  4193. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  4194. }
  4195. else
  4196. {
  4197. sprintf((char*)maxProfile.recurrencyKind, " ");
  4198. }
  4199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  4200. {
  4201. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  4202. }
  4203. else
  4204. {
  4205. sprintf((char*)maxProfile.transactionId, " ");
  4206. }
  4207. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  4208. {
  4209. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  4210. }
  4211. else
  4212. {
  4213. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4214. }
  4215. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  4216. {
  4217. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  4218. }
  4219. else
  4220. {
  4221. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4222. }
  4223. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  4224. {
  4225. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  4226. }
  4227. else
  4228. {
  4229. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4230. }
  4231. }
  4232. }
  4233. }
  4234. json_object_put(obj);
  4235. }
  4236. fclose(fp);
  4237. /*
  4238. if(maxProfile.ChargingProfileId !=-1)
  4239. {
  4240. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  4241. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4242. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4243. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4244. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4245. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4246. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  4247. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4248. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4249. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4250. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4251. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4252. {
  4253. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4254. {
  4255. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4256. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4257. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4258. }
  4259. }
  4260. }
  4261. else
  4262. DEBUG_INFO("MaxProfile not found.\n");
  4263. DEBUG_INFO("------------------------------------\n");*/
  4264. }
  4265. /*
  4266. * Align found profile start schedule & periods
  4267. */
  4268. //DEBUG_INFO("====================================\n");
  4269. /*
  4270. // For local test usage, force modify found profile start schedule info
  4271. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  4272. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  4273. sprintf((char*)txProfile.chargingSchedule[idxSchedule].StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  4274. */
  4275. if(txProfile.id != -1)
  4276. {
  4277. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4278. {
  4279. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4280. {
  4281. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4282. 0:
  4283. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4284. }
  4285. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4286. {
  4287. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4288. {
  4289. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4290. 0:
  4291. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4292. if(idxPeriod > 0)
  4293. {
  4294. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4295. {
  4296. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4297. }
  4298. }
  4299. }
  4300. }
  4301. }
  4302. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4303. {
  4304. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4305. {
  4306. txProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].duration:((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4307. 0:
  4308. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4309. }
  4310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4311. {
  4312. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4313. {
  4314. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4315. 0:
  4316. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4317. if(idxPeriod > 0)
  4318. {
  4319. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4320. {
  4321. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4322. }
  4323. }
  4324. }
  4325. }
  4326. }
  4327. else
  4328. {
  4329. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4330. {
  4331. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4332. {
  4333. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4334. 0:
  4335. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4336. }
  4337. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4338. {
  4339. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4340. {
  4341. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4342. 0:
  4343. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4344. if(idxPeriod > 0)
  4345. {
  4346. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4347. {
  4348. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4349. }
  4350. }
  4351. }
  4352. }
  4353. }
  4354. else
  4355. {
  4356. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4357. {
  4358. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4359. 0:
  4360. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4361. }
  4362. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4363. {
  4364. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4365. {
  4366. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4367. 0:
  4368. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4369. if(idxPeriod > 0)
  4370. {
  4371. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4372. {
  4373. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4374. }
  4375. }
  4376. }
  4377. }
  4378. }
  4379. }
  4380. /*
  4381. DEBUG_INFO("txProfile after align.\n");
  4382. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  4383. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4384. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4385. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4386. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4387. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4388. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  4389. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4390. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4391. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4392. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4394. {
  4395. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4396. {
  4397. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4398. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4399. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4400. }
  4401. }*/
  4402. }
  4403. if(defaultTxProfile.id != -1)
  4404. {
  4405. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4406. {
  4407. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4408. {
  4409. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4410. 0:
  4411. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4412. }
  4413. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4414. {
  4415. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4416. {
  4417. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4418. 0:
  4419. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4420. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4421. {
  4422. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4423. }
  4424. if(idxPeriod > 0)
  4425. {
  4426. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4427. {
  4428. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4429. }
  4430. }
  4431. }
  4432. }
  4433. }
  4434. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4435. {
  4436. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4437. {
  4438. defaultTxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].duration:((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4439. 0:
  4440. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4441. }
  4442. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4443. {
  4444. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4445. {
  4446. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4447. 0:
  4448. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4449. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4450. {
  4451. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4452. }
  4453. if(idxPeriod > 0)
  4454. {
  4455. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4456. {
  4457. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4458. }
  4459. }
  4460. }
  4461. }
  4462. }
  4463. else
  4464. {
  4465. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4466. {
  4467. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4468. {
  4469. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4470. 0:
  4471. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4472. }
  4473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4474. {
  4475. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4476. {
  4477. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4478. 0:
  4479. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4480. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4481. {
  4482. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4483. }
  4484. if(idxPeriod > 0)
  4485. {
  4486. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4487. {
  4488. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4489. }
  4490. }
  4491. }
  4492. }
  4493. }
  4494. else
  4495. {
  4496. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4497. {
  4498. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4499. 0:
  4500. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4501. }
  4502. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4503. {
  4504. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4505. {
  4506. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4507. 0:
  4508. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4509. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4510. {
  4511. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4512. }
  4513. if(idxPeriod > 0)
  4514. {
  4515. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4516. {
  4517. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4518. }
  4519. }
  4520. }
  4521. }
  4522. }
  4523. }
  4524. /*
  4525. DEBUG_INFO("defaultTxProfile after align.\n");
  4526. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  4527. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  4528. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  4529. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  4530. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  4531. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  4532. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  4533. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4534. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  4535. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4536. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4537. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4538. {
  4539. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4540. {
  4541. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4542. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4543. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4544. }
  4545. }
  4546. DEBUG_INFO("------------------------------------\n");*/
  4547. }
  4548. if(maxProfile.id != -1)
  4549. {
  4550. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4551. {
  4552. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4553. {
  4554. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4555. 0:
  4556. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4557. }
  4558. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4559. {
  4560. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4561. {
  4562. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4563. 0:
  4564. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4565. if(idxPeriod > 0)
  4566. {
  4567. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4568. {
  4569. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4570. }
  4571. }
  4572. }
  4573. }
  4574. }
  4575. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4576. {
  4577. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4578. {
  4579. maxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].duration:((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4580. 0:
  4581. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[9].startSchedule)));
  4582. }
  4583. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4584. {
  4585. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4586. {
  4587. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4588. 0:
  4589. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4590. if(idxPeriod > 0)
  4591. {
  4592. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4593. {
  4594. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4595. }
  4596. }
  4597. }
  4598. }
  4599. }
  4600. else
  4601. {
  4602. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4603. {
  4604. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4605. {
  4606. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4607. 0:
  4608. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4609. }
  4610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4611. {
  4612. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4613. {
  4614. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4615. 0:
  4616. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4617. if(idxPeriod > 0)
  4618. {
  4619. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4620. {
  4621. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4622. }
  4623. }
  4624. }
  4625. }
  4626. }
  4627. else
  4628. {
  4629. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4630. {
  4631. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4632. 0:
  4633. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4634. }
  4635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4636. {
  4637. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4638. {
  4639. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4640. 0:
  4641. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4642. if(idxPeriod > 0)
  4643. {
  4644. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4645. {
  4646. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4647. }
  4648. }
  4649. }
  4650. }
  4651. }
  4652. }
  4653. /*
  4654. DEBUG_INFO("MaxProfile after align.\n");
  4655. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  4656. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4657. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4658. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4659. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4660. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4661. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  4662. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4663. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4664. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4665. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4666. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4667. {
  4668. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4669. {
  4670. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4671. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4672. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4673. }
  4674. }
  4675. DEBUG_INFO("------------------------------------\n");*/
  4676. }
  4677. /*
  4678. * Merge to conposite schedule
  4679. */
  4680. //DEBUG_INFO("====================================\n");
  4681. // Find each profile period quantity
  4682. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4683. {
  4684. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4685. limitMax = idx+1;
  4686. }
  4687. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4688. {
  4689. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4690. limitDef = idx+1;
  4691. }
  4692. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4693. {
  4694. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4695. limitTx = idx+1;
  4696. }
  4697. // TxProfile found, composite schedule based on it
  4698. if(txProfile.id != -1)
  4699. {
  4700. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  4701. {
  4702. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  4703. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  4704. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  4705. {
  4706. if(maxProfile.id != -1)
  4707. {
  4708. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4709. {
  4710. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  4711. {
  4712. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4713. {
  4714. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4715. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4716. tmpPeriod.limit = (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit>maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit:txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit);
  4717. }
  4718. else
  4719. {
  4720. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4721. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4722. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  4723. }
  4724. }
  4725. if(idxMaxPeriod == (limitMax-1))
  4726. {
  4727. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4728. {
  4729. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4730. {
  4731. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4732. compositePeriodIdx++;
  4733. }
  4734. else
  4735. {
  4736. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4737. }
  4738. }
  4739. }
  4740. }
  4741. }
  4742. else
  4743. {
  4744. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4745. {
  4746. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4747. compositePeriodIdx++;
  4748. }
  4749. else
  4750. {
  4751. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4752. }
  4753. }
  4754. }
  4755. if(idxTxPeriod == (limitTx-1))
  4756. {
  4757. if(defaultTxProfile.id != -1)
  4758. {
  4759. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4760. {
  4761. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  4762. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4763. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  4764. {
  4765. if(maxProfile.id != -1)
  4766. {
  4767. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4768. {
  4769. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4770. {
  4771. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4772. {
  4773. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4774. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4775. tmpPeriod.limit = (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit>maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit:defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit);
  4776. }
  4777. else
  4778. {
  4779. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4780. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4781. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4782. }
  4783. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4784. {
  4785. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4786. {
  4787. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4788. compositePeriodIdx++;
  4789. }
  4790. else
  4791. {
  4792. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4793. }
  4794. }
  4795. // Delete duplicate period
  4796. if(compositePeriodIdx > 1)
  4797. {
  4798. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4799. {
  4800. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4801. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4802. compositePeriodIdx -= 1;
  4803. }
  4804. }
  4805. }
  4806. else
  4807. break;
  4808. }
  4809. }
  4810. else
  4811. {
  4812. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4813. {
  4814. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4815. compositePeriodIdx++;
  4816. }
  4817. else
  4818. {
  4819. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4820. }
  4821. }
  4822. }
  4823. }
  4824. }
  4825. }
  4826. }
  4827. }
  4828. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4829. else if(defaultTxProfile.id != -1)
  4830. {
  4831. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4832. {
  4833. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  4834. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4835. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  4836. {
  4837. if(maxProfile.id != -1)
  4838. {
  4839. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4840. {
  4841. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4842. {
  4843. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4844. {
  4845. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4846. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4847. tmpPeriod.limit = (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit>maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit:defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit);
  4848. }
  4849. else
  4850. {
  4851. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4852. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4853. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4854. }
  4855. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4856. {
  4857. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4858. {
  4859. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4860. compositePeriodIdx++;
  4861. }
  4862. else
  4863. {
  4864. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4865. }
  4866. }
  4867. // Delete duplicate period
  4868. if(compositePeriodIdx > 1)
  4869. {
  4870. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4871. {
  4872. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4873. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4874. compositePeriodIdx -= 1;
  4875. }
  4876. }
  4877. }
  4878. else
  4879. break;
  4880. }
  4881. }
  4882. else
  4883. {
  4884. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4885. {
  4886. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4887. compositePeriodIdx++;
  4888. }
  4889. else
  4890. {
  4891. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4892. }
  4893. }
  4894. }
  4895. }
  4896. }
  4897. // Fill other period by MaxProfile
  4898. if(maxProfile.id != -1)
  4899. {
  4900. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4901. {
  4902. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4903. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4904. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4905. {
  4906. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod >= compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod) &&
  4907. (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  4908. {
  4909. tmpPeriod.startPeriod = (compositePeriodIdx==0)?0:compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod;
  4910. tmpPeriod.numberPhases = compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].numberPhases;
  4911. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  4912. }
  4913. if((compositePeriodIdx > 0) && (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  4914. {
  4915. tmpPeriod.startPeriod = (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod>compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod)?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod:compositeProfile->chargingSchedule[idxSchedule].duration;
  4916. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  4917. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  4918. }
  4919. if(tmpPeriod.limit != -1)
  4920. {
  4921. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4922. {
  4923. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4924. {
  4925. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4926. compositePeriodIdx++;
  4927. }
  4928. else
  4929. {
  4930. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4931. }
  4932. }
  4933. // Delete duplicate period
  4934. if(compositePeriodIdx > 1)
  4935. {
  4936. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4937. {
  4938. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4939. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4940. compositePeriodIdx -= 1;
  4941. }
  4942. }
  4943. }
  4944. }
  4945. }
  4946. }
  4947. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4948. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  4949. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[idxSchedule].duration);
  4950. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit);
  4951. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4952. {
  4953. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4954. {
  4955. compositeProfile->id = 1;
  4956. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4957. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4958. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4959. }
  4960. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4961. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4962. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4963. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4964. }
  4965. if(line)
  4966. free(line);
  4967. checkChargePointMaxProfile(durationReq, &ShmOCPP20Data->MaxChargingProfile, idxSchedule, isUnitA);
  4968. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  4969. }
  4970. //==========================================
  4971. // Init all share memory
  4972. //==========================================
  4973. int InitShareMemory()
  4974. {
  4975. int result = PASS;
  4976. int MeterSMId;
  4977. //creat ShmSysConfigAndInfo
  4978. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4979. {
  4980. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4981. result = FAIL;
  4982. }
  4983. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4984. {
  4985. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4986. result = FAIL;
  4987. }
  4988. else
  4989. {}
  4990. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4991. {
  4992. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4993. result = FAIL;
  4994. }
  4995. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4996. {
  4997. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4998. result = FAIL;
  4999. }
  5000. else
  5001. {}
  5002. //creat ShmPsuData
  5003. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  5004. {
  5005. DEBUG_ERROR("shmget ShmPsuData NG\n");
  5006. result = FAIL;
  5007. }
  5008. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5009. {
  5010. DEBUG_ERROR("shmat ShmPsuData NG\n");
  5011. result = FAIL;
  5012. }
  5013. else
  5014. {}
  5015. //creat ShmOCPP20Data
  5016. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  5017. {
  5018. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  5019. result = FAIL;
  5020. }
  5021. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5022. {
  5023. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  5024. result = FAIL;
  5025. }
  5026. else
  5027. {}
  5028. /****************************** For Initial Settings************************************************/
  5029. /*
  5030. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  5031. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  5032. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  5033. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  5034. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  5035. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  5036. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  5037. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  5038. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  5039. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  5040. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  5041. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  5042. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  5043. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  5044. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  5045. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  5046. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  5047. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  5048. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  5049. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  5050. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  5051. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  5052. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  5053. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  5054. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  5055. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  5056. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  5057. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  5058. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  5059. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  5060. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  5061. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  5062. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  5063. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  5064. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  5065. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  5066. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  5067. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  5068. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  5069. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  5070. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  5071. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  5072. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  5073. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  5074. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  5075. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  5076. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  5077. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  5078. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  5079. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  5080. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  5081. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  5082. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  5083. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  5084. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  5085. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  5086. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  5087. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  5088. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  5089. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  5090. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  5091. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  5092. */
  5093. return result;
  5094. }
  5095. int ProcessShareMemory()
  5096. {
  5097. if(InitShareMemory() == FAIL)
  5098. {
  5099. DEBUG_ERROR("InitShareMemory NG\n");
  5100. if(ShmStatusCodeData!=NULL)
  5101. {
  5102. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  5103. }
  5104. sleep(5);
  5105. return FAIL;
  5106. }
  5107. return PASS;
  5108. }
  5109. //---------------------common routine---------------------------//
  5110. void checkNetworkProfile(void)
  5111. {
  5112. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  5113. json_object *priority;
  5114. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  5115. if(!is_error(priority))
  5116. {
  5117. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  5118. {
  5119. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  5120. {
  5121. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  5122. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  5123. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  5124. {
  5125. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  5126. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  5127. break;
  5128. }
  5129. }
  5130. }
  5131. }
  5132. json_object_put(priority);
  5133. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  5134. }
  5135. void CheckSystemValue(void)
  5136. {
  5137. char filenmae[100]={0};
  5138. char str[100]={0};
  5139. int tempIndex = 0;
  5140. //===============================
  5141. // EVSE operation check
  5142. //===============================
  5143. //===============================
  5144. // Heartbeat check
  5145. //===============================
  5146. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  5147. {
  5148. clientTime.Heartbeat = time((time_t*)NULL);
  5149. if(server_sign == TRUE)
  5150. {
  5151. HeartBeatWaitTime = ShmOCPP20Data->BootNotification.Response_interval;
  5152. }
  5153. else
  5154. {
  5155. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  5156. }
  5157. }
  5158. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  5159. {
  5160. //parameter for test
  5161. sendHeartbeatRequest(0);
  5162. //==============================================
  5163. // Reset Waiting Time
  5164. //==============================================
  5165. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  5166. }
  5167. //===============================
  5168. // CSU Trigger Authorize Request
  5169. //===============================
  5170. if(isWebsocketSendable &&
  5171. (server_sign == TRUE) &&
  5172. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  5173. (authorizeRetryTimes < 3))
  5174. {
  5175. sendAuthorizeRequest(0);
  5176. authorizeRetryTimes = authorizeRetryTimes + 1;
  5177. if(authorizeRetryTimes < 3)
  5178. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5179. }
  5180. else if((server_sign == TRUE) &&
  5181. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  5182. (authorizeRetryTimes >= 3))
  5183. {
  5184. authorizeRetryTimes = 0;
  5185. SetOcppConnStatus(FALSE);
  5186. server_sign = FALSE;
  5187. }
  5188. else if((server_sign == FALSE) &&
  5189. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE") == 0) &&
  5190. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  5191. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  5192. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  5193. {
  5194. sendAuthorizeRequest(0);
  5195. }
  5196. if(isWebsocketSendable &&
  5197. (server_sign == TRUE) &&
  5198. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  5199. {
  5200. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  5201. {
  5202. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  5203. {
  5204. /*
  5205. * TODO:
  5206. * 1. Report component that are ThresholdMonitoring
  5207. */
  5208. }
  5209. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  5210. {
  5211. /*
  5212. * TODO:
  5213. * 1. Report component that are DeltaMonitoring
  5214. */
  5215. }
  5216. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  5217. {
  5218. /*
  5219. * TODO:
  5220. * 1. Report component that are PeriodicMonitoring
  5221. */
  5222. }
  5223. else
  5224. {
  5225. /*
  5226. * TODO:
  5227. * 1. Process unknown criteria condition
  5228. */
  5229. }
  5230. }
  5231. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  5232. }
  5233. if(isWebsocketSendable &&
  5234. (server_sign == TRUE) &&
  5235. (ShmOCPP20Data->GetReport.requestId > 0))
  5236. {
  5237. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  5238. {
  5239. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  5240. {
  5241. /*
  5242. * TODO:
  5243. * 1. Report component that are active
  5244. */
  5245. }
  5246. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  5247. {
  5248. /*
  5249. * TODO:
  5250. * 1. Report component that are available
  5251. */
  5252. }
  5253. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  5254. {
  5255. /*
  5256. * TODO:
  5257. * 1. Report component that are enable
  5258. */
  5259. }
  5260. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  5261. {
  5262. /*
  5263. * TODO:
  5264. * 1. Report component that are problem
  5265. */
  5266. }
  5267. else
  5268. {
  5269. /*
  5270. * TODO:
  5271. * 1. Process unknown criteria condition
  5272. */
  5273. }
  5274. }
  5275. ShmOCPP20Data->GetReport.requestId = 0;
  5276. }
  5277. if(isWebsocketSendable &&
  5278. (server_sign == TRUE) &&
  5279. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  5280. {
  5281. uint8_t reportIdx = 0;
  5282. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  5283. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  5284. {
  5285. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  5286. {
  5287. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  5288. {
  5289. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]) == 0) || (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]) == 0))
  5290. {
  5291. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  5292. reportIdx++;
  5293. }
  5294. }
  5295. else
  5296. {
  5297. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5298. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5299. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5300. else
  5301. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5302. sendNotifyReportRequest();
  5303. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5304. reportIdx = 0;
  5305. }
  5306. }
  5307. }
  5308. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  5309. {
  5310. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  5311. {
  5312. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  5313. {
  5314. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  5315. reportIdx++;
  5316. }
  5317. else
  5318. {
  5319. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5320. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5321. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5322. else
  5323. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5324. sendNotifyReportRequest();
  5325. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5326. reportIdx = 0;
  5327. }
  5328. }
  5329. }
  5330. else
  5331. {
  5332. /*
  5333. * TODO:
  5334. * 1. Fill out summary inventory to response message, currently not support
  5335. */
  5336. }
  5337. if(reportIdx > 0)
  5338. {
  5339. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5340. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5341. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5342. else
  5343. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5344. sendNotifyReportRequest();
  5345. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5346. reportIdx = 0;
  5347. }
  5348. ShmOCPP20Data->GetBaseReport.requestId = 0;
  5349. }
  5350. if(isWebsocketSendable &&
  5351. (server_sign == TRUE) &&
  5352. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  5353. {
  5354. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  5355. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  5356. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  5357. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  5358. else
  5359. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  5360. sendNotifyEventRequest();
  5361. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  5362. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  5363. }
  5364. if(isWebsocketSendable &&
  5365. (server_sign == TRUE) &&
  5366. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  5367. {
  5368. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  5369. {
  5370. /*
  5371. * TODO:
  5372. * 1.
  5373. */
  5374. }
  5375. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  5376. {
  5377. /*
  5378. * TODO:
  5379. * 1.
  5380. */
  5381. }
  5382. else
  5383. {
  5384. /*
  5385. * TODO:
  5386. * 1.
  5387. */
  5388. }
  5389. sendGet15118EVCertificateRequest();
  5390. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  5391. }
  5392. //===============================
  5393. // Each connector operation check
  5394. //===============================
  5395. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  5396. {
  5397. //==========================================
  5398. // csu trigger DataTransferReq
  5399. //==========================================
  5400. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  5401. {
  5402. sendDataTransferRequest(gun_index);
  5403. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  5404. }
  5405. //==============================================
  5406. // Charger start transaction
  5407. //==============================================
  5408. /*
  5409. if((ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq == ON))
  5410. {
  5411. ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq = OFF;
  5412. sendStartTransactionRequest(gun_index);
  5413. clientTime.StartTransaction = time((time_t*)NULL);
  5414. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  5415. }*/
  5416. //==============================================
  5417. // Charger stop transaction
  5418. //==============================================
  5419. /*
  5420. if(((ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq == ON)))
  5421. {
  5422. ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq =OFF;
  5423. sendStopTransactionRequest(gun_index);
  5424. clientTime.StopTransaction = time((time_t*)NULL);
  5425. }*/
  5426. //==============================================
  5427. // Charger status notification & Transaction event report
  5428. //==============================================
  5429. //--- Check Mode Change ---//
  5430. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5431. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5432. {
  5433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5434. {
  5435. tempIndex = ((gun_index==2) ? 1: 0);
  5436. }
  5437. else
  5438. {
  5439. tempIndex = gun_index;
  5440. }
  5441. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5442. {
  5443. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5444. {
  5445. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5446. {
  5447. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5448. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5449. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5450. if((SystemInitial == 0) &&
  5451. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5452. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5453. {
  5454. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5455. }
  5456. }
  5457. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5458. {
  5459. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5460. if((access(filenmae,F_OK))!=-1)
  5461. {
  5462. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5463. sprintf(str,"rm -f %s",filenmae);
  5464. system(str);
  5465. }
  5466. }
  5467. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5468. #if 1 // for TempStopTransaction
  5469. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5470. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5471. {
  5472. checkTempStopTransaction(gun_index);
  5473. }
  5474. #endif
  5475. }
  5476. }
  5477. }
  5478. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  5489. {
  5490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5491. {
  5492. 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]*/ )
  5493. {
  5494. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5495. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5496. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5497. if((SystemInitial == 0) &&
  5498. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5499. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5500. {
  5501. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5502. }
  5503. }
  5504. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5505. {
  5506. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5507. if((access(filenmae,F_OK))!=-1)
  5508. {
  5509. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5510. sprintf(str,"rm -f %s",filenmae);
  5511. system(str);
  5512. }
  5513. }
  5514. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5515. #if 1 // for TempStopTransaction
  5516. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5517. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5518. {
  5519. checkTempStopTransaction(gun_index);
  5520. }
  5521. #endif
  5522. }
  5523. }
  5524. }
  5525. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5526. {
  5527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5528. {
  5529. tempIndex = ((gun_index==2) ? 1: 0);
  5530. }
  5531. else
  5532. {
  5533. tempIndex = gun_index;
  5534. }
  5535. for (int index = 0; index < GB_QUANTITY; index++)
  5536. {
  5537. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5538. {
  5539. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5540. {
  5541. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5542. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5543. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5544. if((SystemInitial == 0) &&
  5545. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5546. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5547. {
  5548. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5549. }
  5550. }
  5551. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5552. {
  5553. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5554. if((access(filenmae,F_OK))!=-1)
  5555. {
  5556. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5557. sprintf(str,"rm -f %s",filenmae);
  5558. system(str);
  5559. }
  5560. }
  5561. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5562. #if 1 // for TempStopTransaction
  5563. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5564. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5565. {
  5566. checkTempStopTransaction(gun_index);
  5567. }
  5568. #endif
  5569. }
  5570. }
  5571. }
  5572. else if(gunType[gun_index] == GUN_TYPE_DO)
  5573. {
  5574. tempIndex = gun_index;
  5575. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5576. {
  5577. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5578. {
  5579. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5580. {
  5581. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5582. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5583. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5584. if((SystemInitial == 0) &&
  5585. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) &&
  5586. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE))
  5587. {
  5588. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5589. }
  5590. }
  5591. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  5592. {
  5593. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5594. if((access(filenmae,F_OK))!=-1)
  5595. {
  5596. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5597. sprintf(str,"rm -f %s",filenmae);
  5598. system(str);
  5599. }
  5600. }
  5601. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5602. #if 1 // for TempStopTransaction
  5603. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5604. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5605. {
  5606. checkTempStopTransaction(gun_index);
  5607. }
  5608. #endif
  5609. }
  5610. }
  5611. }
  5612. else
  5613. {
  5614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5615. {
  5616. tempIndex = 2;
  5617. }
  5618. else
  5619. {
  5620. tempIndex = gun_index;
  5621. }
  5622. for (int index = 0; index < AC_QUANTITY; index++)
  5623. {
  5624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5625. {
  5626. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5627. {
  5628. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5629. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5630. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5631. if((SystemInitial == 0) &&
  5632. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5633. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5634. {
  5635. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5636. }
  5637. }
  5638. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5639. {
  5640. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5641. if((access(filenmae,F_OK))!=-1)
  5642. {
  5643. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5644. sprintf(str,"rm -f %s",filenmae);
  5645. system(str);
  5646. }
  5647. }
  5648. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5649. #if 1 // for TempStopTransaction
  5650. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5651. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5652. {
  5653. checkTempStopTransaction(gun_index);
  5654. }
  5655. #endif
  5656. }
  5657. }// END
  5658. }
  5659. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  5660. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON)) )
  5661. {
  5662. if(SystemInitial > 0)
  5663. SystemInitial -= 1;
  5664. sendStatusNotificationRequest(gun_index);
  5665. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  5666. }
  5667. //==============================================
  5668. // CSU Trigger Smart Charging Profile
  5669. //==============================================
  5670. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  5671. {
  5672. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  5673. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  5674. }
  5675. //==============================================
  5676. // CSU transaction event
  5677. //==============================================
  5678. if(cpinitateMsg.bits[gun_index].TransactionEventReq == ON)
  5679. {
  5680. sendTransactionEventRequest(gun_index);
  5681. cpinitateMsg.bits[gun_index].TransactionEventReq = OFF;
  5682. storeTempStopTransaction(gun_index);
  5683. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  5684. }
  5685. //==============================================
  5686. // Meter report
  5687. //==============================================
  5688. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  5689. {
  5690. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  5691. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  5692. }
  5693. // ClockAlign MeterValue
  5694. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value)))==0):FALSE))
  5695. {
  5696. //check Transaction active
  5697. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5698. {
  5699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5700. {
  5701. tempIndex = ((gun_index==2) ? 1: 0);
  5702. }
  5703. else
  5704. {
  5705. tempIndex = gun_index;
  5706. }
  5707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5708. {
  5709. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5710. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5711. {
  5712. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5713. }
  5714. }// End for CHAdeMO
  5715. }
  5716. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5717. {
  5718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5719. {
  5720. tempIndex = ((gun_index==2) ? 1: 0);
  5721. }
  5722. else
  5723. {
  5724. tempIndex = gun_index;
  5725. }
  5726. for (int index = 0; index < CCS_QUANTITY; index++)
  5727. {
  5728. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5729. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5730. {
  5731. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5732. }
  5733. } // End for CCS
  5734. }
  5735. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5736. {
  5737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5738. {
  5739. tempIndex = ((gun_index==2) ? 1: 0);
  5740. }
  5741. else
  5742. {
  5743. tempIndex = gun_index;
  5744. }
  5745. for (int index = 0; index < GB_QUANTITY; index++)
  5746. {
  5747. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5748. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5749. {
  5750. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5751. }
  5752. }// End for GB
  5753. }
  5754. else if(gunType[gun_index] == GUN_TYPE_DO)
  5755. {
  5756. tempIndex = gun_index;
  5757. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5758. {
  5759. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5760. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5761. {
  5762. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5763. }
  5764. }
  5765. }
  5766. else
  5767. {
  5768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5769. {
  5770. tempIndex = 2;
  5771. }
  5772. else
  5773. {
  5774. tempIndex = gun_index;
  5775. }
  5776. for (int index = 0; index < AC_QUANTITY; index++)
  5777. {
  5778. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5779. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5780. {
  5781. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5782. }
  5783. }//End for AC
  5784. }
  5785. if(cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON)
  5786. {
  5787. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  5788. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  5789. }
  5790. }
  5791. // Sample period MeterValue
  5792. if((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)>10)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1):10))
  5793. {
  5794. //check Transaction active
  5795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5796. {
  5797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5798. {
  5799. tempIndex = ((gun_index==2) ? 1: 0);
  5800. }
  5801. else
  5802. {
  5803. tempIndex = gun_index;
  5804. }
  5805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5806. {
  5807. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5808. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5809. {
  5810. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5811. {
  5812. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5813. }
  5814. }
  5815. }// End for CHAdeMO
  5816. }
  5817. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5818. {
  5819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5820. {
  5821. tempIndex = ((gun_index==2) ? 1: 0);
  5822. }
  5823. else
  5824. {
  5825. tempIndex = gun_index;
  5826. }
  5827. for (int index = 0; index < CCS_QUANTITY; index++)
  5828. {
  5829. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5830. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5831. {
  5832. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5833. {
  5834. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5835. }
  5836. }
  5837. } // End for CCS
  5838. }
  5839. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5840. {
  5841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5842. {
  5843. tempIndex = ((gun_index==2) ? 1: 0);
  5844. }
  5845. else
  5846. {
  5847. tempIndex = gun_index;
  5848. }
  5849. for (int index = 0; index < GB_QUANTITY; index++)
  5850. {
  5851. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5852. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5853. {
  5854. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5855. {
  5856. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5857. }
  5858. }
  5859. }// End for GB
  5860. }
  5861. else if(gunType[gun_index] == GUN_TYPE_DO)
  5862. {
  5863. tempIndex = gun_index;
  5864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5865. {
  5866. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5867. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5868. {
  5869. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5870. {
  5871. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5872. }
  5873. }
  5874. }
  5875. }
  5876. else
  5877. {
  5878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5879. {
  5880. tempIndex = 2;
  5881. }
  5882. else
  5883. {
  5884. tempIndex = gun_index;
  5885. }
  5886. for (int index = 0; index < AC_QUANTITY; index++)
  5887. {
  5888. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5889. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5890. {
  5891. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5892. {
  5893. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5894. }
  5895. }
  5896. }//End for AC
  5897. }
  5898. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  5899. {
  5900. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  5901. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  5902. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  5903. }
  5904. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  5905. }
  5906. //==============================================
  5907. // Check Connector reserved
  5908. //==============================================
  5909. //===============================
  5910. // Check if Reserve is expired
  5911. //===============================
  5912. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  5913. {
  5914. if(isOvertNow((uint8_t *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  5915. {
  5916. DEBUG_INFO("reserve expired.\n");
  5917. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  5918. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  5919. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  5920. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  5921. }
  5922. }//END OF Check if Reserve is expired
  5923. //==========================================
  5924. // csu trigger FirmwareStatusNotificationReq
  5925. //==========================================
  5926. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  5927. {
  5928. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  5929. }
  5930. //==========================================
  5931. // csu cleared charging limit request
  5932. //==========================================
  5933. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  5934. {
  5935. sendClearedChargingLimitRequest(gun_index);
  5936. }
  5937. //==========================================
  5938. // csu trigger CancelReservationConf
  5939. //==========================================
  5940. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  5941. {
  5942. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  5943. }
  5944. //==========================================
  5945. // csu notify EV charging need request
  5946. //==========================================
  5947. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  5948. {
  5949. sendNotifyEVChargingNeedsRequest(gun_index);
  5950. }
  5951. //==========================================
  5952. // csu trigger ChangeAvailabilityConf
  5953. //==========================================
  5954. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  5955. {
  5956. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  5957. }
  5958. //==========================================
  5959. // csu trigger UnlockConnectorConf
  5960. //==========================================
  5961. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  5962. {
  5963. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  5964. }
  5965. //==========================================
  5966. // csu trigger ReserveNowConf
  5967. //==========================================
  5968. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  5969. {
  5970. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  5971. }
  5972. //==========================================
  5973. // csu trigger ReserveNowConf
  5974. //==========================================
  5975. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  5976. {
  5977. sendReservationStatusUpdateRequest(gun_index);
  5978. }
  5979. //==========================================
  5980. // csu trigger LogStatusNotificationReq
  5981. //==========================================
  5982. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  5983. {
  5984. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  5985. }
  5986. //==========================================
  5987. // csu trigger SignCertificateReq
  5988. //==========================================
  5989. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  5990. {
  5991. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  5992. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  5993. {
  5994. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  5995. }
  5996. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  5997. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  5998. {
  5999. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  6000. }
  6001. }
  6002. }
  6003. }
  6004. //==========================================
  6005. // send request routine
  6006. //==========================================
  6007. int sendAuthorizeRequest(int gun_index)
  6008. {
  6009. mtrace();
  6010. int result = FAIL;
  6011. char message[4096]={0};
  6012. char guid[37];
  6013. char tempdata[128]={0};
  6014. json_object *Authorize = json_object_new_object();
  6015. json_object *idToken = json_object_new_object();
  6016. DEBUG_INFO("sendAuthorizeRequest...\n");
  6017. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  6018. //Local Authorize
  6019. if ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "TRUE")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  6020. {
  6021. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  6022. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  6023. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  6024. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  6025. result = PASS;
  6026. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6027. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6028. authorizeRetryTimes = 0;
  6029. return result;
  6030. }
  6031. 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)) ||
  6032. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0)))
  6033. {
  6034. // Query idtag from cache
  6035. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  6036. // Query idtag from list
  6037. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  6038. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  6039. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  6040. {
  6041. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  6042. {
  6043. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  6044. }
  6045. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  6046. {
  6047. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  6048. }
  6049. // Return authorize result if does not connect to server
  6050. if(!ShmOCPP20Data->OcppConnStatus)
  6051. {
  6052. DEBUG_INFO("Local Authorization Fail.\n");
  6053. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  6054. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6055. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  6056. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  6057. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6058. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6059. authorizeRetryTimes = 0;
  6060. return result;
  6061. }
  6062. }
  6063. else
  6064. {
  6065. DEBUG_INFO("Local Authorization get result.\n");
  6066. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  6067. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6068. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  6069. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  6070. else
  6071. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  6072. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  6073. result = PASS;
  6074. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6075. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6076. authorizeRetryTimes = 0;
  6077. return result;
  6078. }
  6079. }
  6080. //get data from shared memory
  6081. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6082. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  6083. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  6084. json_object_object_add(Authorize, "idToken", idToken);
  6085. random_uuid(guid);
  6086. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  6087. json_object_put(Authorize);
  6088. LWS_Send(message);
  6089. sprintf(tempdata, "Authorize,%d", gun_index);
  6090. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6091. {
  6092. result = PASS;
  6093. }
  6094. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6095. return result;
  6096. }
  6097. int sendBootNotificationRequest()
  6098. {
  6099. mtrace();
  6100. int result = FAIL;
  6101. char message[4096]={0};
  6102. char guid[37]={0};
  6103. char tempdata[128]={0};
  6104. json_object *BootNotification = json_object_new_object();
  6105. json_object *chargingStation = json_object_new_object();
  6106. json_object *modem = json_object_new_object();
  6107. DEBUG_INFO("sendBootNotificationRequest...\n");
  6108. // Fill BootNotification fields
  6109. DB_getBooType();
  6110. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  6111. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6112. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  6113. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  6114. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  6115. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  6116. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  6117. {
  6118. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  6119. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  6120. json_object_object_add(chargingStation, "modem", modem);
  6121. }
  6122. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  6123. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  6124. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  6125. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  6126. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  6127. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  6128. random_uuid(guid);
  6129. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  6130. json_object_put(BootNotification);
  6131. LWS_Send(message);
  6132. sprintf(tempdata, "BootNotification,0");
  6133. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6134. {
  6135. result = PASS;
  6136. }
  6137. return result;
  6138. }
  6139. int sendClearedChargingLimitRequest(int gun_index)
  6140. {
  6141. mtrace();
  6142. int result = FAIL;
  6143. char message[4096]={0};
  6144. char guid[37]={0};
  6145. char tempdata[128]={0};
  6146. json_object *ClearedChargingLimit = json_object_new_object();
  6147. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  6148. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  6149. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  6150. random_uuid(guid);
  6151. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  6152. json_object_put(ClearedChargingLimit);
  6153. LWS_Send(message);
  6154. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  6155. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6156. {
  6157. result = PASS;
  6158. }
  6159. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  6160. return result;
  6161. }
  6162. int sendDataTransferRequest(int gun_index)
  6163. {
  6164. mtrace();
  6165. char message[1000]={0};
  6166. char guid[37]={0};
  6167. char tempdata[65]={0};
  6168. int result = FAIL;
  6169. DEBUG_INFO("sendDataTransferRequest...\n");
  6170. random_uuid(guid);
  6171. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  6172. MESSAGE_TYPE_CALL,
  6173. guid,
  6174. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  6175. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  6176. ShmOCPP20Data->DataTransfer[gun_index].data);
  6177. LWS_Send(message);
  6178. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  6179. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6180. {
  6181. result = PASS;
  6182. }
  6183. return result;
  6184. }
  6185. int sendFirmwareStatusNotificationRequest(char *status)
  6186. {
  6187. mtrace();
  6188. int result = FAIL;
  6189. char message[110]={0};
  6190. char guid[37]={0};
  6191. char tempdata[65]={0};
  6192. json_object *FirmwareStatusNotification = json_object_new_object();
  6193. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  6194. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  6195. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  6196. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  6197. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  6198. random_uuid(guid);
  6199. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6200. json_object_put(FirmwareStatusNotification);
  6201. LWS_SendNow(message);
  6202. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6203. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6204. {
  6205. result = PASS;
  6206. }
  6207. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  6208. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  6209. //record status
  6210. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  6211. {
  6212. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  6213. }
  6214. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  6215. {
  6216. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  6217. }
  6218. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  6219. {
  6220. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  6221. }
  6222. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  6223. {
  6224. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  6225. }
  6226. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  6227. {
  6228. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  6229. }
  6230. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  6231. {
  6232. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  6233. }
  6234. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  6235. {
  6236. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  6237. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6238. }
  6239. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  6240. {
  6241. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  6242. }
  6243. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  6244. {
  6245. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  6246. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6247. }
  6248. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  6249. {
  6250. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  6251. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6252. }
  6253. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  6254. {
  6255. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  6256. }
  6257. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  6258. {
  6259. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  6260. }
  6261. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  6262. {
  6263. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  6264. }
  6265. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  6266. {
  6267. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  6268. }
  6269. return result;
  6270. }
  6271. int sendGet15118EVCertificateRequest()
  6272. {
  6273. mtrace();
  6274. int result = FAIL;
  6275. char message[4096]={0};
  6276. char guid[37]={0};
  6277. char tempdata[128]={0};
  6278. json_object *Get15118EVCertificate = json_object_new_object();
  6279. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  6280. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  6281. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  6282. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  6283. random_uuid(guid);
  6284. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  6285. json_object_put(Get15118EVCertificate);
  6286. LWS_Send(message);
  6287. sprintf(tempdata, "Get15118EVCertificate,0");
  6288. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6289. {
  6290. result = PASS;
  6291. }
  6292. return result;
  6293. }
  6294. int sendGetCertificateStatusRequest()
  6295. {
  6296. mtrace();
  6297. int result = FAIL;
  6298. char message[4096]={0};
  6299. char guid[37]={0};
  6300. char tempdata[128]={0};
  6301. json_object *GetCertificateStatus = json_object_new_object();
  6302. json_object *ocspRequestData = json_object_new_object();
  6303. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  6304. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  6305. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  6306. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  6307. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  6308. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  6309. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  6310. random_uuid(guid);
  6311. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  6312. json_object_put(GetCertificateStatus);
  6313. LWS_Send(message);
  6314. sprintf(tempdata, "GetCertificateStatus,0");
  6315. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6316. {
  6317. result = PASS;
  6318. }
  6319. return result;
  6320. }
  6321. int sendHeartbeatRequest()
  6322. {
  6323. mtrace();
  6324. int result = FAIL;
  6325. char message[40096]={0};
  6326. char guid[37]={0};
  6327. char tempdata[128]={0};
  6328. DEBUG_INFO("sendHeartbeatRequest...\n");
  6329. random_uuid(guid);
  6330. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6331. , MESSAGE_TYPE_CALL
  6332. , guid );
  6333. LWS_Send(message);
  6334. sprintf(tempdata, "Heartbeat,%d", 0);
  6335. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6336. {
  6337. result = PASS;
  6338. }
  6339. return result;
  6340. }
  6341. int sendLogStatusNotificationRequest(char *status)
  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 *LogStatusNotification = json_object_new_object();
  6349. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6350. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  6351. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  6352. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  6353. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  6354. random_uuid(guid);
  6355. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6356. json_object_put(LogStatusNotification);
  6357. LWS_SendNow(message);
  6358. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6359. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6360. {
  6361. result = PASS;
  6362. }
  6363. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  6364. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  6365. //record status
  6366. if(strcmp(status,"BadMessage")==0)
  6367. {
  6368. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  6369. }
  6370. else if(strcmp(status,"Idle")==0)
  6371. {
  6372. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  6373. }
  6374. else if(strcmp(status,"NotSupportedOperation")==0)
  6375. {
  6376. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  6377. }
  6378. else if(strcmp(status,"PermissionDenied")==0)
  6379. {
  6380. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  6381. }
  6382. else if(strcmp(status,"Uploaded")==0)
  6383. {
  6384. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  6385. }
  6386. else if(strcmp(status,"UploadFailure")==0)
  6387. {
  6388. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  6389. }
  6390. else if(strcmp(status,"Uploading")==0)
  6391. {
  6392. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  6393. }
  6394. return result;
  6395. }
  6396. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  6397. {
  6398. mtrace();
  6399. int result = FAIL;
  6400. char guid[37]={0};
  6401. char tempdata[65]={0};
  6402. int tempIndex = 0;
  6403. json_object *MeterValueReq = json_object_new_object();
  6404. json_object *meterValues = json_object_new_array();
  6405. json_object *sampledValues = json_object_new_array();
  6406. DEBUG_INFO("sendMeterValuesRequest...\n");
  6407. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6408. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  6409. //set value
  6410. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  6411. //UTC Date time
  6412. struct timeval tmnow;
  6413. struct tm *tm;
  6414. char buf[28];//, usec_buf[6];
  6415. gettimeofday(&tmnow, NULL);
  6416. time_t t;
  6417. t = time(NULL);
  6418. /*UTC time and date*/
  6419. tm = gmtime(&t);
  6420. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6421. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  6422. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6423. //idx_sample=0;
  6424. //********************************(1)Current.Import L1************************************************/
  6425. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  6426. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  6427. (dataType == ReadingContextEnumType_Trigger))
  6428. {
  6429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6430. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6431. {
  6432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6433. {
  6434. tempIndex = ((gun_index==2) ? 1: 0);
  6435. }
  6436. else
  6437. {
  6438. tempIndex = gun_index;
  6439. }
  6440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6441. {
  6442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6443. {
  6444. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent*100))/100.0;
  6445. }
  6446. }
  6447. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6448. }
  6449. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6450. {
  6451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6452. {
  6453. tempIndex = ((gun_index==2) ? 1: 0);
  6454. }
  6455. else
  6456. {
  6457. tempIndex = gun_index;
  6458. }
  6459. for (int index = 0; index < CCS_QUANTITY; index++)
  6460. {
  6461. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6462. {
  6463. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent*100))/100.0;
  6464. }
  6465. }
  6466. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6467. }
  6468. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6469. {
  6470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6471. {
  6472. tempIndex = ((gun_index==2) ? 1: 0);
  6473. }
  6474. else
  6475. {
  6476. tempIndex = gun_index;
  6477. }
  6478. for (int index = 0; index < GB_QUANTITY; index++)
  6479. {
  6480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6481. {
  6482. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent*100))/100.0;
  6483. }
  6484. }
  6485. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6486. }
  6487. else if(gunType[gun_index] == GUN_TYPE_DO)
  6488. {
  6489. tempIndex = gun_index;
  6490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6491. {
  6492. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6493. {
  6494. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent*100))/100.0;
  6495. }
  6496. }
  6497. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6498. }
  6499. else
  6500. {
  6501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6502. {
  6503. tempIndex = 2;
  6504. }
  6505. else
  6506. {
  6507. tempIndex = gun_index;
  6508. }
  6509. for (int index = 0; index < AC_QUANTITY; index++)
  6510. {
  6511. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6512. {
  6513. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent*100))/100.0;
  6514. }
  6515. }
  6516. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6517. }
  6518. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  6519. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6520. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6521. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  6522. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  6523. }
  6524. //idx_sample=1;
  6525. //********************************(2)Energy.Active.Import.Register ************************************************/
  6526. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  6527. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  6528. (dataType == ReadingContextEnumType_Trigger))
  6529. {
  6530. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6531. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6532. {
  6533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6534. {
  6535. tempIndex = ((gun_index==2) ? 1: 0);
  6536. }
  6537. else
  6538. {
  6539. tempIndex = gun_index;
  6540. }
  6541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6542. {
  6543. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6544. {
  6545. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*100))/100.0;
  6546. }
  6547. }
  6548. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6549. }
  6550. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6551. {
  6552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6553. {
  6554. tempIndex = ((gun_index==2) ? 1: 0);
  6555. }
  6556. else
  6557. {
  6558. tempIndex = gun_index;
  6559. }
  6560. for (int index = 0; index < CCS_QUANTITY; index++)
  6561. {
  6562. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6563. {
  6564. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*100))/100.0;
  6565. }
  6566. }
  6567. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6568. }
  6569. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6570. {
  6571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6572. {
  6573. tempIndex = ((gun_index==2) ? 1: 0);
  6574. }
  6575. else
  6576. {
  6577. tempIndex = gun_index;
  6578. }
  6579. for (int index = 0; index < GB_QUANTITY; index++)
  6580. {
  6581. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6582. {
  6583. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*100))/100.0;
  6584. }
  6585. }
  6586. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6587. }
  6588. else if(gunType[gun_index] == GUN_TYPE_DO)
  6589. {
  6590. tempIndex = gun_index;
  6591. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6592. {
  6593. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6594. {
  6595. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*100))/100.0;
  6596. }
  6597. }
  6598. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6599. }
  6600. else
  6601. {
  6602. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6603. {
  6604. tempIndex = 2;
  6605. }
  6606. else
  6607. {
  6608. tempIndex = gun_index;
  6609. }
  6610. for (int index = 0; index < AC_QUANTITY; index++)
  6611. {
  6612. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6613. {
  6614. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*100))/100.0;
  6615. }
  6616. }
  6617. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6618. }
  6619. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  6620. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  6621. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6622. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  6623. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  6624. }
  6625. //idx_sample=2;
  6626. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6627. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  6628. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  6629. (dataType == ReadingContextEnumType_Trigger))
  6630. {
  6631. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6632. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6633. {
  6634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6635. {
  6636. tempIndex = ((gun_index==2) ? 1: 0);
  6637. }
  6638. else
  6639. {
  6640. tempIndex = gun_index;
  6641. }
  6642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6643. {
  6644. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6645. {
  6646. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*100))/100.0;
  6647. }
  6648. } // END OF FOR CHAdeMO_QUANTITY
  6649. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6650. }
  6651. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6652. {
  6653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6654. {
  6655. tempIndex = ((gun_index==2) ? 1: 0);
  6656. }
  6657. else
  6658. {
  6659. tempIndex = gun_index;
  6660. }
  6661. for (int index = 0; index < CCS_QUANTITY; index++)
  6662. {
  6663. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6664. {
  6665. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*100))/100.0;
  6666. }
  6667. } // END OF CCS_QUANTITY
  6668. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6669. }
  6670. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6671. {
  6672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6673. {
  6674. tempIndex = ((gun_index==2) ? 1: 0);
  6675. }
  6676. else
  6677. {
  6678. tempIndex = gun_index;
  6679. }
  6680. for (int index = 0; index < GB_QUANTITY; index++)
  6681. {
  6682. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6683. {
  6684. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*100))/100.0;
  6685. }
  6686. } // END OF GB_QUANTITY
  6687. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6688. }
  6689. else if(gunType[gun_index] == GUN_TYPE_DO)
  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. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*100))/100.0;
  6697. }
  6698. }
  6699. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6700. }
  6701. else
  6702. {
  6703. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6704. {
  6705. tempIndex = 2;
  6706. }
  6707. else
  6708. {
  6709. tempIndex = gun_index;
  6710. }
  6711. for (int index = 0; index < AC_QUANTITY; index++)
  6712. {
  6713. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6714. {
  6715. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*100))/100.0;
  6716. }
  6717. }
  6718. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6719. }
  6720. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  6721. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  6722. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6723. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  6724. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  6725. }
  6726. //idx_sample=3;
  6727. //********************************(4)Power.Active.Import************************************************/
  6728. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  6729. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  6730. (dataType == ReadingContextEnumType_Trigger))
  6731. {
  6732. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6733. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6734. {
  6735. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6736. {
  6737. tempIndex = ((gun_index==2) ? 1: 0);
  6738. }
  6739. else
  6740. {
  6741. tempIndex = gun_index;
  6742. }
  6743. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6744. {
  6745. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6746. {
  6747. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower*100))/100.0;
  6748. }
  6749. } // END OF FOR
  6750. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6751. }
  6752. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6753. {
  6754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6755. {
  6756. tempIndex = ((gun_index==2) ? 1: 0);
  6757. }
  6758. else
  6759. {
  6760. tempIndex = gun_index;
  6761. }
  6762. for (int index = 0; index < CCS_QUANTITY; index++)
  6763. {
  6764. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6765. {
  6766. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower*100))/100.0;
  6767. }
  6768. }
  6769. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6770. }
  6771. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6772. {
  6773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6774. {
  6775. tempIndex = ((gun_index==2) ? 1: 0);
  6776. }
  6777. else
  6778. {
  6779. tempIndex = gun_index;
  6780. }
  6781. for (int index = 0; index < GB_QUANTITY; index++)
  6782. {
  6783. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6784. {
  6785. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6786. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower*100))/100.0;
  6787. }
  6788. }
  6789. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6790. }
  6791. else if(gunType[gun_index] == GUN_TYPE_DO)
  6792. {
  6793. tempIndex = gun_index;
  6794. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6795. {
  6796. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6797. {
  6798. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6799. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower*100))/100.0;
  6800. }
  6801. }
  6802. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6803. }
  6804. else
  6805. {
  6806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6807. {
  6808. tempIndex = 2;
  6809. }
  6810. else
  6811. {
  6812. tempIndex = gun_index;
  6813. }
  6814. for (int index = 0; index < AC_QUANTITY; index++)
  6815. {
  6816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6817. {
  6818. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower*100))/100.0;
  6819. }
  6820. }
  6821. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6822. }
  6823. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  6824. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  6825. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6826. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  6827. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  6828. }
  6829. //idx_sample=4;
  6830. //***********************************************(5)VOLTAGE L1******************************************************/
  6831. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  6832. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  6833. (dataType == ReadingContextEnumType_Trigger))
  6834. {
  6835. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6836. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6837. {
  6838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6839. {
  6840. tempIndex = ((gun_index==2) ? 1: 0);
  6841. }
  6842. else
  6843. {
  6844. tempIndex = gun_index;
  6845. }
  6846. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6847. {
  6848. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6849. {
  6850. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage*100))/100.0;
  6851. }
  6852. }
  6853. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6854. }
  6855. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6856. {
  6857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6858. {
  6859. tempIndex = ((gun_index==2) ? 1: 0);
  6860. }
  6861. else
  6862. {
  6863. tempIndex = gun_index;
  6864. }
  6865. for (int index = 0; index < CCS_QUANTITY; index++)
  6866. {
  6867. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6868. {
  6869. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage*100))/100.0;
  6870. }
  6871. }
  6872. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6873. }
  6874. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6875. {
  6876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6877. {
  6878. tempIndex = ((gun_index==2) ? 1: 0);
  6879. }
  6880. else
  6881. {
  6882. tempIndex = gun_index;
  6883. }
  6884. for (int index = 0; index < GB_QUANTITY; index++)
  6885. {
  6886. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6887. {
  6888. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage*100))/100.0;
  6889. }
  6890. }
  6891. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6892. }
  6893. else if(gunType[gun_index] == GUN_TYPE_DO)
  6894. {
  6895. tempIndex = gun_index;
  6896. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6899. {
  6900. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage*100))/100.0;
  6901. }
  6902. }
  6903. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6904. }
  6905. else
  6906. {
  6907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6908. {
  6909. tempIndex = 2;
  6910. }
  6911. else
  6912. {
  6913. tempIndex = gun_index;
  6914. }
  6915. for (int index = 0; index < AC_QUANTITY; index++)
  6916. {
  6917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6918. {
  6919. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage*100))/100.0;
  6920. }
  6921. }
  6922. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6923. }
  6924. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  6925. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6926. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6927. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  6928. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  6929. }
  6930. //***********************************************(6)SOC******************************************************/
  6931. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  6932. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  6933. (dataType == ReadingContextEnumType_Trigger))
  6934. {
  6935. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  6936. {
  6937. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6938. {
  6939. tempIndex = ((gun_index==2) ? 1: 0);
  6940. }
  6941. else
  6942. {
  6943. tempIndex = gun_index;
  6944. }
  6945. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6946. {
  6947. //tempIndex = ((gun_index==2) ? 1: 0);
  6948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6949. {
  6950. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6951. {
  6952. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  6953. }
  6954. }
  6955. }
  6956. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6957. {
  6958. //tempIndex = ((gun_index==2) ? 1: 0);
  6959. for (int index = 0; index < CCS_QUANTITY; index++)
  6960. {
  6961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6962. {
  6963. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  6964. }
  6965. }
  6966. }
  6967. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6968. {
  6969. //tempIndex = ((gun_index==2) ? 1: 0);
  6970. for (int index = 0; index < GB_QUANTITY; index++)
  6971. {
  6972. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6973. {
  6974. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  6975. }
  6976. }
  6977. }
  6978. else if(gunType[gun_index] == GUN_TYPE_DO)
  6979. {
  6980. //tempIndex = ((gun_index==2) ? 1: 0);
  6981. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6982. {
  6983. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6984. {
  6985. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  6986. }
  6987. }
  6988. }
  6989. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  6990. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  6991. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6992. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  6993. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  6994. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  6995. }
  6996. }
  6997. //********************************(7)Current.Import L2************************************************/
  6998. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  6999. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7000. (dataType == ReadingContextEnumType_Trigger))
  7001. {
  7002. // Only for AC 3 phase
  7003. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7004. {
  7005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7006. {
  7007. tempIndex = 2;
  7008. }
  7009. else
  7010. {
  7011. tempIndex = gun_index;
  7012. }
  7013. for (int index = 0; index < AC_QUANTITY; index++)
  7014. {
  7015. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7016. {
  7017. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2*100))/100.0;
  7018. }
  7019. }
  7020. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  7021. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  7022. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7023. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7024. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  7025. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  7026. }
  7027. }
  7028. //********************************(8)Current.Import L3************************************************/
  7029. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7030. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7031. (dataType == ReadingContextEnumType_Trigger))
  7032. {
  7033. // Only for AC 3 phase
  7034. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7035. {
  7036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7037. {
  7038. tempIndex = 2;
  7039. }
  7040. else
  7041. {
  7042. tempIndex = gun_index;
  7043. }
  7044. for (int index = 0; index < AC_QUANTITY; index++)
  7045. {
  7046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7047. {
  7048. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3*100))/100.0;
  7049. }
  7050. }
  7051. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7052. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  7053. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7054. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7055. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  7056. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  7057. }
  7058. }
  7059. //***********************************************(9)VOLTAGE L2******************************************************/
  7060. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7061. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7062. (dataType == ReadingContextEnumType_Trigger))
  7063. {
  7064. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7065. {
  7066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7067. {
  7068. tempIndex = 2;
  7069. }
  7070. else
  7071. {
  7072. tempIndex = gun_index;
  7073. }
  7074. for (int index = 0; index < AC_QUANTITY; index++)
  7075. {
  7076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7077. {
  7078. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2*100))/100.0;
  7079. }
  7080. }
  7081. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  7082. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  7083. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  7084. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7085. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  7086. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  7087. }
  7088. }
  7089. //***********************************************(10)VOLTAGE L3******************************************************/
  7090. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7091. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7092. (dataType == ReadingContextEnumType_Trigger))
  7093. {
  7094. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7095. {
  7096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7097. {
  7098. tempIndex = 2;
  7099. }
  7100. else
  7101. {
  7102. tempIndex = gun_index;
  7103. }
  7104. for (int index = 0; index < AC_QUANTITY; index++)
  7105. {
  7106. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7107. {
  7108. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3*100))/100.0;
  7109. }
  7110. }
  7111. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7112. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  7113. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  7114. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7115. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  7116. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  7117. }
  7118. }
  7119. //***********************************************(11)Current.Offered******************************************************/
  7120. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  7121. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  7122. (dataType == ReadingContextEnumType_Trigger))
  7123. {
  7124. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7125. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7126. {
  7127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7128. {
  7129. tempIndex = ((gun_index==2) ? 1: 0);
  7130. }
  7131. else
  7132. {
  7133. tempIndex = gun_index;
  7134. }
  7135. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7136. {
  7137. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7138. {
  7139. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10);
  7140. }
  7141. } // END OF FOR
  7142. }
  7143. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7144. {
  7145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7146. {
  7147. tempIndex = ((gun_index==2) ? 1: 0);
  7148. }
  7149. else
  7150. {
  7151. tempIndex = gun_index;
  7152. }
  7153. for (int index = 0; index < CCS_QUANTITY; index++)
  7154. {
  7155. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7156. {
  7157. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10);
  7158. }
  7159. }
  7160. }
  7161. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7162. {
  7163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7164. {
  7165. tempIndex = ((gun_index==2) ? 1: 0);
  7166. }
  7167. else
  7168. {
  7169. tempIndex = gun_index;
  7170. }
  7171. for (int index = 0; index < GB_QUANTITY; index++)
  7172. {
  7173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7174. {
  7175. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7176. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10);;
  7177. }
  7178. }
  7179. }
  7180. else if(gunType[gun_index] == GUN_TYPE_DO)
  7181. {
  7182. tempIndex = gun_index;
  7183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7184. {
  7185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7186. {
  7187. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7188. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10);;
  7189. }
  7190. }
  7191. }
  7192. else
  7193. {
  7194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7195. {
  7196. tempIndex = 2;
  7197. }
  7198. else
  7199. {
  7200. tempIndex = gun_index;
  7201. }
  7202. for (int index = 0; index < AC_QUANTITY; index++)
  7203. {
  7204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7205. {
  7206. uint16_t currentOffer;
  7207. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7208. {
  7209. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7210. }
  7211. else
  7212. {
  7213. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7214. }
  7215. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  7216. }
  7217. }
  7218. }
  7219. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  7220. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  7221. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7222. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  7223. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  7224. }
  7225. //***********************************************(12)Power.Offered******************************************************/
  7226. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  7227. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  7228. (dataType == ReadingContextEnumType_Trigger))
  7229. {
  7230. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7231. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7232. {
  7233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7234. {
  7235. tempIndex = ((gun_index==2) ? 1: 0);
  7236. }
  7237. else
  7238. {
  7239. tempIndex = gun_index;
  7240. }
  7241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7244. {
  7245. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100);
  7246. }
  7247. } // END OF FOR
  7248. }
  7249. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7250. {
  7251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7252. {
  7253. tempIndex = ((gun_index==2) ? 1: 0);
  7254. }
  7255. else
  7256. {
  7257. tempIndex = gun_index;
  7258. }
  7259. for (int index = 0; index < CCS_QUANTITY; index++)
  7260. {
  7261. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7262. {
  7263. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100);
  7264. }
  7265. }
  7266. }
  7267. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7268. {
  7269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7270. {
  7271. tempIndex = ((gun_index==2) ? 1: 0);
  7272. }
  7273. else
  7274. {
  7275. tempIndex = gun_index;
  7276. }
  7277. for (int index = 0; index < GB_QUANTITY; index++)
  7278. {
  7279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7280. {
  7281. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7282. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100);
  7283. }
  7284. }
  7285. }
  7286. else if(gunType[gun_index] == GUN_TYPE_DO)
  7287. {
  7288. tempIndex = gun_index;
  7289. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7290. {
  7291. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7292. {
  7293. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7294. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100);
  7295. }
  7296. }
  7297. }
  7298. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  7299. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  7300. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7301. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  7302. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  7303. }
  7304. // Message create ====================================================================================================
  7305. random_uuid(guid);
  7306. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  7307. {
  7308. json_object *meterValue = json_object_new_object();
  7309. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  7310. {
  7311. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  7312. {
  7313. json_object *sampledValue = json_object_new_object();
  7314. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  7315. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  7316. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  7317. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  7318. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  7319. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  7320. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  7321. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  7322. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  7323. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  7324. {
  7325. json_object *unitOfMeasure = json_object_new_object();
  7326. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  7327. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  7328. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  7329. }
  7330. json_object_array_add(sampledValues, sampledValue);
  7331. }
  7332. }
  7333. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  7334. json_object_object_add(meterValue, "sampledValue", sampledValues);
  7335. json_object_array_add(meterValues, meterValue);
  7336. idxMeter++;
  7337. }
  7338. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  7339. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  7340. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  7341. ,MESSAGE_TYPE_CALL
  7342. ,guid
  7343. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7344. json_object_put(MeterValueReq);
  7345. if((dataType != ReadingContextEnumType_Trigger) &&
  7346. (dataType != ReadingContextEnumType_Sample_Clock))
  7347. {
  7348. // Transaction meter value send by TransactionEvent message
  7349. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  7350. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  7351. result = PASS;
  7352. }
  7353. else
  7354. {
  7355. // Put request guid to hash map
  7356. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7357. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7358. {
  7359. result = PASS;
  7360. }
  7361. if((dataType != ReadingContextEnumType_Trigger) &&
  7362. (dataType != ReadingContextEnumType_Sample_Clock))
  7363. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  7364. else
  7365. {
  7366. if(FirstHeartBeat)
  7367. LWS_Send(queuedata +2);
  7368. }
  7369. }
  7370. return result;
  7371. }
  7372. int sendNotifyChargingLimitRequest(int gun_index)
  7373. {
  7374. mtrace();
  7375. int result = FAIL;
  7376. char message[4096]={0};
  7377. char guid[37]={0};
  7378. char tempdata[128]={0};
  7379. json_object *NotifyChargingLimit = json_object_new_object();
  7380. json_object *chargingLimit = json_object_new_object();
  7381. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  7382. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  7383. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  7384. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  7385. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  7386. random_uuid(guid);
  7387. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  7388. json_object_put(NotifyChargingLimit);
  7389. LWS_Send(message);
  7390. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  7391. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7392. {
  7393. result = PASS;
  7394. }
  7395. return result;
  7396. }
  7397. int sendNotifyCustomerInformationRequest()
  7398. {
  7399. mtrace();
  7400. int result = FAIL;
  7401. char message[4096]={0};
  7402. char guid[37]={0};
  7403. char tempdata[128]={0};
  7404. json_object *NotifyCustomerInformation = json_object_new_object();
  7405. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  7406. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  7407. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  7408. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  7409. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  7410. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  7411. random_uuid(guid);
  7412. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  7413. json_object_put(NotifyCustomerInformation);
  7414. LWS_Send(message);
  7415. sprintf(tempdata, "NotifyCustomerInformation,0");
  7416. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7417. {
  7418. result = PASS;
  7419. }
  7420. return result;
  7421. }
  7422. int sendNotifyDisplayMessagesRequest()
  7423. {
  7424. mtrace();
  7425. int result = FAIL;
  7426. char message[4096]={0};
  7427. char guid[37]={0};
  7428. char tempdata[128]={0};
  7429. json_object *NotifyDisplayMessages = json_object_new_object();
  7430. json_object *messageInfos = json_object_new_array();
  7431. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  7432. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  7433. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  7434. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  7435. {
  7436. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  7437. {
  7438. json_object *messageInfo = json_object_new_object();
  7439. json_object *message = json_object_new_object();
  7440. json_object *display = json_object_new_object();
  7441. json_object *evse = json_object_new_object();
  7442. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  7443. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  7444. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  7445. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  7446. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  7447. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  7448. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  7449. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  7450. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  7451. json_object_object_add(messageInfo, "message", message);
  7452. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  7453. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  7454. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  7455. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  7456. json_object_object_add(display, "evse",evse);
  7457. json_object_object_add(messageInfo, "evse", display);
  7458. json_object_array_add(messageInfos, messageInfo);
  7459. }
  7460. }
  7461. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  7462. random_uuid(guid);
  7463. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  7464. json_object_put(NotifyDisplayMessages);
  7465. LWS_Send(message);
  7466. sprintf(tempdata, "NotifyDisplayMessages,0");
  7467. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7468. {
  7469. result = PASS;
  7470. }
  7471. return result;
  7472. }
  7473. int sendNotifyEVChargingNeedsRequest(int gun_index)
  7474. {
  7475. mtrace();
  7476. int result = FAIL;
  7477. char message[4096]={0};
  7478. char guid[37]={0};
  7479. char tempdata[128]={0};
  7480. json_object *NotifyEVChargingNeeds = json_object_new_object();
  7481. json_object *chargingNeeds = json_object_new_object();
  7482. json_object *acChargingParameters = json_object_new_object();
  7483. json_object *dcChargingParameters = json_object_new_object();
  7484. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  7485. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  7486. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  7487. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  7488. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  7489. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  7490. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  7491. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  7492. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  7493. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  7494. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  7495. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  7496. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  7497. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  7498. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  7499. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  7500. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  7501. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  7502. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  7503. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  7504. random_uuid(guid);
  7505. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  7506. json_object_put(NotifyEVChargingNeeds);
  7507. LWS_Send(message);
  7508. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  7509. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7510. {
  7511. result = PASS;
  7512. }
  7513. return result;
  7514. }
  7515. int sendNotifyEVChargingScheduleRequest(int gun_index)
  7516. {
  7517. mtrace();
  7518. int result = FAIL;
  7519. char message[4096]={0};
  7520. char guid[37]={0};
  7521. char tempdata[128]={0};
  7522. json_object *NotifyEVChargingSchedule = json_object_new_object();
  7523. json_object *chargingSchedule = json_object_new_object();
  7524. json_object *periods = json_object_new_array();
  7525. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  7526. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  7527. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  7528. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  7529. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  7530. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  7531. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  7532. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  7533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  7534. {
  7535. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  7536. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  7537. {
  7538. json_object *Period = json_object_new_object();
  7539. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  7540. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  7541. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  7542. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  7543. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  7544. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  7545. json_object_array_add(periods, Period);
  7546. }
  7547. }
  7548. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  7549. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  7550. random_uuid(guid);
  7551. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  7552. json_object_put(NotifyEVChargingSchedule);
  7553. LWS_Send(message);
  7554. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  7555. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7556. {
  7557. result = PASS;
  7558. }
  7559. return result;
  7560. }
  7561. int sendNotifyEventRequest()
  7562. {
  7563. mtrace();
  7564. int result = FAIL;
  7565. char message[4096]={0};
  7566. char guid[37]={0};
  7567. char tempdata[128]={0};
  7568. json_object *NotifyEvent = json_object_new_object();
  7569. json_object *eventDatas = json_object_new_array();
  7570. DEBUG_INFO("sendNotifyEventRequest...\n");
  7571. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  7572. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  7573. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  7574. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  7575. {
  7576. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  7577. {
  7578. json_object *eventData = json_object_new_object();
  7579. json_object *component = json_object_new_object();
  7580. json_object *evse = json_object_new_object();
  7581. json_object *variable = json_object_new_object();
  7582. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  7583. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  7584. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  7585. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  7586. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  7587. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  7588. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  7589. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  7590. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  7591. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  7592. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  7593. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  7594. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  7595. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  7596. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  7597. json_object_object_add(component, "evse",evse);
  7598. json_object_object_add(eventData, "component", component);
  7599. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  7600. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  7601. json_object_object_add(eventData, "variable", variable);
  7602. json_object_array_add(eventDatas, eventData);
  7603. }
  7604. }
  7605. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  7606. random_uuid(guid);
  7607. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  7608. json_object_put(NotifyEvent);
  7609. LWS_Send(message);
  7610. sprintf(tempdata, "NotifyEvent,0");
  7611. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7612. {
  7613. result = PASS;
  7614. }
  7615. return result;
  7616. }
  7617. int sendNotifyMonitoringReportRequest()
  7618. {
  7619. mtrace();
  7620. int result = FAIL;
  7621. char message[4096]={0};
  7622. char guid[37]={0};
  7623. char tempdata[128]={0};
  7624. json_object *NotifyMonitoringReport = json_object_new_object();
  7625. json_object *monitors = json_object_new_array();
  7626. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  7627. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  7628. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  7629. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  7630. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  7631. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  7632. {
  7633. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  7634. {
  7635. json_object *monitor = json_object_new_object();
  7636. json_object *component = json_object_new_object();
  7637. json_object *evse = json_object_new_object();
  7638. json_object *variable = json_object_new_object();
  7639. json_object *variableMonitorings = json_object_new_array();
  7640. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  7641. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  7642. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  7643. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  7644. json_object_object_add(component, "evse",evse);
  7645. json_object_object_add(monitor, "component", component);
  7646. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  7647. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  7648. json_object_object_add(monitor, "variable", variable);
  7649. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  7650. {
  7651. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  7652. {
  7653. json_object *variableMonitoring = json_object_new_object();
  7654. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  7655. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  7656. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  7657. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  7658. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  7659. json_object_array_add(variableMonitorings, variableMonitoring);
  7660. }
  7661. }
  7662. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  7663. json_object_array_add(monitors, monitor);
  7664. }
  7665. }
  7666. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  7667. random_uuid(guid);
  7668. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  7669. json_object_put(NotifyMonitoringReport);
  7670. LWS_Send(message);
  7671. sprintf(tempdata, "NotifyMonitoringReport,0");
  7672. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7673. {
  7674. result = PASS;
  7675. }
  7676. return result;
  7677. }
  7678. int sendNotifyReportRequest()
  7679. {
  7680. mtrace();
  7681. int result = FAIL;
  7682. char message[4096]={0};
  7683. char guid[37]={0};
  7684. char tempdata[128]={0};
  7685. json_object *NotifyReport = json_object_new_object();
  7686. json_object *reportDatas = json_object_new_array();
  7687. DEBUG_INFO("sendNotifyReportRequest...\n");
  7688. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  7689. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  7690. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  7691. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  7692. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  7693. {
  7694. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  7695. {
  7696. json_object *reportData = json_object_new_object();
  7697. json_object *component = json_object_new_object();
  7698. json_object *evse = json_object_new_object();
  7699. json_object *variable = json_object_new_object();
  7700. json_object *variableAttributes = json_object_new_array();
  7701. json_object *variableCharacteristics = json_object_new_object();
  7702. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  7703. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  7704. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  7705. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  7706. json_object_object_add(component, "evse",evse);
  7707. json_object_object_add(reportData, "component", component);
  7708. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  7709. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  7710. json_object_object_add(reportData, "variable",variable);
  7711. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  7712. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  7713. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  7714. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  7715. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  7716. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  7717. {
  7718. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  7719. {
  7720. json_object *variableAttribute = json_object_new_object();
  7721. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  7722. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  7723. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  7724. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  7725. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  7726. json_object_array_add(variableAttributes, variableAttribute);
  7727. }
  7728. }
  7729. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  7730. json_object_array_add(reportDatas, reportData);
  7731. }
  7732. }
  7733. json_object_object_add(NotifyReport, "reportData", reportDatas);
  7734. random_uuid(guid);
  7735. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  7736. json_object_put(NotifyReport);
  7737. LWS_SendNow(message);
  7738. sprintf(tempdata, "NotifyReport,0");
  7739. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7740. {
  7741. result = PASS;
  7742. }
  7743. return result;
  7744. }
  7745. int sendPublishFirmwareStatusNotificationRequest()
  7746. {
  7747. mtrace();
  7748. int result = FAIL;
  7749. char message[4096]={0};
  7750. char guid[37]={0};
  7751. char tempdata[128]={0};
  7752. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  7753. json_object *locations = json_object_new_array();
  7754. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  7755. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  7756. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  7757. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  7758. {
  7759. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  7760. }
  7761. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  7762. random_uuid(guid);
  7763. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7764. json_object_put(PublishFirmwareStatusNotification);
  7765. LWS_Send(message);
  7766. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  7767. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7768. {
  7769. result = PASS;
  7770. }
  7771. return result;
  7772. }
  7773. int sendReportChargingProfilesRequest(int gun_index)
  7774. {
  7775. mtrace();
  7776. int result = FAIL;
  7777. char message[4096]={0};
  7778. char guid[37]={0};
  7779. char tempdata[128]={0};
  7780. json_object *ReportChargingProfiles = json_object_new_object();
  7781. json_object *chargingProfiles = json_object_new_array();
  7782. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  7783. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  7784. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  7785. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  7786. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  7787. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  7788. {
  7789. json_object *chargingProfile = json_object_new_object();
  7790. json_object *chargingSchedules = json_object_new_array();
  7791. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  7792. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  7793. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  7794. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  7795. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  7796. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  7797. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  7798. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  7799. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  7800. {
  7801. json_object *chargingSchedule = json_object_new_object();
  7802. json_object *chargingSchedulePeriods = json_object_new_array();
  7803. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  7804. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  7805. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  7806. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  7807. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  7808. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  7809. {
  7810. json_object *chargingSchedulePeriod = json_object_new_object();
  7811. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  7812. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  7813. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  7814. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  7815. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  7816. }
  7817. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  7818. json_object_array_add(chargingSchedules, chargingSchedule);
  7819. }
  7820. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  7821. json_object_array_add(chargingProfiles, chargingProfile);
  7822. }
  7823. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  7824. random_uuid(guid);
  7825. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  7826. json_object_put(ReportChargingProfiles);
  7827. LWS_Send(message);
  7828. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  7829. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7830. {
  7831. result = PASS;
  7832. }
  7833. return result;
  7834. }
  7835. int sendReservationStatusUpdateRequest(int gun_index)
  7836. {
  7837. mtrace();
  7838. int result = FAIL;
  7839. char message[4096]={0};
  7840. char guid[37]={0};
  7841. char tempdata[128]={0};
  7842. json_object *ReservationStatusUpdate = json_object_new_object();
  7843. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  7844. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  7845. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  7846. random_uuid(guid);
  7847. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  7848. json_object_put(ReservationStatusUpdate);
  7849. LWS_Send(message);
  7850. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  7851. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7852. {
  7853. result = PASS;
  7854. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  7855. }
  7856. return result;
  7857. }
  7858. int sendSecurityEventNotificationRequest()
  7859. {
  7860. mtrace();
  7861. int result = FAIL;
  7862. char message[4096]={0};
  7863. char guid[37]={0};
  7864. char tempdata[128]={0};
  7865. json_object *SecurityEventNotification = json_object_new_object();
  7866. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7867. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  7868. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  7869. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  7870. random_uuid(guid);
  7871. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7872. json_object_put(SecurityEventNotification);
  7873. LWS_Send(message);
  7874. sprintf(tempdata, "SecurityEventNotification,0");
  7875. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7876. {
  7877. result = PASS;
  7878. }
  7879. return result;
  7880. }
  7881. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  7882. {
  7883. mtrace();
  7884. int result = FAIL;
  7885. char message[4096]={0};
  7886. char guid[37]={0};
  7887. char tempdata[128]={0};
  7888. json_object *SignCertificate = json_object_new_object();
  7889. DEBUG_INFO("sendSignCertificateRequest...\n");
  7890. // Read csr file content
  7891. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  7892. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  7893. char *line = NULL;
  7894. size_t len = 0;
  7895. while(getline(&line, &len, fp) != -1)
  7896. {
  7897. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7898. {
  7899. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  7900. }
  7901. }
  7902. fclose(fp);
  7903. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  7904. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  7905. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  7906. random_uuid(guid);
  7907. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7908. json_object_put(SignCertificate);
  7909. LWS_Send(message);
  7910. sprintf(tempdata, "SignCertificate,0");
  7911. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7912. {
  7913. result = PASS;
  7914. }
  7915. return result;
  7916. }
  7917. int sendStatusNotificationRequest(int gun_index)
  7918. {
  7919. mtrace();
  7920. int result = FAIL;
  7921. char message[600]={0};
  7922. char guid[37];
  7923. int currentStatus = 0;
  7924. struct timeval tmnow;
  7925. struct tm *tm;
  7926. char buf[28];//, usec_buf[6];
  7927. char tempdata[65]={0};
  7928. int tempIndex = 0;
  7929. uint8_t isStateChanged = TRUE;
  7930. DEBUG_INFO("sendStatusNotificationRequest...\n");
  7931. gettimeofday(&tmnow, NULL);
  7932. time_t t;
  7933. t = time(NULL);
  7934. /*UTC time and date*/
  7935. tm = gmtime(&t);
  7936. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7937. #if 0 // remove temporally
  7938. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  7939. strcat(buf,".");
  7940. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  7941. strcat(buf,usec_buf);
  7942. #endif
  7943. printf("%s",buf);
  7944. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  7945. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  7946. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  7947. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  7948. /*
  7949. enum _SYSTEM_STATUS
  7950. {
  7951. S_BOOTING = 0,
  7952. S_IDLE, = 1
  7953. S_AUTHORIZING, =2
  7954. S_REASSIGN_CHECK, =3
  7955. S_REASSIGN, =4
  7956. S_PRECHARGE, =5
  7957. S_PREPARING_FOR_EV, =6
  7958. S_PREPARING_FOR_EVSE, =7
  7959. S_CHARGING, =8
  7960. S_TERMINATING, =9
  7961. S_COMPLETE, =10
  7962. S_ALARM, =11
  7963. S_FAULT =12
  7964. }
  7965. */
  7966. //check Transaction active
  7967. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7968. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7969. {
  7970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7971. {
  7972. tempIndex = ((gun_index==2) ? 1: 0);
  7973. }
  7974. else
  7975. {
  7976. tempIndex = gun_index;
  7977. }
  7978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7979. {
  7980. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  7981. {
  7982. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  7983. {
  7984. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7985. {
  7986. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7987. }
  7988. else
  7989. {
  7990. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7991. }
  7992. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7993. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7994. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7995. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7996. }
  7997. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7998. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7999. ) //S_PRECHARGE
  8000. {
  8001. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8002. }
  8003. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8004. {
  8005. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8006. }
  8007. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8008. {
  8009. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8010. }
  8011. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8012. {
  8013. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8014. }
  8015. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  8016. {
  8017. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8018. }
  8019. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8020. {
  8021. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8022. }
  8023. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8024. {
  8025. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8026. }
  8027. } //end of the same index
  8028. }//end of for CHAdeMO_QUANTITY
  8029. }
  8030. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8031. {
  8032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8033. {
  8034. tempIndex = ((gun_index==2) ? 1: 0);
  8035. }
  8036. else
  8037. {
  8038. tempIndex = gun_index;
  8039. }
  8040. for (int index = 0; index < CCS_QUANTITY; index++)
  8041. {
  8042. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8043. {
  8044. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8045. {
  8046. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  8047. {
  8048. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8049. }
  8050. else
  8051. {
  8052. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8053. }
  8054. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8055. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8056. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8057. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8058. }
  8059. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8060. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8061. ) //S_PRECHARGE
  8062. {
  8063. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8064. }
  8065. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8066. {
  8067. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8068. }
  8069. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8070. {
  8071. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8072. }
  8073. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  8074. {
  8075. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8076. }
  8077. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  8078. {
  8079. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  8080. }
  8081. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  8082. {
  8083. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8084. }
  8085. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8086. {
  8087. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8088. }
  8089. } //end of the same index
  8090. } // end of for CCS_QUANTITY
  8091. }
  8092. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8093. {
  8094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8095. {
  8096. tempIndex = ((gun_index==2) ? 1: 0);
  8097. }
  8098. else
  8099. {
  8100. tempIndex = gun_index;
  8101. }
  8102. for (int index = 0; index < GB_QUANTITY; index++)
  8103. {
  8104. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8105. {
  8106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8107. {
  8108. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8109. {
  8110. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8111. }
  8112. else
  8113. {
  8114. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8115. }
  8116. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8117. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8118. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8119. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8120. }
  8121. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8122. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8123. ) //S_PRECHARGE
  8124. {
  8125. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8126. }
  8127. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8128. {
  8129. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8130. }
  8131. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8132. {
  8133. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8134. }
  8135. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8136. {
  8137. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8138. }
  8139. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  8140. {
  8141. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8142. }
  8143. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  8144. {
  8145. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8146. }
  8147. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8148. {
  8149. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8150. }
  8151. } //end of the same index
  8152. } // end of for GB_QUANTITY
  8153. }
  8154. else if(gunType[gun_index] == GUN_TYPE_DO)
  8155. {
  8156. tempIndex = gun_index;
  8157. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8158. {
  8159. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8160. {
  8161. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8162. {
  8163. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8164. {
  8165. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8166. }
  8167. else
  8168. {
  8169. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8170. }
  8171. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8172. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8173. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8174. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8175. }
  8176. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8177. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8178. ) //S_PRECHARGE
  8179. {
  8180. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8181. }
  8182. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8183. {
  8184. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8185. }
  8186. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8187. {
  8188. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8189. }
  8190. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8191. {
  8192. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8193. }
  8194. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  8195. {
  8196. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8197. }
  8198. 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
  8199. {
  8200. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8201. }
  8202. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8203. {
  8204. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8205. }
  8206. } //end of the same index
  8207. }
  8208. }
  8209. else
  8210. {
  8211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8212. {
  8213. tempIndex = 2;
  8214. }
  8215. else
  8216. {
  8217. tempIndex = gun_index;
  8218. }
  8219. for (int index = 0; index < AC_QUANTITY; index++)
  8220. {
  8221. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8222. {
  8223. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  8224. {
  8225. 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))
  8226. {
  8227. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8228. }
  8229. else
  8230. {
  8231. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8232. }
  8233. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8234. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8235. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8236. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8237. }
  8238. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  8239. {
  8240. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8241. }
  8242. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  8243. {
  8244. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8245. }
  8246. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  8247. {
  8248. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8249. }
  8250. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8251. {
  8252. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8253. }
  8254. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  8255. {
  8256. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8257. }
  8258. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8259. {
  8260. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8261. }
  8262. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8263. {
  8264. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8265. }
  8266. }//end of the same index
  8267. }//end of for AC_QUANTITY
  8268. }
  8269. //it's option
  8270. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  8271. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  8272. {
  8273. isStateChanged = FALSE;
  8274. }
  8275. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  8276. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  8277. random_uuid(guid);
  8278. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  8279. , MESSAGE_TYPE_CALL
  8280. , guid
  8281. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  8282. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  8283. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  8284. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  8285. if((server_sign == TRUE) && isStateChanged)
  8286. {
  8287. LWS_Send(message);
  8288. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  8289. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8290. {
  8291. result = PASS;
  8292. }
  8293. }
  8294. else
  8295. {
  8296. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  8297. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  8298. result = PASS;
  8299. }
  8300. return result;
  8301. }
  8302. int sendTransactionEventRequest(int gun_index)
  8303. {
  8304. mtrace();
  8305. int result = FAIL;
  8306. char message[1024*20]={0};
  8307. char guid[37]={0};
  8308. char tempdata[128]={0};
  8309. uint8_t tempIndex;
  8310. json_object *TransactionEvent = json_object_new_object();
  8311. json_object *transactionInfo = json_object_new_object();
  8312. json_object *idToken = json_object_new_object();
  8313. json_object *evse = json_object_new_object();
  8314. json_object *meterValues = json_object_new_array();
  8315. char TempStopTransaction[256];
  8316. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  8317. DEBUG_INFO("sendTransactionEventRequest...\n");
  8318. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8319. {
  8320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8321. {
  8322. tempIndex = ((gun_index==2) ? 1: 0);
  8323. }
  8324. else
  8325. {
  8326. tempIndex = gun_index;
  8327. }
  8328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8329. {
  8330. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  8331. {
  8332. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8333. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8334. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8335. else
  8336. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8337. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8338. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8339. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8340. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  8341. {
  8342. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8343. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8344. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8345. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8346. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8347. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8348. {
  8349. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8350. }
  8351. else
  8352. {
  8353. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8354. }
  8355. }
  8356. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8357. {
  8358. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8359. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8360. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8361. }
  8362. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8363. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8364. ) //S_PRECHARGE
  8365. {
  8366. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8367. {
  8368. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8369. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  8370. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  8371. storeTempStopTransaction(gun_index);
  8372. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8373. }
  8374. else
  8375. {
  8376. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8377. }
  8378. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8379. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8380. }
  8381. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8382. {
  8383. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8384. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8385. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8386. }
  8387. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8388. {
  8389. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8390. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8391. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8392. if((access(TempStopTransaction,F_OK))!=-1)
  8393. {
  8394. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8395. }
  8396. }
  8397. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8398. {
  8399. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8400. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8401. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8402. }
  8403. 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
  8404. {
  8405. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8406. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8407. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8408. }
  8409. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8410. {
  8411. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8412. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8413. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8414. }
  8415. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8416. {
  8417. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8418. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8419. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8420. }
  8421. } //end of the same index
  8422. }//end of for CHAdeMO_QUANTITY
  8423. }
  8424. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8425. {
  8426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8427. {
  8428. tempIndex = ((gun_index==2) ? 1: 0);
  8429. }
  8430. else
  8431. {
  8432. tempIndex = gun_index;
  8433. }
  8434. for (int index = 0; index < CCS_QUANTITY; index++)
  8435. {
  8436. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8437. {
  8438. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8439. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8440. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8441. else
  8442. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8443. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8444. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8445. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8446. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8447. {
  8448. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8449. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8450. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8451. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8452. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8453. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  8454. {
  8455. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8456. }
  8457. else
  8458. {
  8459. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8460. }
  8461. }
  8462. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8463. {
  8464. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8465. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8466. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8467. }
  8468. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8469. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8470. ) //S_PRECHARGE
  8471. {
  8472. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8473. {
  8474. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8475. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  8476. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  8477. storeTempStopTransaction(gun_index);
  8478. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8479. }
  8480. else
  8481. {
  8482. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8483. }
  8484. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8485. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8486. }
  8487. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8488. {
  8489. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8490. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8491. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8492. }
  8493. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8494. {
  8495. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8496. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8497. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8498. if((access(TempStopTransaction,F_OK))!=-1)
  8499. {
  8500. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8501. }
  8502. }
  8503. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8504. {
  8505. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8506. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8507. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8508. }
  8509. 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
  8510. {
  8511. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8512. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8513. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8514. }
  8515. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8516. {
  8517. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8518. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8519. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8520. }
  8521. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8522. {
  8523. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8524. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8525. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8526. }
  8527. } //end of the same index
  8528. } // end of for CCS_QUANTITY
  8529. }
  8530. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8531. {
  8532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8533. {
  8534. tempIndex = ((gun_index==2) ? 1: 0);
  8535. }
  8536. else
  8537. {
  8538. tempIndex = gun_index;
  8539. }
  8540. for (int index = 0; index < GB_QUANTITY; index++)
  8541. {
  8542. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8543. {
  8544. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8545. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8546. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8547. else
  8548. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8549. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8550. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8551. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8553. {
  8554. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8555. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8556. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8557. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8558. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8559. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  8560. {
  8561. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8562. }
  8563. else
  8564. {
  8565. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8566. }
  8567. }
  8568. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8569. {
  8570. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8571. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8572. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8573. }
  8574. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8575. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8576. ) //S_PRECHARGE
  8577. {
  8578. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8579. {
  8580. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8581. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  8582. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  8583. storeTempStopTransaction(gun_index);
  8584. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8585. }
  8586. else
  8587. {
  8588. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8589. }
  8590. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8591. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8592. }
  8593. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8594. {
  8595. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8596. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8597. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8598. }
  8599. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8600. {
  8601. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8602. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8603. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8604. if((access(TempStopTransaction,F_OK))!=-1)
  8605. {
  8606. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8607. }
  8608. }
  8609. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8610. {
  8611. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8612. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8613. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8614. }
  8615. 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
  8616. {
  8617. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8618. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8619. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8620. }
  8621. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8622. {
  8623. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8624. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8625. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8626. }
  8627. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8628. {
  8629. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8630. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8631. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8632. }
  8633. } //end of the same index
  8634. } // end of for GB_QUANTITY
  8635. }
  8636. else if(gunType[gun_index] == GUN_TYPE_DO)
  8637. {
  8638. tempIndex = gun_index;
  8639. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8640. {
  8641. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8642. {
  8643. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8644. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8645. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8646. else
  8647. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8648. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8649. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8650. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8651. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8652. {
  8653. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8654. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8655. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8656. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8657. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8658. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8659. {
  8660. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8661. }
  8662. else
  8663. {
  8664. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8665. }
  8666. }
  8667. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8668. {
  8669. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8670. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8671. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8672. }
  8673. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8674. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8675. ) //S_PRECHARGE
  8676. {
  8677. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8678. {
  8679. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8680. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  8681. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  8682. storeTempStopTransaction(gun_index);
  8683. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8684. }
  8685. else
  8686. {
  8687. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8688. }
  8689. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8690. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8691. }
  8692. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8693. {
  8694. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8695. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8696. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8697. }
  8698. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8699. {
  8700. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8701. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8702. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8703. if((access(TempStopTransaction,F_OK))!=-1)
  8704. {
  8705. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8706. }
  8707. }
  8708. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8709. {
  8710. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8711. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8712. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8713. }
  8714. 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
  8715. {
  8716. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8717. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8718. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8719. }
  8720. 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
  8721. {
  8722. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8723. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8724. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8725. }
  8726. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8727. {
  8728. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8729. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8730. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8731. }
  8732. } //end of the same index
  8733. }
  8734. }
  8735. else
  8736. {
  8737. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8738. {
  8739. tempIndex = 2;
  8740. }
  8741. else
  8742. {
  8743. tempIndex = gun_index;
  8744. }
  8745. for (int index = 0; index < AC_QUANTITY; index++)
  8746. {
  8747. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8748. {
  8749. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8750. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8751. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8752. else
  8753. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8754. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8755. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8756. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  8758. {
  8759. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8760. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8761. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8762. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8763. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8764. 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))
  8765. {
  8766. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8767. }
  8768. else
  8769. {
  8770. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8771. }
  8772. }
  8773. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8774. {
  8775. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8776. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8777. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8778. }
  8779. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8780. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8781. ) //S_PRECHARGE
  8782. {
  8783. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8784. {
  8785. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8786. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  8787. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  8788. storeTempStopTransaction(gun_index);
  8789. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8790. }
  8791. else
  8792. {
  8793. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8794. }
  8795. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8796. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8797. }
  8798. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8799. {
  8800. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8801. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8802. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8803. }
  8804. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8805. {
  8806. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8807. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8808. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8809. if((access(TempStopTransaction,F_OK))!=-1)
  8810. {
  8811. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8812. }
  8813. }
  8814. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8815. {
  8816. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8817. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8818. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8819. }
  8820. 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
  8821. {
  8822. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8823. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8824. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8825. }
  8826. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8827. {
  8828. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8829. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8830. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8831. }
  8832. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8833. {
  8834. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8835. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8836. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8837. }
  8838. }//end of the same index
  8839. }//end of for AC_QUANTITY
  8840. }
  8841. // Message
  8842. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8843. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  8844. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  8845. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  8846. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  8847. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  8848. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  8849. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  8850. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  8851. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  8852. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  8853. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  8854. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  8855. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  8856. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  8857. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  8858. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  8859. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  8860. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  8861. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  8862. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  8863. {
  8864. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  8865. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  8866. json_object_object_add(TransactionEvent, "idToken", idToken);
  8867. }
  8868. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  8869. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  8870. json_object_object_add(TransactionEvent, "evse", evse);
  8871. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  8872. {
  8873. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  8874. {
  8875. json_object *meterValue = json_object_new_object();
  8876. json_object *sampledValues = json_object_new_array();
  8877. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  8878. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8879. {
  8880. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  8881. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0)))
  8882. {
  8883. json_object *sampledValue = json_object_new_object();
  8884. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8885. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8886. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8887. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8888. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8889. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8890. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8891. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8892. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8893. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8894. {
  8895. json_object *unitOfMeasure = json_object_new_object();
  8896. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8897. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8898. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8899. }
  8900. json_object_array_add(sampledValues, sampledValue);
  8901. }
  8902. }
  8903. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8904. json_object_array_add(meterValues, meterValue);
  8905. }
  8906. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  8907. }
  8908. random_uuid(guid);
  8909. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  8910. json_object_put(TransactionEvent);
  8911. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  8912. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8913. {
  8914. result = PASS;
  8915. }
  8916. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  8917. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  8918. OCPP_insert_transaction_msg(YES, message);
  8919. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  8920. OCPP_insert_transaction_msg(NO, message);
  8921. return result;
  8922. }
  8923. //==========================================
  8924. // send confirm routine
  8925. //==========================================
  8926. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  8927. {
  8928. mtrace();
  8929. int result = FAIL;
  8930. char message[4096]={0};
  8931. json_object *CancelReservation = json_object_new_object();
  8932. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8933. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  8934. sprintf(message,"[%d,\"%s\",%s]"
  8935. ,MESSAGE_TYPE_CALLRESULT
  8936. ,uuid
  8937. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  8938. json_object_put(CancelReservation);
  8939. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  8940. LWS_Send(message);
  8941. result = TRUE;
  8942. return result;
  8943. }
  8944. int sendCertificateSignedConfirmation(char *uuid)
  8945. {
  8946. mtrace();
  8947. int result = FAIL;
  8948. char message[4096]={0};
  8949. json_object *CertificateSigned = json_object_new_object();
  8950. json_object *statusInfo = json_object_new_object();
  8951. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8952. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  8953. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  8954. {
  8955. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  8956. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  8957. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  8958. }
  8959. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  8960. sprintf(message,"[%d,\"%s\",%s]"
  8961. ,MESSAGE_TYPE_CALLRESULT
  8962. ,uuid
  8963. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8964. json_object_put(CertificateSigned);
  8965. LWS_Send(message);
  8966. result = TRUE;
  8967. return result;
  8968. }
  8969. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  8970. {
  8971. mtrace();
  8972. int result = FAIL;
  8973. char message[4096]={0};
  8974. json_object *ChangeAvailability = json_object_new_object();
  8975. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8976. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  8977. sprintf(message,"[%d,\"%s\",%s]"
  8978. ,MESSAGE_TYPE_CALLRESULT
  8979. ,uuid
  8980. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  8981. json_object_put(ChangeAvailability);
  8982. LWS_Send(message);
  8983. result = TRUE;
  8984. return result;
  8985. }
  8986. int sendClearCacheConfirmation(char *uuid)
  8987. {
  8988. mtrace();
  8989. int result = FAIL;
  8990. char message[4096]={0};
  8991. json_object *ClearCache = json_object_new_object();
  8992. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8993. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  8994. sprintf(message,"[%d,\"%s\",%s]"
  8995. ,MESSAGE_TYPE_CALLRESULT
  8996. ,uuid
  8997. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  8998. json_object_put(ClearCache);
  8999. LWS_Send(message);
  9000. result = TRUE;
  9001. return result;
  9002. }
  9003. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  9004. {
  9005. mtrace();
  9006. int result = FAIL;
  9007. char message[500]={0};
  9008. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  9009. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  9010. LWS_Send(message);
  9011. return result;
  9012. }
  9013. int sendClearDisplayMessageConfirmation(char *uuid)
  9014. {
  9015. mtrace();
  9016. int result = FAIL;
  9017. char message[4096]={0};
  9018. json_object *ClearDisplayMessage = json_object_new_object();
  9019. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  9020. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  9021. sprintf(message,"[%d,\"%s\",%s]"
  9022. ,MESSAGE_TYPE_CALLRESULT
  9023. ,uuid
  9024. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  9025. json_object_put(ClearDisplayMessage);
  9026. LWS_Send(message);
  9027. result = TRUE;
  9028. return result;
  9029. }
  9030. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  9031. {
  9032. mtrace();
  9033. int result = FAIL;
  9034. char message[4096]={0};
  9035. json_object *ClearVariableMonitoring = json_object_new_object();
  9036. json_object *clearMonitoringResults = json_object_new_array();
  9037. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  9038. for(int idx=0;idx<variableQuantity;idx++)
  9039. {
  9040. json_object *clearMonitoringResult = json_object_new_object();
  9041. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  9042. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  9043. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  9044. }
  9045. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  9046. sprintf(message,"[%d,\"%s\",%s]"
  9047. ,MESSAGE_TYPE_CALLRESULT
  9048. ,uuid
  9049. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  9050. json_object_put(ClearVariableMonitoring);
  9051. LWS_Send(message);
  9052. result = TRUE;
  9053. return result;
  9054. }
  9055. int sendCostUpdatedConfirmation(char *uuid)
  9056. {
  9057. mtrace();
  9058. int result = FAIL;
  9059. char message[4096]={0};
  9060. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  9061. sprintf(message,"[%d,\"%s\",{}]"
  9062. ,MESSAGE_TYPE_CALLRESULT
  9063. ,uuid);
  9064. LWS_Send(message);
  9065. result = TRUE;
  9066. return result;
  9067. }
  9068. int sendCustomerInformationConfirmation(char *uuid)
  9069. {
  9070. mtrace();
  9071. int result = FAIL;
  9072. char message[4096]={0};
  9073. json_object *CustomerInformation = json_object_new_object();
  9074. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  9075. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  9076. sprintf(message,"[%d,\"%s\",%s]"
  9077. ,MESSAGE_TYPE_CALLRESULT
  9078. ,uuid
  9079. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  9080. json_object_put(CustomerInformation);
  9081. LWS_Send(message);
  9082. result = TRUE;
  9083. return result;
  9084. }
  9085. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  9086. {
  9087. mtrace();
  9088. int result = FAIL;
  9089. char message[4096]={0};
  9090. json_object *DataTransfer = json_object_new_object();
  9091. DEBUG_INFO("sendDataTransferConfirmation...\n");
  9092. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  9093. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  9094. sprintf(message,"[%d,\"%s\",%s]"
  9095. ,MESSAGE_TYPE_CALLRESULT
  9096. ,uuid
  9097. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  9098. json_object_put(DataTransfer);
  9099. LWS_Send(message);
  9100. result = TRUE;
  9101. return result;
  9102. }
  9103. int sendDeleteCertificateConfirmation(char *uuid)
  9104. {
  9105. mtrace();
  9106. int result = FAIL;
  9107. char message[4096]={0};
  9108. json_object *DeleteCertificate = json_object_new_object();
  9109. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  9110. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  9111. sprintf(message,"[%d,\"%s\",%s]"
  9112. ,MESSAGE_TYPE_CALLRESULT
  9113. ,uuid
  9114. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  9115. json_object_put(DeleteCertificate);
  9116. LWS_Send(message);
  9117. result = TRUE;
  9118. return result;
  9119. }
  9120. int sendGetBaseReportConfirmation(char *uuid)
  9121. {
  9122. mtrace();
  9123. int result = FAIL;
  9124. char message[4096]={0};
  9125. json_object *GetBaseReport = json_object_new_object();
  9126. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  9127. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  9128. sprintf(message,"[%d,\"%s\",%s]"
  9129. ,MESSAGE_TYPE_CALLRESULT
  9130. ,uuid
  9131. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  9132. json_object_put(GetBaseReport);
  9133. LWS_Send(message);
  9134. result = TRUE;
  9135. return result;
  9136. }
  9137. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  9138. {
  9139. mtrace();
  9140. int result = FAIL;
  9141. char message[4096]={0};
  9142. json_object *GetChargingProfiles = json_object_new_object();
  9143. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  9144. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  9145. sprintf(message,"[%d,\"%s\",%s]"
  9146. ,MESSAGE_TYPE_CALLRESULT
  9147. ,uuid
  9148. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  9149. json_object_put(GetChargingProfiles);
  9150. LWS_Send(message);
  9151. result = TRUE;
  9152. return result;
  9153. }
  9154. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  9155. {
  9156. mtrace();
  9157. int result = FAIL;
  9158. char message[4096]={0};
  9159. int CompositeScheduleIndex = 0;
  9160. json_object *GetCompositeSchedule = json_object_new_object();
  9161. json_object *schedule = json_object_new_object();
  9162. json_object *chargingSchedule = json_object_new_object();
  9163. json_object *chargingSchedulePeriod = json_object_new_array();
  9164. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  9165. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  9166. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  9167. if(nPeriod == 0)
  9168. {
  9169. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  9170. {
  9171. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  9172. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  9173. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  9174. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  9175. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  9176. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  9177. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  9178. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  9179. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  9180. {
  9181. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  9182. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  9183. {
  9184. json_object *Period = json_object_new_object();
  9185. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  9186. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  9187. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  9188. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  9189. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  9190. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  9191. json_object_array_add(chargingSchedulePeriod, Period);
  9192. }
  9193. }
  9194. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  9195. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  9196. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  9197. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  9198. }
  9199. }
  9200. else
  9201. {
  9202. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  9203. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  9204. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  9205. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  9206. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  9207. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  9208. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  9209. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  9210. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  9211. {
  9212. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  9213. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  9214. {
  9215. json_object *Period = json_object_new_object();
  9216. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  9217. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  9218. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  9219. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  9220. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  9221. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  9222. json_object_array_add(chargingSchedulePeriod, Period);
  9223. }
  9224. }
  9225. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  9226. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  9227. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  9228. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  9229. }
  9230. sprintf(message,"[%d,\"%s\",%s]"
  9231. ,MESSAGE_TYPE_CALLRESULT
  9232. ,uuid
  9233. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  9234. json_object_put(GetCompositeSchedule);
  9235. LWS_Send(message);
  9236. result = TRUE;
  9237. return result;
  9238. }
  9239. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  9240. {
  9241. mtrace();
  9242. int result = FAIL;
  9243. char message[4096]={0};
  9244. json_object *GetGetDisplayMessages = json_object_new_object();
  9245. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  9246. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  9247. sprintf(message,"[%d,\"%s\",%s]"
  9248. ,MESSAGE_TYPE_CALLRESULT
  9249. ,uuid
  9250. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  9251. json_object_put(GetGetDisplayMessages);
  9252. LWS_Send(message);
  9253. result = TRUE;
  9254. return result;
  9255. }
  9256. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  9257. {
  9258. mtrace();
  9259. int result = FAIL;
  9260. char message[4096]={0};
  9261. json_object *GetInstalledCertificateIds = json_object_new_object();
  9262. json_object *certificateHashDataChains = json_object_new_array();
  9263. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  9264. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  9265. for(int idx=0;idx<certQuantity;idx++)
  9266. {
  9267. json_object *cert = json_object_new_object();
  9268. json_object *certificateHashData = json_object_new_object();
  9269. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  9270. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  9271. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  9272. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  9273. json_object_object_add(cert, "certificateHashData", certificateHashData);
  9274. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  9275. json_object_array_add(certificateHashDataChains, cert);
  9276. }
  9277. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  9278. sprintf(message,"[%d,\"%s\",%s]"
  9279. ,MESSAGE_TYPE_CALLRESULT
  9280. ,uuid
  9281. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  9282. json_object_put(GetInstalledCertificateIds);
  9283. LWS_Send(message);
  9284. result = TRUE;
  9285. return result;
  9286. }
  9287. int sendGetLocalListVersionConfirmation(char *uuid)
  9288. {
  9289. mtrace();
  9290. int result = FAIL;
  9291. char message[4096]={0};
  9292. json_object *GetLocalListVersion = json_object_new_object();
  9293. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  9294. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  9295. sprintf(message,"[%d,\"%s\",%s]"
  9296. ,MESSAGE_TYPE_CALLRESULT
  9297. ,uuid
  9298. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  9299. json_object_put(GetLocalListVersion);
  9300. LWS_Send(message);
  9301. result = TRUE;
  9302. return result;
  9303. }
  9304. int sendGetLogConfirmation(char *uuid)
  9305. {
  9306. mtrace();
  9307. int result = FAIL;
  9308. char message[4096]={0};
  9309. json_object *GetLog = json_object_new_object();
  9310. DEBUG_INFO("sendGetLogConfirmation...\n");
  9311. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  9312. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  9313. sprintf(message,"[%d,\"%s\",%s]"
  9314. ,MESSAGE_TYPE_CALLRESULT
  9315. ,uuid
  9316. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  9317. json_object_put(GetLog);
  9318. LWS_Send(message);
  9319. result = TRUE;
  9320. return result;
  9321. }
  9322. int sendGetMonitoringReportConfirmation(char *uuid)
  9323. {
  9324. mtrace();
  9325. int result = FAIL;
  9326. char message[4096]={0};
  9327. json_object *GetMonitoringReport = json_object_new_object();
  9328. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  9329. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  9330. sprintf(message,"[%d,\"%s\",%s]"
  9331. ,MESSAGE_TYPE_CALLRESULT
  9332. ,uuid
  9333. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  9334. json_object_put(GetMonitoringReport);
  9335. LWS_Send(message);
  9336. result = TRUE;
  9337. return result;
  9338. }
  9339. int sendGetReportConfirmation(char *uuid)
  9340. {
  9341. mtrace();
  9342. int result = FAIL;
  9343. char message[4096]={0};
  9344. json_object *GetReport = json_object_new_object();
  9345. DEBUG_INFO("sendGetReportConfirmation...\n");
  9346. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  9347. sprintf(message,"[%d,\"%s\",%s]"
  9348. ,MESSAGE_TYPE_CALLRESULT
  9349. ,uuid
  9350. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  9351. json_object_put(GetReport);
  9352. LWS_Send(message);
  9353. result = TRUE;
  9354. return result;
  9355. }
  9356. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  9357. {
  9358. mtrace();
  9359. int result = FAIL;
  9360. char message[4096]={0};
  9361. json_object *GetTransactionStatus = json_object_new_object();
  9362. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  9363. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  9364. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  9365. sprintf(message,"[%d,\"%s\",%s]"
  9366. ,MESSAGE_TYPE_CALLRESULT
  9367. ,uuid
  9368. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  9369. json_object_put(GetTransactionStatus);
  9370. LWS_Send(message);
  9371. result = TRUE;
  9372. return result;
  9373. }
  9374. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  9375. {
  9376. mtrace();
  9377. int result = FAIL;
  9378. char message[4096]={0};
  9379. json_object *GetVariables = json_object_new_object();
  9380. json_object *getVariableResults = json_object_new_array();
  9381. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  9382. for(int idx=0;idx<variableQuantity;idx++)
  9383. {
  9384. json_object *variableResult = json_object_new_object();
  9385. json_object *component = json_object_new_object();
  9386. json_object *variable = json_object_new_object();
  9387. json_object *evse = json_object_new_object();
  9388. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  9389. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  9390. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  9391. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  9392. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  9393. json_object_object_add(component, "evse", evse);
  9394. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  9395. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  9396. json_object_object_add(variableResult, "component", component);
  9397. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  9398. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  9399. json_object_object_add(variableResult, "variable", variable);
  9400. json_object_array_add(getVariableResults, variableResult);
  9401. }
  9402. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  9403. sprintf(message,"[%d,\"%s\",%s]"
  9404. ,MESSAGE_TYPE_CALLRESULT
  9405. ,uuid
  9406. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  9407. json_object_put(GetVariables);
  9408. LWS_Send(message);
  9409. result = TRUE;
  9410. return result;
  9411. }
  9412. int sendInstallCertificateConfirmation(char *uuid)
  9413. {
  9414. mtrace();
  9415. int result = FAIL;
  9416. char message[4096]={0};
  9417. json_object *InstallCertificate = json_object_new_object();
  9418. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  9419. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  9420. sprintf(message,"[%d,\"%s\",%s]"
  9421. ,MESSAGE_TYPE_CALLRESULT
  9422. ,uuid
  9423. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  9424. json_object_put(InstallCertificate);
  9425. LWS_Send(message);
  9426. result = TRUE;
  9427. return result;
  9428. }
  9429. int sendPublishFirmwareConfirmation(char *uuid)
  9430. {
  9431. mtrace();
  9432. int result = FAIL;
  9433. char message[4096]={0};
  9434. json_object *PublishFirmware = json_object_new_object();
  9435. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  9436. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  9437. sprintf(message,"[%d,\"%s\",%s]"
  9438. ,MESSAGE_TYPE_CALLRESULT
  9439. ,uuid
  9440. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  9441. json_object_put(PublishFirmware);
  9442. LWS_Send(message);
  9443. result = TRUE;
  9444. return result;
  9445. }
  9446. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  9447. {
  9448. mtrace();
  9449. int result = FAIL;
  9450. char message[4096]={0};
  9451. json_object *RemoteStartTransaction = json_object_new_object();
  9452. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  9453. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  9454. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  9455. sprintf(message,"[%d,\"%s\",%s]"
  9456. ,MESSAGE_TYPE_CALLRESULT
  9457. ,uuid
  9458. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  9459. json_object_put(RemoteStartTransaction);
  9460. LWS_Send(message);
  9461. result = TRUE;
  9462. return result;
  9463. }
  9464. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  9465. {
  9466. mtrace();
  9467. int result = FAIL;
  9468. char message[4096]={0};
  9469. json_object *RemoteStopTransaction = json_object_new_object();
  9470. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  9471. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  9472. sprintf(message,"[%d,\"%s\",%s]"
  9473. ,MESSAGE_TYPE_CALLRESULT
  9474. ,uuid
  9475. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  9476. json_object_put(RemoteStopTransaction);
  9477. LWS_Send(message);
  9478. result = TRUE;
  9479. return result;
  9480. }
  9481. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  9482. {
  9483. mtrace();
  9484. int result = FAIL;
  9485. char message[4096]={0};
  9486. json_object *ReserveNow = json_object_new_object();
  9487. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  9488. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  9489. sprintf(message,"[%d,\"%s\",%s]"
  9490. ,MESSAGE_TYPE_CALLRESULT
  9491. ,uuid
  9492. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  9493. json_object_put(ReserveNow);
  9494. LWS_Send(message);
  9495. result = TRUE;
  9496. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  9497. return result;
  9498. }
  9499. int sendResetConfirmation(char *uuid)
  9500. {
  9501. mtrace();
  9502. int result = FAIL;
  9503. char message[4096]={0};
  9504. json_object *Reset = json_object_new_object();
  9505. DEBUG_INFO("sendResetConfirmation...\n");
  9506. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  9507. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  9508. sprintf(message,"[%d,\"%s\",%s]"
  9509. ,MESSAGE_TYPE_CALLRESULT
  9510. ,uuid
  9511. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  9512. json_object_put(Reset);
  9513. LWS_Send(message);
  9514. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  9515. {
  9516. DB_updateBootType(BootReasonEnumType_RemoteReset);
  9517. }
  9518. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  9519. {
  9520. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  9521. }
  9522. result = TRUE;
  9523. return result;
  9524. }
  9525. int sendSendLocalListConfirmation(char *uuid)
  9526. {
  9527. mtrace();
  9528. int result = FAIL;
  9529. char message[4096]={0};
  9530. json_object *SendLocalList = json_object_new_object();
  9531. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  9532. sprintf(message,"[%d,\"%s\",%s]"
  9533. ,MESSAGE_TYPE_CALLRESULT
  9534. ,uuid
  9535. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  9536. json_object_put(SendLocalList);
  9537. LWS_Send(message);
  9538. result = TRUE;
  9539. return result;
  9540. }
  9541. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  9542. {
  9543. mtrace();
  9544. int result = FAIL;
  9545. char message[4096]={0};
  9546. json_object *SetChargingProfile = json_object_new_object();
  9547. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  9548. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  9549. sprintf(message,"[%d,\"%s\",%s]"
  9550. ,MESSAGE_TYPE_CALLRESULT
  9551. ,uuid
  9552. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  9553. json_object_put(SetChargingProfile);
  9554. LWS_Send(message);
  9555. result = TRUE;
  9556. return result;
  9557. }
  9558. int sendSetDisplayMessagesConfirmation(char *uuid)
  9559. {
  9560. mtrace();
  9561. int result = FAIL;
  9562. char message[4096]={0};
  9563. json_object *SetDisplayMessage = json_object_new_object();
  9564. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  9565. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  9566. sprintf(message,"[%d,\"%s\",%s]"
  9567. ,MESSAGE_TYPE_CALLRESULT
  9568. ,uuid
  9569. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  9570. json_object_put(SetDisplayMessage);
  9571. LWS_Send(message);
  9572. result = TRUE;
  9573. return result;
  9574. }
  9575. int sendSetMonitoringBaseConfirmation(char *uuid)
  9576. {
  9577. mtrace();
  9578. int result = FAIL;
  9579. char message[4096]={0};
  9580. json_object *SetMonitoringBase = json_object_new_object();
  9581. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  9582. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  9583. sprintf(message,"[%d,\"%s\",%s]"
  9584. ,MESSAGE_TYPE_CALLRESULT
  9585. ,uuid
  9586. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  9587. json_object_put(SetMonitoringBase);
  9588. LWS_Send(message);
  9589. result = TRUE;
  9590. return result;
  9591. }
  9592. int sendSetMonitoringLevelConfirmation(char *uuid)
  9593. {
  9594. mtrace();
  9595. int result = FAIL;
  9596. char message[4096]={0};
  9597. json_object *SetMonitoringLevel = json_object_new_object();
  9598. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  9599. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  9600. sprintf(message,"[%d,\"%s\",%s]"
  9601. ,MESSAGE_TYPE_CALLRESULT
  9602. ,uuid
  9603. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  9604. json_object_put(SetMonitoringLevel);
  9605. LWS_Send(message);
  9606. result = TRUE;
  9607. return result;
  9608. }
  9609. int sendSetNetworkProfileConfirmation(char *uuid)
  9610. {
  9611. mtrace();
  9612. int result = FAIL;
  9613. char message[4096]={0};
  9614. json_object *SetNetworkProfile = json_object_new_object();
  9615. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  9616. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  9617. sprintf(message,"[%d,\"%s\",%s]"
  9618. ,MESSAGE_TYPE_CALLRESULT
  9619. ,uuid
  9620. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  9621. json_object_put(SetNetworkProfile);
  9622. LWS_Send(message);
  9623. result = TRUE;
  9624. return result;
  9625. }
  9626. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  9627. {
  9628. mtrace();
  9629. int result = FAIL;
  9630. char message[4096]={0};
  9631. json_object *SetVariableMonitoring = json_object_new_object();
  9632. json_object *setMonitoringResults = json_object_new_array();
  9633. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  9634. for(int idx=0;idx<variableQuantity;idx++)
  9635. {
  9636. json_object *variableMonitorResult = json_object_new_object();
  9637. json_object *component = json_object_new_object();
  9638. json_object *variable = json_object_new_object();
  9639. json_object *evse = json_object_new_object();
  9640. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  9641. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  9642. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  9643. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  9644. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  9645. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  9646. json_object_object_add(component, "component", evse);
  9647. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  9648. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  9649. json_object_object_add(variableMonitorResult, "component", component);
  9650. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  9651. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  9652. json_object_object_add(variableMonitorResult, "variable", variable);
  9653. json_object_array_add(setMonitoringResults, variableMonitorResult);
  9654. }
  9655. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  9656. sprintf(message,"[%d,\"%s\",%s]"
  9657. ,MESSAGE_TYPE_CALLRESULT
  9658. ,uuid
  9659. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  9660. json_object_put(SetVariableMonitoring);
  9661. LWS_Send(message);
  9662. result = TRUE;
  9663. return result;
  9664. }
  9665. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  9666. {
  9667. mtrace();
  9668. int result = FAIL;
  9669. char message[4096]={0};
  9670. json_object *SetVariable = json_object_new_object();
  9671. json_object *setVariableResults = json_object_new_array();
  9672. DEBUG_INFO("sendSetVariableConfirmation...\n");
  9673. for(int idx=0;idx<variableQuantity;idx++)
  9674. {
  9675. json_object *variableResult = json_object_new_object();
  9676. json_object *component = json_object_new_object();
  9677. json_object *variable = json_object_new_object();
  9678. json_object *evse = json_object_new_object();
  9679. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  9680. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  9681. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  9682. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  9683. json_object_object_add(component, "component", evse);
  9684. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  9685. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  9686. json_object_object_add(variableResult, "component", component);
  9687. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  9688. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  9689. json_object_object_add(variableResult, "variable", variable);
  9690. json_object_array_add(setVariableResults, variableResult);
  9691. }
  9692. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  9693. sprintf(message,"[%d,\"%s\",%s]"
  9694. ,MESSAGE_TYPE_CALLRESULT
  9695. ,uuid
  9696. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  9697. json_object_put(SetVariable);
  9698. LWS_Send(message);
  9699. result = TRUE;
  9700. return result;
  9701. }
  9702. int sendTriggerMessageConfirmation(char *uuid)
  9703. {
  9704. mtrace();
  9705. int result = FAIL;
  9706. char message[4096]={0};
  9707. json_object *TriggerMessage = json_object_new_object();
  9708. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  9709. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  9710. sprintf(message,"[%d,\"%s\",%s]",
  9711. MESSAGE_TYPE_CALLRESULT,
  9712. uuid,
  9713. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  9714. json_object_put(TriggerMessage);
  9715. LWS_Send(message);
  9716. result = TRUE;
  9717. return result;
  9718. }
  9719. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  9720. {
  9721. mtrace();
  9722. int result = FAIL;
  9723. char message[4096]={0};
  9724. json_object *UnlockConnector = json_object_new_object();
  9725. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  9726. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  9727. sprintf(message,"[%d,\"%s\",%s]",
  9728. MESSAGE_TYPE_CALLRESULT,
  9729. uuid,
  9730. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  9731. json_object_put(UnlockConnector);
  9732. LWS_Send(message);
  9733. result = TRUE;
  9734. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  9735. return result;
  9736. }
  9737. int sendUnpublishFirmwareConfirmation(char *uuid)
  9738. {
  9739. mtrace();
  9740. int result = FAIL;
  9741. char message[4096]={0};
  9742. json_object *UnpublishFirmware = json_object_new_object();
  9743. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  9744. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  9745. sprintf(message,"[%d,\"%s\",%s]"
  9746. ,MESSAGE_TYPE_CALLRESULT
  9747. ,uuid
  9748. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  9749. json_object_put(UnpublishFirmware);
  9750. LWS_Send(message);
  9751. result = TRUE;
  9752. return result;
  9753. }
  9754. int sendUpdateFirmwareConfirmation(char *uuid)
  9755. {
  9756. mtrace();
  9757. int result = FAIL;
  9758. char message[4096]={0};
  9759. json_object *UpdateFirmware = json_object_new_object();
  9760. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  9761. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  9762. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  9763. sprintf(message,"[%d,\"%s\",%s]"
  9764. ,MESSAGE_TYPE_CALLRESULT
  9765. ,uuid
  9766. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  9767. json_object_put(UpdateFirmware);
  9768. LWS_Send(message);
  9769. result = TRUE;
  9770. return result;
  9771. }
  9772. int sendUnknownConfirmation(char *uuid)
  9773. {
  9774. mtrace();
  9775. int result = FAIL;
  9776. char message[256]={0};
  9777. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  9778. DEBUG_INFO("sendUnknownConfirmation...\n");
  9779. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  9780. LWS_Send(message);
  9781. result = TRUE;
  9782. return result;
  9783. }
  9784. //==========================================
  9785. // send CallError routine
  9786. //==========================================
  9787. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  9788. {
  9789. mtrace();
  9790. char message[220]={0};
  9791. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  9792. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  9793. LWS_Send(message);
  9794. }
  9795. //==========================================
  9796. // Handle server request routine Start
  9797. //==========================================
  9798. int handleCancelReservationRequest(char *uuid, char *payload)
  9799. {
  9800. mtrace();
  9801. int result = FAIL;
  9802. int gunNO = 0;
  9803. int reservationIdInt = -1;
  9804. DEBUG_INFO("handleCancelReservationRequest...\n");
  9805. json_object *CancelReservation;
  9806. CancelReservation = json_tokener_parse(payload);
  9807. if(!is_error(CancelReservation))
  9808. {
  9809. // Required data
  9810. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  9811. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  9812. }
  9813. json_object_put(CancelReservation);
  9814. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  9815. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  9816. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  9817. if(reservationIdInt != -1)
  9818. {
  9819. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9820. //check Transaction active
  9821. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  9822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9823. {
  9824. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  9825. {
  9826. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9827. if(gunType[2] == GUN_TYPE_CHAdeMO)
  9828. {
  9829. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  9830. }
  9831. else
  9832. {
  9833. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  9834. }
  9835. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9836. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  9837. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  9838. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  9839. goto end;
  9840. }
  9841. }
  9842. for (int index = 0; index < CCS_QUANTITY; index++)
  9843. {
  9844. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  9845. {
  9846. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9847. if(gunType[2] == GUN_TYPE_CCS)
  9848. {
  9849. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  9850. }
  9851. else
  9852. {
  9853. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  9854. }
  9855. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9856. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  9857. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  9858. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  9859. goto end;
  9860. }
  9861. }
  9862. for (int index = 0; index < GB_QUANTITY; index++)
  9863. {
  9864. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  9865. {
  9866. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9867. if(gunType[2] == GUN_TYPE_GBT)
  9868. {
  9869. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  9870. }
  9871. else
  9872. {
  9873. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  9874. }
  9875. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9876. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  9877. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  9878. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  9879. goto end;
  9880. }
  9881. }
  9882. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9883. {
  9884. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  9885. {
  9886. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9887. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  9888. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9889. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  9890. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  9891. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  9892. goto end;
  9893. }
  9894. }
  9895. for (int index = 0; index < AC_QUANTITY; index++)
  9896. {
  9897. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  9898. {
  9899. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9900. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9901. {
  9902. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  9903. }
  9904. else
  9905. {
  9906. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  9907. }
  9908. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9909. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  9910. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  9911. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  9912. goto end;
  9913. }
  9914. }
  9915. }
  9916. //The reservationId does NOT match the reservationId
  9917. sendCancelReservationConfirmation(uuid, gunNO);
  9918. end:
  9919. // Fill in ocpp packet uuid
  9920. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  9921. return result;
  9922. }
  9923. int handleCertificateSignedRequest(char *uuid, char *payload)
  9924. {
  9925. mtrace();
  9926. int result = FAIL;
  9927. json_object *CertificateSigned;
  9928. DEBUG_INFO("handleCertificateSignedRequest...\n");
  9929. CertificateSigned = json_tokener_parse(payload);
  9930. if(!is_error(CertificateSigned))
  9931. {
  9932. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  9933. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  9934. // Required data
  9935. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  9936. // Optional data
  9937. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  9938. {
  9939. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  9940. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  9941. {
  9942. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  9943. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9944. fclose(fp);
  9945. }
  9946. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  9947. {
  9948. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  9949. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9950. fclose(fp);
  9951. }
  9952. }
  9953. else
  9954. {
  9955. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  9956. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9957. fclose(fp);
  9958. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  9959. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9960. fclose(fp);
  9961. }
  9962. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9963. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  9964. }
  9965. else
  9966. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  9967. json_object_put(CertificateSigned);
  9968. sendCertificateSignedConfirmation(uuid);
  9969. return result;
  9970. }
  9971. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  9972. {
  9973. mtrace();
  9974. int result = FAIL;
  9975. int evseId = 0, gunIndex = 0;
  9976. char operationalStatus[16]={0};
  9977. char comfirmstr[20];
  9978. int specificId = FALSE;
  9979. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  9980. json_object *ChangeAvailability;
  9981. ChangeAvailability = json_tokener_parse(payload);
  9982. if(!is_error(ChangeAvailability))
  9983. {
  9984. // Required data
  9985. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  9986. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  9987. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  9988. {
  9989. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  9990. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  9991. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  9992. }
  9993. }
  9994. json_object_put(ChangeAvailability);
  9995. if((evseId != 0) && (evseId <= gunTotalNumber))
  9996. {
  9997. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  9998. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  9999. }
  10000. else if(evseId == 0)
  10001. {
  10002. for(int i=0; i < gunTotalNumber; i++)
  10003. {
  10004. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  10005. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  10006. }
  10007. }
  10008. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  10009. {
  10010. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  10011. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  10012. }
  10013. else if(gunIndex == 0)
  10014. {
  10015. for(int i=0; i < gunTotalNumber; i++)
  10016. {
  10017. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  10018. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  10019. }
  10020. }
  10021. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  10022. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10023. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  10024. {
  10025. specificId = TRUE;
  10026. }
  10027. if(specificId == FALSE)
  10028. goto end;
  10029. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  10030. {
  10031. //----------------------gunIndex is 0 ------------------------------------------------//
  10032. if(gunIndex == 0)
  10033. {
  10034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10035. {
  10036. for(int i=0; i < gunTotalNumber; i++)
  10037. {
  10038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10039. {
  10040. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  10041. {
  10042. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10043. {
  10044. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10045. goto end;
  10046. }
  10047. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10048. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10049. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10050. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10051. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10052. {
  10053. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10054. goto end;
  10055. }
  10056. }
  10057. }//END FOR CHAdeMO_QUANTITY
  10058. for (int index = 0; index < CCS_QUANTITY; index++)
  10059. {
  10060. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  10061. {
  10062. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  10063. {
  10064. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10065. goto end;
  10066. }
  10067. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10068. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10069. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10070. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10071. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10072. {
  10073. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10074. goto end;
  10075. }
  10076. }
  10077. }//END FOR CCS_QUANTITY
  10078. for (int index = 0; index < GB_QUANTITY; index++)
  10079. {
  10080. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  10081. {
  10082. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10083. {
  10084. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10085. goto end;
  10086. }
  10087. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10088. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10089. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10090. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10091. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10092. {
  10093. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10094. goto end;
  10095. }
  10096. }
  10097. }// END FOR GB_QUANTITY
  10098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10099. {
  10100. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  10101. {
  10102. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10103. {
  10104. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10105. goto end;
  10106. }
  10107. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  10108. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  10109. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  10110. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  10111. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10112. {
  10113. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10114. goto end;
  10115. }
  10116. }
  10117. }// END FOR DO_QUANTITY
  10118. for (int index = 0; index < AC_QUANTITY; index++)
  10119. {
  10120. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  10121. {
  10122. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10123. {
  10124. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10125. goto end;
  10126. }
  10127. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10128. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10129. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10130. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10131. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10132. {
  10133. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10134. goto end;
  10135. }
  10136. }
  10137. }//END FOR AC_QUANTITY
  10138. }// END FOR gunTotalNumber
  10139. }
  10140. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  10141. {
  10142. for(int i=0; i < gunTotalNumber; i++)
  10143. {
  10144. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10145. {
  10146. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10147. goto end;
  10148. }
  10149. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10150. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  10151. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  10152. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  10153. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10154. {
  10155. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10156. goto end;
  10157. }
  10158. }
  10159. }
  10160. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10161. goto end;
  10162. }
  10163. //----------------------gunIndex is not 0 ------------------------------------------------//
  10164. //check Transaction active
  10165. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10166. {
  10167. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  10168. {
  10169. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  10170. {
  10171. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10172. goto end;
  10173. }
  10174. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10175. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10176. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10177. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10178. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10179. {
  10180. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10181. goto end;
  10182. }
  10183. else
  10184. {
  10185. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  10186. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10187. goto end;
  10188. }
  10189. }
  10190. }//END FOR CHAdeMO_QUANTITY
  10191. for (int index = 0; index < CCS_QUANTITY; index++)
  10192. {
  10193. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  10194. {
  10195. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  10196. {
  10197. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10198. goto end;
  10199. }
  10200. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10201. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10202. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10203. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10204. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10205. {
  10206. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10207. goto end;
  10208. }
  10209. else
  10210. {
  10211. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  10212. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10213. goto end;
  10214. }
  10215. }
  10216. }//END FOR CCS_QUANTITY
  10217. for (int index = 0; index < GB_QUANTITY; index++)
  10218. {
  10219. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  10220. {
  10221. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  10222. {
  10223. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10224. goto end;
  10225. }
  10226. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10227. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10228. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10229. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10230. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10231. {
  10232. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10233. goto end;
  10234. }
  10235. else
  10236. {
  10237. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  10238. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10239. goto end;
  10240. }
  10241. }
  10242. }// END FOR GB_QUANTITY
  10243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10244. {
  10245. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  10246. {
  10247. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  10248. {
  10249. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10250. goto end;
  10251. }
  10252. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  10253. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  10254. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  10255. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  10256. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10257. {
  10258. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10259. goto end;
  10260. }
  10261. else
  10262. {
  10263. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  10264. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10265. goto end;
  10266. }
  10267. }
  10268. }// END FOR DO_QUANTITY
  10269. for (int index = 0; index < AC_QUANTITY; index++)
  10270. {
  10271. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  10272. {
  10273. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  10274. {
  10275. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10276. goto end;
  10277. }
  10278. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10279. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10280. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10281. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10282. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10283. {
  10284. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10285. goto end;
  10286. }
  10287. else
  10288. {
  10289. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  10290. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10291. goto end;
  10292. }
  10293. }
  10294. }//END FOR AC_QUANTITY
  10295. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  10296. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  10297. {
  10298. //----------------------gunIndex is 0 ------------------------------------------------//
  10299. if(gunIndex == 0)
  10300. {
  10301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10302. {
  10303. for(int i=0; i < gunTotalNumber; i++)
  10304. {
  10305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10306. {
  10307. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10308. {
  10309. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10310. goto end;
  10311. }
  10312. }//END FOR CHAdeMO_QUANTITY
  10313. for (int index = 0; index < CCS_QUANTITY; index++)
  10314. {
  10315. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10316. {
  10317. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10318. goto end;
  10319. }
  10320. }//END FOR CCS_QUANTITY
  10321. for (int index = 0; index < GB_QUANTITY; index++)
  10322. {
  10323. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10324. {
  10325. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  10326. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10327. goto end;
  10328. }
  10329. }// END FOR GB_QUANTITY
  10330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10331. {
  10332. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10333. {
  10334. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  10335. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10336. goto end;
  10337. }
  10338. }// END FOR DO_QUANTITY
  10339. for (int index = 0; index < AC_QUANTITY; index++)
  10340. {
  10341. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10342. {
  10343. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10344. goto end;
  10345. }
  10346. }//END FOR CHAdeMO_QUANTITY
  10347. }// END FOR gunTotalNumber
  10348. }
  10349. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  10350. {
  10351. for(int i=0; i < gunTotalNumber; i++)
  10352. {
  10353. for (int index = 0; index < AC_QUANTITY; index++)
  10354. {
  10355. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10356. {
  10357. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10358. goto end;
  10359. }
  10360. }//END FOR CHAdeMO_QUANTITY
  10361. } // END FOR gunTotalNumber
  10362. }
  10363. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10364. goto end;
  10365. }
  10366. //----------------------gunIndex is not 0 ------------------------------------------------//
  10367. //check Transaction active
  10368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10369. {
  10370. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10371. {
  10372. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10373. goto end;
  10374. }
  10375. }//END FOR CHAdeMO_QUANTITY
  10376. for (int index = 0; index < CCS_QUANTITY; index++)
  10377. {
  10378. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10379. {
  10380. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10381. goto end;
  10382. }
  10383. }//END FOR CCS_QUANTITY
  10384. for (int index = 0; index < GB_QUANTITY; index++)
  10385. {
  10386. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10387. {
  10388. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10389. goto end;
  10390. }
  10391. }// END FOR GB_QUANTITY
  10392. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10393. {
  10394. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10395. {
  10396. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10397. goto end;
  10398. }
  10399. }// END FOR DO_QUANTITY
  10400. for (int index = 0; index < AC_QUANTITY; index++)
  10401. {
  10402. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10403. {
  10404. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10405. goto end;
  10406. }
  10407. }//END FOR AC_QUANTITY
  10408. }//END FOR AvailabilityEnumTypeStr[Operative]
  10409. end:
  10410. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  10411. {
  10412. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  10413. }
  10414. else
  10415. {
  10416. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  10417. }
  10418. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  10419. {
  10420. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  10421. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  10422. }
  10423. else if(gunIndex == 0)
  10424. {
  10425. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  10426. {
  10427. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  10428. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  10429. }
  10430. }
  10431. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  10432. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10433. return result;
  10434. }
  10435. int handleClearCacheRequest(char *uuid, char *payload)
  10436. {
  10437. mtrace();
  10438. int result = FAIL;
  10439. char rmFileCmd[100]={0};
  10440. struct stat stats;
  10441. DEBUG_INFO("handleClearCacheRequest...\n");
  10442. stat("/Storage/OCPP", &stats);
  10443. // Check for directory existence
  10444. if (S_ISDIR(stats.st_mode) == 1)
  10445. {}
  10446. else
  10447. {
  10448. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  10449. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  10450. system(rmFileCmd);
  10451. }
  10452. if(DB_cleanLocalCache() != PASS)
  10453. {
  10454. DEBUG_INFO("open AuthorizationCache file failed\n");
  10455. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  10456. }
  10457. else
  10458. {
  10459. DEBUG_INFO("open AuthorizationCache file successful\n");
  10460. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  10461. }
  10462. sendClearCacheConfirmation(uuid);
  10463. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10464. return result;
  10465. }
  10466. int handleClearChargingProfileRequest(char *uuid, char *payload)
  10467. {
  10468. mtrace();
  10469. int result = FAIL;
  10470. int resultRename;
  10471. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  10472. char chargingProfilePurposeStr[26]={0};
  10473. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  10474. char tempchargingProfilePurposeStr[26]={0};
  10475. char sstr[160]={0};
  10476. char str[100]={0};
  10477. int c = 0;
  10478. char *loc;
  10479. char fname[200]={0};
  10480. char comfirmstr[20]={0};
  10481. char word[1600]={0};
  10482. int clearflag = FALSE;
  10483. int chargingProfileIdIsNULL = FALSE;
  10484. int connectorIsNULL = FALSE;
  10485. int chargingProfilePurposeIsNULL = FALSE;
  10486. int stackLevelIsNULL = FALSE;
  10487. //int GotoEnd = FALSE;
  10488. FILE *fptr1, *fptr2;
  10489. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  10490. int n_chargingProfile=0;
  10491. int isEmptyFile = FALSE;
  10492. char sLineWord[1600]={0};
  10493. char chargingProfiles[10][100]={0};
  10494. int ChargeProfileCount = 0;
  10495. int ch;
  10496. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  10497. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  10498. json_object *ClearChargingProfile;
  10499. ClearChargingProfile = json_tokener_parse(payload);
  10500. if(!is_error(ClearChargingProfile))
  10501. {
  10502. // Optional data
  10503. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  10504. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  10505. else
  10506. chargingProfileIdIsNULL = TRUE;
  10507. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  10508. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  10509. else
  10510. connectorIsNULL = TRUE;
  10511. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  10512. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  10513. else
  10514. chargingProfilePurposeIsNULL = TRUE;
  10515. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  10516. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  10517. else
  10518. stackLevelIsNULL = TRUE;
  10519. }
  10520. json_object_put(ClearChargingProfile);
  10521. if(connectorIsNULL == FALSE)
  10522. {
  10523. switch(connectorIdInt)
  10524. {
  10525. case 0:
  10526. if(chargingProfilePurposeIsNULL == TRUE)
  10527. {
  10528. int l = 0;
  10529. strcpy(fname, ChargePointMaxProfile_JSON);
  10530. if((access(fname,F_OK))!=-1)
  10531. {
  10532. strcpy(chargingProfiles[l], fname);
  10533. l = l + 1;
  10534. }
  10535. strcpy(fname, TxDefaultProfile_0_JSON);
  10536. if((access(fname,F_OK))!=-1)
  10537. {
  10538. strcpy(chargingProfiles[l], fname);
  10539. l = l + 1;
  10540. }
  10541. ChargeProfileCount = l;
  10542. }
  10543. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  10544. {
  10545. strcpy(fname, ChargePointMaxProfile_JSON);
  10546. if((access(fname,F_OK))!=-1)
  10547. {
  10548. strcpy(chargingProfiles[0], fname);
  10549. ChargeProfileCount = 1;
  10550. }
  10551. }
  10552. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  10553. {
  10554. strcpy(fname, TxDefaultProfile_0_JSON);
  10555. if((access(fname,F_OK))!=-1)
  10556. {
  10557. strcpy(chargingProfiles[0], fname);
  10558. ChargeProfileCount = 1;
  10559. }
  10560. }
  10561. break;
  10562. default:
  10563. if(chargingProfilePurposeIsNULL == TRUE)
  10564. {
  10565. int m = 0;
  10566. memset(fname, 0, ARRAY_SIZE(fname));
  10567. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10568. if((access(fname,F_OK))!=-1)
  10569. {
  10570. strcpy(chargingProfiles[m], fname);
  10571. m = m + 1;
  10572. }
  10573. memset(fname, 0, ARRAY_SIZE(fname));
  10574. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10575. if((access(fname,F_OK))!=-1)
  10576. {
  10577. strcpy(chargingProfiles[m], fname);
  10578. m = m + 1;
  10579. }
  10580. ChargeProfileCount = m;
  10581. }
  10582. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  10583. {
  10584. //strcpy(fname, TxDefaultProfile_1_JSON);
  10585. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10586. if((access(fname,F_OK))!=-1)
  10587. {
  10588. strcpy(chargingProfiles[0], fname);
  10589. ChargeProfileCount = 1;
  10590. }
  10591. }
  10592. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  10593. {
  10594. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10595. if((access(fname,F_OK))!=-1)
  10596. {
  10597. strcpy(chargingProfiles[0], fname);
  10598. ChargeProfileCount = 1;
  10599. }
  10600. }
  10601. //strcpy(fname, ChargePointMaxProfile_JSON );
  10602. break;
  10603. }
  10604. }
  10605. else // Check all Charging Profiles
  10606. {
  10607. int i = 0;
  10608. char fnametemp[200]={0};
  10609. ChargeProfileCount = 0;
  10610. //Check ChargePointMaxProfile.json exit
  10611. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10612. {
  10613. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  10614. i = i + 1;
  10615. }
  10616. //Check TxDefaultProfile_0.json exit
  10617. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10618. {
  10619. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  10620. i = i + 1;
  10621. }
  10622. //Check TxDefaultProfile_%d.json
  10623. for(int j=1; j <= gunTotalNumber; j++)
  10624. {
  10625. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10626. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10627. if((access(fnametemp,F_OK))!=-1)
  10628. {
  10629. strcpy(chargingProfiles[i], fnametemp);
  10630. i = i + 1;
  10631. }
  10632. }
  10633. //Check TxProfile_%d.json
  10634. for(int j=1; j <= gunTotalNumber; j++)
  10635. {
  10636. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10637. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10638. if((access(fnametemp,F_OK))!=-1)
  10639. {
  10640. strcpy(chargingProfiles[i], fnametemp);
  10641. i = i + 1;
  10642. }
  10643. }
  10644. ChargeProfileCount = i;
  10645. }// End connectorIsNULL is TRUE
  10646. if(ChargeProfileCount == 0)
  10647. {
  10648. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10649. goto end;
  10650. }
  10651. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  10652. {
  10653. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10654. goto end;
  10655. }
  10656. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  10657. {
  10658. memset(str, 0, ARRAY_SIZE(str));
  10659. // clear temp file
  10660. sprintf(str,"rm -f %s",temp);
  10661. system(str);
  10662. for(int k=0; k < ChargeProfileCount; k++)
  10663. {
  10664. memset(str, 0, ARRAY_SIZE(str));
  10665. //clear file in C
  10666. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10667. system(str);
  10668. }
  10669. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10670. goto end;
  10671. }
  10672. else if(connectorIsNULL == TRUE)
  10673. {
  10674. for(int k=0; k < ChargeProfileCount; k++)
  10675. {
  10676. fptr1 = fopen(chargingProfiles[k], "r");
  10677. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  10678. //Check Charging Profile Count
  10679. while(fscanf(fptr1, "%s", word) != EOF)
  10680. {
  10681. //DEBUG_INFO("word=%s\n",word);
  10682. if(strstr(word, "chargingProfileId")!= NULL)
  10683. {
  10684. //DEBUG_INFO("test chargingProfileId \n");
  10685. n_chargingProfile = n_chargingProfile + 1;
  10686. //DEBUG_INFO("chargingProfileId Found\n");
  10687. }
  10688. }
  10689. rewind(fptr1);
  10690. //search Charging Profile Element
  10691. //int i= 0;
  10692. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  10693. {
  10694. //------------------------tempconnectorIdInt------------------------//
  10695. loc = strstr(sLineWord, "connectorId");
  10696. c = 0;
  10697. memset(sstr ,0, sizeof(sstr) );
  10698. while (loc[strlen("connectorId")+2+c] != ',')
  10699. {
  10700. sstr[c] = loc[strlen("connectorId")+2+c];
  10701. c++;
  10702. }
  10703. sstr[c] = '\0';
  10704. tempconnectorIdInt = atoi(sstr);
  10705. printf("file's gun number is %d\n", tempconnectorIdInt);
  10706. //--------------------------chargingProfileId--------------------//
  10707. c = 0;
  10708. loc = strstr(sLineWord, "chargingProfileId");
  10709. memset(sstr ,0, ARRAY_SIZE(sstr));
  10710. while (loc[strlen("chargingProfileId")+2+c] != ',')
  10711. {
  10712. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  10713. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10714. c++;
  10715. }
  10716. sstr[c] = '\0';
  10717. tempchargingProfileIdInt = atoi(sstr);
  10718. //stackLevel
  10719. c = 0;
  10720. loc = strstr(sLineWord, "stackLevel");
  10721. memset(sstr ,0, ARRAY_SIZE(sstr));
  10722. while (loc[strlen("stackLevel")+2+c] != ',')
  10723. {
  10724. sstr[c] = loc[strlen("stackLevel")+2+c];
  10725. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10726. c++;
  10727. }
  10728. sstr[c] = '\0';
  10729. tempstackLevelInt = atoi(sstr);
  10730. c = 0;
  10731. loc = strstr(sLineWord, "chargingProfilePurpose");
  10732. memset(sstr ,0, ARRAY_SIZE(sstr));
  10733. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  10734. {
  10735. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  10736. c++;
  10737. }
  10738. sstr[c] = '\0';
  10739. strcpy(tempchargingProfilePurposeStr, sstr);
  10740. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  10741. {
  10742. //------- not write to fptr2-------//
  10743. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10744. //clearflag = TRUE;
  10745. }
  10746. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10747. {
  10748. //------- not write to fptr2-------//
  10749. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10750. }
  10751. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  10752. {
  10753. //------- not write to fptr2-------//
  10754. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10755. }
  10756. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  10757. {
  10758. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10759. }
  10760. else
  10761. {
  10762. fprintf(fptr2, sLineWord);//writing data into file
  10763. }
  10764. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10765. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  10766. if(clearflag == TRUE)
  10767. {
  10768. fclose(fptr1);
  10769. fclose(fptr2);
  10770. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10771. system(str);
  10772. // clear temp file
  10773. sprintf(str,"rm -f %s",temp);
  10774. system(str);
  10775. }
  10776. else
  10777. {
  10778. fclose(fptr1);
  10779. fclose(fptr2);
  10780. memset(str, 0, ARRAY_SIZE(str));
  10781. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10782. system(str);
  10783. resultRename = rename(temp, chargingProfiles[k]);
  10784. if(resultRename == 0)
  10785. {
  10786. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  10787. }
  10788. else
  10789. {
  10790. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  10791. }
  10792. if(comfirmstr[0]== 0)
  10793. {
  10794. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10795. }
  10796. //Check chargingProfile is empty file
  10797. /*------ Read the file ----------------*/
  10798. fptr1=fopen(chargingProfiles[k],"r");
  10799. ch=fgetc(fptr1);
  10800. rewind(fptr1);
  10801. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10802. if(ch!=EOF)
  10803. {
  10804. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  10805. {
  10806. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  10807. if(sLineWord[0]=='\0')
  10808. {
  10809. isEmptyFile = TRUE;
  10810. break;
  10811. }
  10812. else
  10813. {
  10814. isEmptyFile = FALSE;
  10815. break;
  10816. }
  10817. }
  10818. }
  10819. else
  10820. isEmptyFile = TRUE;
  10821. fclose(fptr1);
  10822. if(isEmptyFile == TRUE)
  10823. {
  10824. memset(str, 0, ARRAY_SIZE(str));
  10825. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10826. system(str);
  10827. }
  10828. }
  10829. }// End of while(int k=0; k < ChargePointCount; k++)
  10830. }
  10831. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  10832. {
  10833. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  10834. for(int k=0; k < ChargeProfileCount; k++)
  10835. {
  10836. fptr1 = fopen(chargingProfiles[k], "r");
  10837. fptr2 = fopen(temp, "w+");
  10838. //Check Charging Profile Count
  10839. while(fscanf(fptr1, "%s", word) != EOF)
  10840. {
  10841. //DEBUG_INFO("word=%s\n",word);
  10842. if(strstr(word, "chargingProfileId")!= NULL)
  10843. {
  10844. n_chargingProfile = n_chargingProfile + 1;
  10845. }
  10846. }
  10847. rewind(fptr1);
  10848. //search Charging Profile Element
  10849. //int i= 0;
  10850. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  10851. {
  10852. //*************************tempconnectorIdInt*********************************/
  10853. loc = strstr(sLineWord, "connectorId");
  10854. c = 0;
  10855. memset(sstr ,0, ARRAY_SIZE(sstr));
  10856. while (loc[strlen("connectorId")+2+c] != ',')
  10857. {
  10858. sstr[c] = loc[strlen("connectorId")+2+c];
  10859. c++;
  10860. }
  10861. sstr[c] = '\0';
  10862. tempconnectorIdInt = atoi(sstr);
  10863. //chargingProfileId
  10864. c = 0;
  10865. loc = strstr(sLineWord, "chargingProfileId");
  10866. memset(sstr ,0, ARRAY_SIZE(sstr));
  10867. while (loc[strlen("chargingProfileId")+2+c] != ',')
  10868. {
  10869. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  10870. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10871. c++;
  10872. }
  10873. sstr[c] = '\0';
  10874. tempchargingProfileIdInt = atoi(sstr);
  10875. //stackLevel
  10876. c = 0;
  10877. loc = strstr(sLineWord, "stackLevel");
  10878. memset(sstr ,0, ARRAY_SIZE(sstr));
  10879. while (loc[strlen("stackLevel")+2+c] != ',')
  10880. {
  10881. sstr[c] = loc[strlen("stackLevel")+2+c];
  10882. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10883. c++;
  10884. }
  10885. sstr[c] = '\0';
  10886. tempstackLevelInt = atoi(sstr);
  10887. c = 0;
  10888. loc = strstr(sLineWord, "chargingProfilePurpose");
  10889. memset(sstr ,0, ARRAY_SIZE(sstr));
  10890. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  10891. {
  10892. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  10893. c++;
  10894. }
  10895. sstr[c] = '\0';
  10896. strcpy(tempchargingProfilePurposeStr, sstr);
  10897. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  10898. {
  10899. //------- not write to fptr2-------//
  10900. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10901. //clearflag = TRUE;
  10902. }
  10903. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  10904. {
  10905. //------- not write to fptr2-------//
  10906. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10907. }
  10908. else if(stackLevelIsNULL == TRUE)
  10909. {
  10910. //Clear Whole File
  10911. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10912. clearflag = TRUE;
  10913. break;
  10914. }
  10915. else
  10916. {
  10917. fprintf(fptr2, sLineWord);//writing data into file
  10918. }
  10919. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10920. }
  10921. if(clearflag == TRUE)
  10922. {
  10923. fclose(fptr1);
  10924. fclose(fptr2);
  10925. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10926. system(str);
  10927. // clear temp file
  10928. sprintf(str,"rm -f %s",temp);
  10929. system(str);
  10930. }
  10931. else
  10932. {
  10933. fclose(fptr1);
  10934. fclose(fptr2);
  10935. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10936. system(str);
  10937. resultRename = rename(temp, chargingProfiles[k]);
  10938. if(resultRename == 0)
  10939. {
  10940. DEBUG_INFO("File ChargingProfile renamed successfully");
  10941. }
  10942. else
  10943. {
  10944. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  10945. }
  10946. if(comfirmstr[0]== 0)
  10947. {
  10948. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10949. }
  10950. //Check chargingProfile is empty file
  10951. /*------ Read the file ----------------*/
  10952. fptr1=fopen(chargingProfiles[k],"r");
  10953. ch=fgetc(fptr1);
  10954. rewind(fptr1);
  10955. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10956. if(ch!=EOF)
  10957. {
  10958. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  10959. {
  10960. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  10961. if(sLineWord[0]=='\0')
  10962. {
  10963. isEmptyFile = TRUE;
  10964. break;
  10965. }
  10966. else
  10967. {
  10968. isEmptyFile = FALSE;
  10969. break;
  10970. }
  10971. }
  10972. }
  10973. else
  10974. isEmptyFile = TRUE;
  10975. fclose(fptr1);
  10976. if(isEmptyFile == TRUE)
  10977. {
  10978. memset(str, 0, ARRAY_SIZE(str));
  10979. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10980. system(str);
  10981. }
  10982. /*------- End of reading ---------------*/
  10983. }
  10984. } // while(int k=0; k < ChargeProfileCount; k++)
  10985. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  10986. end:
  10987. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  10988. {
  10989. if(connectorIdInt == 0)
  10990. {
  10991. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10992. {
  10993. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  10994. }
  10995. }
  10996. else
  10997. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  10998. }
  10999. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  11000. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11001. return result;
  11002. }
  11003. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  11004. {
  11005. mtrace();
  11006. int result = FAIL;
  11007. json_object *ClearDisplayMessage;
  11008. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  11009. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  11010. ClearDisplayMessage = json_tokener_parse(payload);
  11011. if(!is_error(ClearDisplayMessage))
  11012. {
  11013. // Required data
  11014. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  11015. {
  11016. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  11017. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  11018. }
  11019. }
  11020. json_object_put(ClearDisplayMessage);
  11021. sendCostUpdatedConfirmation(uuid);
  11022. return result;
  11023. }
  11024. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  11025. {
  11026. mtrace();
  11027. int result = FAIL;
  11028. json_object *ClearVariableMonitorin;
  11029. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  11030. ClearVariableMonitorin = json_tokener_parse(payload);
  11031. if(!is_error(ClearVariableMonitorin))
  11032. {
  11033. // Required data
  11034. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  11035. {
  11036. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  11037. {
  11038. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  11039. /*
  11040. * TODO:
  11041. * 1. Check response
  11042. */
  11043. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  11044. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  11045. }
  11046. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  11047. }
  11048. }
  11049. json_object_put(ClearVariableMonitorin);
  11050. return result;
  11051. }
  11052. int handleCostUpdatedRequest(char *uuid, char *payload)
  11053. {
  11054. mtrace();
  11055. int result = FAIL;
  11056. json_object *CostUpdate;
  11057. DEBUG_INFO("handleCostUpdatedRequest...\n");
  11058. CostUpdate = json_tokener_parse(payload);
  11059. if(!is_error(CostUpdate))
  11060. {
  11061. // Required data
  11062. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  11063. {
  11064. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  11065. }
  11066. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  11067. {
  11068. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  11069. }
  11070. }
  11071. json_object_put(CostUpdate);
  11072. sendCostUpdatedConfirmation(uuid);
  11073. return result;
  11074. }
  11075. int handleCustomerInformationRequest(char *uuid, char *payload)
  11076. {
  11077. mtrace();
  11078. int result = FAIL;
  11079. json_object *CustomerInformation;
  11080. DEBUG_INFO("handleCustomerInformationRequest...\n");
  11081. CustomerInformation = json_tokener_parse(payload);
  11082. if(!is_error(CustomerInformation))
  11083. {
  11084. // Required data
  11085. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  11086. {
  11087. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  11088. }
  11089. if(json_object_object_get(CustomerInformation, "report") != NULL)
  11090. {
  11091. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  11092. }
  11093. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  11094. {
  11095. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  11096. }
  11097. // Optional data
  11098. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  11099. {
  11100. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  11101. {
  11102. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  11103. }
  11104. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  11105. {
  11106. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  11107. }
  11108. }
  11109. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  11110. {
  11111. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  11112. {
  11113. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  11114. }
  11115. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  11116. {
  11117. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  11118. }
  11119. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  11120. {
  11121. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  11122. }
  11123. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  11124. {
  11125. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  11126. }
  11127. }
  11128. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  11129. }
  11130. else
  11131. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  11132. json_object_put(CustomerInformation);
  11133. sendCustomerInformationConfirmation(uuid);
  11134. return result;
  11135. }
  11136. void createFirmwareVersionByDataTransfer(void)
  11137. {
  11138. json_object *FirmwareDataTransfer = json_object_new_object();
  11139. // AC & DC model
  11140. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  11141. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  11142. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  11143. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  11144. // DC model
  11145. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  11146. {
  11147. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  11148. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  11149. (gunType[3] != GUN_TYPE_UNKNOWN))
  11150. {
  11151. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  11152. }
  11153. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  11154. {
  11155. // DS DM DW
  11156. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  11157. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  11158. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  11159. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  11160. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  11161. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  11162. }
  11163. else
  11164. {
  11165. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  11166. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  11167. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  11168. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  11169. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  11170. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  11171. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  11172. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  11173. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  11174. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  11175. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  11176. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  11177. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  11178. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  11179. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  11180. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  11181. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  11182. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  11183. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  11184. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  11185. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  11186. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  11187. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  11188. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  11189. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  11190. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  11191. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  11192. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  11193. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  11194. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  11195. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  11196. }
  11197. }
  11198. // 4G model
  11199. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  11200. {
  11201. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  11202. }
  11203. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  11204. json_object_put(FirmwareDataTransfer);
  11205. }
  11206. int handleDataTransferRequest(char *uuid, char *payload)
  11207. {
  11208. mtrace();
  11209. int result = PASS;
  11210. DEBUG_INFO("handleDataTransferRequest...\n");
  11211. if((uuid != NULL) && (payload != NULL))
  11212. {
  11213. json_object *DataTransfer;
  11214. DataTransfer = json_tokener_parse(payload);
  11215. if(!is_error(DataTransfer))
  11216. {
  11217. // Required data
  11218. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  11219. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  11220. // Optional data
  11221. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  11222. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  11223. if(json_object_object_get(DataTransfer, "data") != NULL)
  11224. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  11225. result = PASS;
  11226. }
  11227. json_object_put(DataTransfer);
  11228. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  11229. {
  11230. // Send all moudle firmware version on EVSE
  11231. createFirmwareVersionByDataTransfer();
  11232. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11233. }
  11234. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  11235. {
  11236. system("/usr/bin/run_tmate_restart.sh &");
  11237. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11238. }
  11239. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  11240. {
  11241. json_object *data;
  11242. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11243. if(!is_error(data))
  11244. {
  11245. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  11246. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  11247. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  11248. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  11249. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  11250. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  11251. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  11252. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  11253. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  11254. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  11255. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11256. }
  11257. else
  11258. {
  11259. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11260. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11261. }
  11262. json_object_put(data);
  11263. }
  11264. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  11265. {
  11266. json_object *data;
  11267. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11268. if(!is_error(data))
  11269. {
  11270. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11271. if(json_object_object_get(data, "Content_Type") != NULL)
  11272. {
  11273. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  11274. {
  11275. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  11276. if(json_object_object_get(data, "Customization_Conent") != NULL)
  11277. {
  11278. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  11279. }
  11280. }
  11281. else
  11282. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11283. }
  11284. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  11285. }
  11286. else
  11287. {
  11288. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11289. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11290. }
  11291. json_object_put(data);
  11292. }
  11293. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DsiplayLcdPage") != NULL)
  11294. {
  11295. json_object *data;
  11296. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11297. if(!is_error(data))
  11298. {
  11299. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11300. if(json_object_object_get(data, "Page_Index") != NULL)
  11301. {
  11302. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  11303. }
  11304. if(json_object_object_get(data, "Duration") != NULL)
  11305. {
  11306. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  11307. }
  11308. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  11309. }
  11310. else
  11311. {
  11312. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11313. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11314. }
  11315. json_object_put(data);
  11316. }
  11317. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  11318. {
  11319. json_object *data;
  11320. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11321. if(!is_error(data))
  11322. {
  11323. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11324. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  11325. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  11326. {
  11327. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  11328. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  11329. else
  11330. {
  11331. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11332. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11333. }
  11334. }
  11335. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  11336. {
  11337. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  11338. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  11339. else
  11340. {
  11341. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11342. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11343. }
  11344. }
  11345. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  11346. {
  11347. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  11348. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  11349. else
  11350. {
  11351. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11352. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11353. }
  11354. }
  11355. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  11356. {
  11357. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  11358. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  11359. else
  11360. {
  11361. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11362. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11363. }
  11364. }
  11365. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  11366. {
  11367. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  11368. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  11369. else
  11370. {
  11371. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11372. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11373. }
  11374. }
  11375. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  11376. {
  11377. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  11378. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  11379. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  11380. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  11381. else
  11382. {
  11383. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11384. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11385. }
  11386. }
  11387. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  11388. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  11389. }
  11390. else
  11391. {
  11392. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11393. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11394. }
  11395. json_object_put(data);
  11396. }
  11397. else
  11398. {
  11399. // Can not find valid message id
  11400. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  11401. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  11402. ,ShmOCPP20Data->DataTransfer[0].vendorId
  11403. ,ShmOCPP20Data->DataTransfer[0].messageId
  11404. ,ShmOCPP20Data->DataTransfer[0].data);
  11405. }
  11406. }
  11407. else
  11408. {
  11409. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  11410. result = FAIL;
  11411. }
  11412. sendDataTransferConfirmation(uuid, 0);
  11413. return result;
  11414. }
  11415. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11416. {
  11417. mtrace();
  11418. int result = FAIL;
  11419. json_object *DeleteCertificate;
  11420. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11421. DeleteCertificate = json_tokener_parse(payload);
  11422. if(!is_error(DeleteCertificate))
  11423. {
  11424. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  11425. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  11426. // Required data
  11427. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  11428. {
  11429. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  11430. {
  11431. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11432. }
  11433. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  11434. {
  11435. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11436. }
  11437. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  11438. {
  11439. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11440. }
  11441. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  11442. {
  11443. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11444. }
  11445. /*
  11446. * TODO:
  11447. * 1. Delete certification and response
  11448. */
  11449. if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA256]) != NULL)
  11450. {
  11451. }
  11452. else if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA384]) != NULL)
  11453. {
  11454. }
  11455. else
  11456. {
  11457. }
  11458. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  11459. }
  11460. }
  11461. else
  11462. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  11463. json_object_put(DeleteCertificate);
  11464. sendDeleteCertificateConfirmation(uuid);
  11465. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11466. return result;
  11467. }
  11468. int handleGetBaseReportRequest(char *uuid, char *payload)
  11469. {
  11470. mtrace();
  11471. int result = FAIL;
  11472. json_object *GetBaseRepor;
  11473. DEBUG_INFO("handleGetBaseReportRequest...\n");
  11474. GetBaseRepor = json_tokener_parse(payload);
  11475. if(!is_error(GetBaseRepor))
  11476. {
  11477. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  11478. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  11479. // Required data
  11480. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  11481. {
  11482. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  11483. }
  11484. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  11485. {
  11486. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  11487. }
  11488. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  11489. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  11490. else
  11491. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11492. }
  11493. else
  11494. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  11495. json_object_put(GetBaseRepor);
  11496. sendGetBaseReportConfirmation(uuid);
  11497. return result;
  11498. }
  11499. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  11500. {
  11501. mtrace();
  11502. int result = FAIL;
  11503. int gun_index = -1;
  11504. json_object *GetChargingProfiles;
  11505. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  11506. GetChargingProfiles = json_tokener_parse(payload);
  11507. if(!is_error(GetChargingProfiles))
  11508. {
  11509. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  11510. {
  11511. 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;
  11512. }
  11513. if(gun_index >-1)
  11514. {
  11515. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  11516. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  11517. // Required data
  11518. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  11519. {
  11520. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  11521. }
  11522. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  11523. {
  11524. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  11525. {
  11526. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  11527. }
  11528. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  11529. {
  11530. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  11531. }
  11532. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  11533. {
  11534. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  11535. {
  11536. 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)));
  11537. }
  11538. }
  11539. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  11540. {
  11541. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  11542. {
  11543. 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));
  11544. }
  11545. }
  11546. }
  11547. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  11548. }
  11549. else
  11550. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  11551. }
  11552. json_object_put(GetChargingProfiles);
  11553. sendGetChargingProfilesConfirmation(uuid, gun_index);
  11554. return result;
  11555. }
  11556. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  11557. {
  11558. mtrace();
  11559. int result = FAIL;
  11560. int connectorIdInt, durationInt;
  11561. char chargingRateUnitStr[4]={0};
  11562. char comfirmstr[20];
  11563. int confirmPeriods = 0;
  11564. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  11565. json_object *GetCompositeSchedule;
  11566. GetCompositeSchedule = json_tokener_parse(payload);
  11567. if(!is_error(GetCompositeSchedule))
  11568. {
  11569. // Required data
  11570. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  11571. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  11572. else
  11573. connectorIdInt = -1;
  11574. if(json_object_object_get(GetCompositeSchedule, "duration"))
  11575. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  11576. else
  11577. durationInt = 86400;
  11578. // Optional data
  11579. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  11580. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  11581. }
  11582. json_object_put(GetCompositeSchedule);
  11583. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  11584. if((connectorIdInt == 0) ||
  11585. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  11586. {
  11587. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  11588. struct ChargingProfileType tmpProfile[1];
  11589. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  11590. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  11591. if(strstr(chargingRateUnitStr, "W") != NULL)
  11592. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  11593. else
  11594. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  11595. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  11596. {
  11597. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  11598. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  11599. }
  11600. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct CompositeScheduleType));
  11601. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  11602. {
  11603. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  11604. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  11605. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  11606. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  11607. (idx<(ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod)-1)?(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx+1].startPeriod==0):TRUE))
  11608. {
  11609. confirmPeriods = idx;
  11610. break;
  11611. }
  11612. }
  11613. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  11614. {
  11615. confirmPeriods += 1;
  11616. }
  11617. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  11618. }
  11619. else
  11620. {
  11621. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  11622. }
  11623. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  11624. return result;
  11625. }
  11626. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  11627. {
  11628. mtrace();
  11629. int result = FAIL;
  11630. json_object *GetDisplayMessages;
  11631. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  11632. GetDisplayMessages = json_tokener_parse(payload);
  11633. if(!is_error(GetDisplayMessages))
  11634. {
  11635. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  11636. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  11637. // Required data
  11638. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  11639. {
  11640. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  11641. }
  11642. // Optional data
  11643. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  11644. {
  11645. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  11646. }
  11647. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  11648. {
  11649. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  11650. }
  11651. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  11652. {
  11653. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  11654. {
  11655. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  11656. }
  11657. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  11658. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  11659. }
  11660. else
  11661. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  11662. }
  11663. json_object_put(GetDisplayMessages);
  11664. return result;
  11665. }
  11666. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11667. {
  11668. mtrace();
  11669. int result = FAIL;
  11670. json_object *GetInstalledCertificateIds;
  11671. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11672. GetInstalledCertificateIds = json_tokener_parse(payload);
  11673. if(!is_error(GetInstalledCertificateIds))
  11674. {
  11675. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  11676. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  11677. // Optional data
  11678. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  11679. {
  11680. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  11681. {
  11682. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  11683. /*
  11684. * TODO:
  11685. * 1. Get installed certificate info for response
  11686. */
  11687. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GRootCertificate]) != NULL)
  11688. {
  11689. }
  11690. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_MORootCertificate]) != NULL)
  11691. {
  11692. }
  11693. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_CSMSRootCertificate]) != NULL)
  11694. {
  11695. }
  11696. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GCertificateChain]) != NULL)
  11697. {
  11698. }
  11699. else
  11700. {
  11701. }
  11702. }
  11703. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  11704. }
  11705. else
  11706. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  11707. }
  11708. json_object_put(GetInstalledCertificateIds);
  11709. sendInstallCertificateConfirmation(uuid);
  11710. return result;
  11711. }
  11712. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11713. {
  11714. mtrace();
  11715. int result = FAIL;
  11716. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11717. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  11718. {
  11719. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11720. localversion = -1;
  11721. }
  11722. else
  11723. {
  11724. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11725. DB_getListVerion();
  11726. }
  11727. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  11728. sendGetLocalListVersionConfirmation(uuid);
  11729. return result;
  11730. }
  11731. static char fnamePlusPath[100]={0};
  11732. static char fnamePWithNoPath[60]={0};
  11733. void checkUploadLog(void)
  11734. {
  11735. FILE *fp;
  11736. /* Open the command for reading. */
  11737. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  11738. if (fp == NULL) {
  11739. printf("Failed to run command\n" );
  11740. exit(1);
  11741. }
  11742. int ftppathlen = 0;
  11743. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  11744. int i = 0;
  11745. /* Read the output a line at a time - output it. */
  11746. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  11747. if(i==0)
  11748. {
  11749. ftppathlen = strlen(fnamePlusPath);
  11750. printf("%s\n", fnamePlusPath);
  11751. fnamePlusPath[ftppathlen]='\0';
  11752. break;
  11753. }
  11754. i= i+1;
  11755. }
  11756. /* close */
  11757. pclose(fp);
  11758. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  11759. {
  11760. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  11761. {
  11762. fnamePlusPath[k]='\0';
  11763. }
  11764. }
  11765. i=1;
  11766. //char fname[60]={0};
  11767. while(i < ftppathlen)
  11768. {
  11769. int len=ftppathlen-i;
  11770. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11771. {
  11772. printf("compare '/' all right\n");
  11773. break;
  11774. }
  11775. i=i+1;
  11776. }
  11777. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11778. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11779. fnamePWithNoPath[i+1] = '\0';
  11780. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11781. {
  11782. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11783. {
  11784. fnamePWithNoPath[j]='\0';
  11785. }
  11786. }
  11787. FILE* fp1 = fopen(fnamePlusPath, "r");
  11788. if (fp1)
  11789. {
  11790. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11791. // file exists
  11792. fclose(fp1);
  11793. }
  11794. else
  11795. {
  11796. // file doesn't exist
  11797. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11798. }
  11799. }
  11800. void* GetLogProcess(void* data)
  11801. {
  11802. pthread_detach(pthread_self());
  11803. mtrace();
  11804. int requestId, retriesInt=0, retryIntervalInt=0;
  11805. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  11806. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  11807. int port=0;
  11808. int isSuccess = FALSE;
  11809. char ftpbuf[1024]={0};
  11810. char cmdBuf[2048];
  11811. struct tm *tmNow;
  11812. time_t CurrentTime;
  11813. struct tm tmStart;
  11814. struct tm tmStop;
  11815. CurrentTime = time(NULL);
  11816. tmNow=localtime(&CurrentTime);
  11817. uint16_t targetYear, targetMonth;
  11818. json_object *GetLog;
  11819. DEBUG_INFO("GetGetProcess...\n");
  11820. GetLog = json_tokener_parse(data);
  11821. if(!is_error(GetLog))
  11822. {
  11823. // Required data
  11824. if(json_object_object_get(GetLog, "requestId") != NULL)
  11825. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11826. if(json_object_object_get(GetLog, "logType") != NULL)
  11827. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11828. if(json_object_object_get(GetLog, "log") != NULL)
  11829. {
  11830. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  11831. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11832. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11833. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11834. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11835. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11836. }
  11837. // Optional data
  11838. if(json_object_object_get(GetLog, "retries") != NULL)
  11839. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11840. else
  11841. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11842. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11843. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11844. else
  11845. retryIntervalInt = 30;
  11846. }
  11847. json_object_put(GetLog);
  11848. ShmOCPP20Data->GetLog.requestId = requestId;
  11849. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  11850. {
  11851. /*
  11852. * TODO:
  11853. * 1. Pack security log
  11854. */
  11855. }
  11856. else
  11857. {
  11858. // Pack log to compress file
  11859. if((sscanf((char*)oldestTimestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  11860. (sscanf((char*)latestTimestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  11861. {
  11862. // Pack system log
  11863. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11864. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11865. targetYear = tmStart.tm_year;
  11866. targetMonth = tmStart.tm_mon;
  11867. do
  11868. {
  11869. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11870. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11871. if(targetMonth+1>=13)
  11872. {
  11873. targetYear += 1;
  11874. targetMonth = 1;
  11875. }
  11876. else
  11877. {
  11878. targetMonth += 1;
  11879. }
  11880. }while((targetYear < (tmNow->tm_year+1900)) ||
  11881. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11882. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11883. system(cmdBuf);
  11884. // Pack charging & event log
  11885. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11886. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11887. targetYear = tmStart.tm_year;
  11888. targetMonth = tmStart.tm_mon;
  11889. do
  11890. {
  11891. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11892. if(targetMonth+1>=13)
  11893. {
  11894. targetYear += 1;
  11895. targetMonth = 1;
  11896. }
  11897. else
  11898. {
  11899. targetMonth += 1;
  11900. }
  11901. }while((targetYear < (tmNow->tm_year+1900)) ||
  11902. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11903. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11904. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11905. system(cmdBuf);
  11906. // Combine log file
  11907. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11908. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11909. }
  11910. else
  11911. {
  11912. system("exec /root/logPackTools 'log' 6");
  11913. }
  11914. }
  11915. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  11916. system(cmdBuf);
  11917. checkUploadLog();
  11918. //****************location*******************/
  11919. if(strcmp(remoteLocation,"")==0)
  11920. {
  11921. DEBUG_INFO("remoteLocation is <Empty>!\n");
  11922. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11923. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11924. goto end;
  11925. }
  11926. memset(protocol, 0, ARRAY_SIZE(protocol));
  11927. memset(user, 0, ARRAY_SIZE(user) );
  11928. memset(password, 0, ARRAY_SIZE(password));
  11929. memset(host, 0, ARRAY_SIZE(host));
  11930. memset(path, 0, ARRAY_SIZE(path));
  11931. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11932. memset(host1, 0, ARRAY_SIZE(host1));
  11933. memset(path1, 0, ARRAY_SIZE(path1));
  11934. /*location: ftp://user:password@host:port/path*/
  11935. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11936. if((access(fnamePlusPath,F_OK))!=-1)
  11937. {
  11938. DEBUG_INFO("fnamePlusPath exist.\n");
  11939. }
  11940. else
  11941. {
  11942. DEBUG_INFO("fnamePlusPath not exist!\n");
  11943. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11944. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11945. goto end;
  11946. }
  11947. if(strchr(remoteLocation,'@')==NULL)
  11948. {
  11949. sscanf(remoteLocation,
  11950. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11951. protocol, host, &port, path);
  11952. strcpy(user,"anonymous");
  11953. strcpy(password,"");
  11954. }
  11955. else
  11956. {
  11957. //DEBUG_INFO("pch=%s\n", pch);
  11958. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11959. protocol, user, password, host, &port, path);
  11960. }
  11961. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11962. {
  11963. DEBUG_INFO("protocol is not ftp/http ! \n");
  11964. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11965. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11966. goto end;
  11967. }
  11968. if(strncmp(remoteLocation,"http", 4) == 0)
  11969. {
  11970. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11971. sprintf(ftppath,"/%s", path);
  11972. do
  11973. {
  11974. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  11975. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11976. sleep(3);
  11977. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  11978. if(!isSuccess)
  11979. {
  11980. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  11981. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11982. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11983. sleep(retryIntervalInt);
  11984. }
  11985. else
  11986. {
  11987. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  11988. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  11989. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11990. }
  11991. retriesInt--;
  11992. }while((isSuccess == 0)&&(retriesInt >= 0));
  11993. }
  11994. else
  11995. {
  11996. sscanf(host,"%[^/]%s",host1, path1);
  11997. if(strlen(path) > 0)
  11998. sprintf(ftppath,"/%s", path);
  11999. else
  12000. sprintf(ftppath,"/%s", path1);
  12001. int ftppathlen=strlen(ftppath);
  12002. int i=1;
  12003. char filenametemp[50];
  12004. while(i < ftppathlen)
  12005. {
  12006. int len=ftppathlen-i;
  12007. if(ftppath[len]== 47) // '/' ascll code: 47
  12008. {
  12009. DEBUG_INFO("find '/' all right\n");
  12010. break;
  12011. }
  12012. i=i+1;
  12013. }
  12014. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12015. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12016. filenametemp[i+1] = 0;
  12017. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12018. if(port == 0)
  12019. port = 21;
  12020. do
  12021. {
  12022. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  12023. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12024. sleep(3);
  12025. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  12026. if(!isSuccess)
  12027. {
  12028. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  12029. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  12030. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12031. sleep(retryIntervalInt);
  12032. }
  12033. else
  12034. {
  12035. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  12036. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  12037. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12038. }
  12039. retriesInt--;
  12040. }while((!isSuccess)&&(retriesInt >= 0));
  12041. }
  12042. end:
  12043. system("rm -f /mnt/*");
  12044. sleep(5);
  12045. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  12046. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12047. interLock.isGetLogGoing = OFF;
  12048. pthread_exit(NULL);
  12049. }
  12050. int handleGetLogRequest(char *uuid, char *payload)
  12051. {
  12052. mtrace();
  12053. int result = FAIL;
  12054. char fName[258];
  12055. time_t CurrentTime;
  12056. struct tm *tm;
  12057. pthread_t th_Status;
  12058. CurrentTime = time(NULL);
  12059. tm = localtime(&CurrentTime);
  12060. 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);
  12061. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  12062. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  12063. sendGetLogConfirmation(uuid);
  12064. if(!interLock.isGetLogGoing)
  12065. {
  12066. interLock.isGetLogGoing = ON;
  12067. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  12068. }
  12069. else
  12070. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  12071. return result;
  12072. }
  12073. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  12074. {
  12075. mtrace();
  12076. int result = FAIL;
  12077. json_object *GetMonitoringReport;
  12078. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  12079. GetMonitoringReport = json_tokener_parse(payload);
  12080. if(!is_error(GetMonitoringReport))
  12081. {
  12082. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  12083. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  12084. // Required data
  12085. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  12086. {
  12087. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  12088. }
  12089. // Optional data
  12090. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  12091. {
  12092. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  12093. }
  12094. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  12095. {
  12096. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  12097. {
  12098. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  12099. {
  12100. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  12101. {
  12102. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  12103. {
  12104. 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")));
  12105. }
  12106. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  12107. {
  12108. 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")));
  12109. }
  12110. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  12111. {
  12112. 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)
  12113. {
  12114. 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"));
  12115. }
  12116. 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)
  12117. {
  12118. 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"));
  12119. }
  12120. }
  12121. }
  12122. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  12123. {
  12124. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  12125. {
  12126. 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")));
  12127. }
  12128. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  12129. {
  12130. 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")));
  12131. }
  12132. }
  12133. }
  12134. }
  12135. }
  12136. }
  12137. json_object_put(GetMonitoringReport);
  12138. /*
  12139. * TODO:
  12140. * 1. Response result
  12141. */
  12142. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12143. sendGetMonitoringReportConfirmation(uuid);
  12144. return result;
  12145. }
  12146. int handleGetReportRequest(char *uuid, char *payload)
  12147. {
  12148. mtrace();
  12149. int result = FAIL;
  12150. json_object *GetReport;
  12151. DEBUG_INFO("handleGetReportRequest...\n");
  12152. GetReport = json_tokener_parse(payload);
  12153. if(!is_error(GetReport))
  12154. {
  12155. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  12156. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  12157. // Required data
  12158. if(json_object_object_get(GetReport, "requestId") != NULL)
  12159. {
  12160. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  12161. }
  12162. // Optional data
  12163. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  12164. {
  12165. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  12166. }
  12167. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  12168. {
  12169. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  12170. {
  12171. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  12172. {
  12173. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  12174. {
  12175. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  12176. {
  12177. 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")));
  12178. }
  12179. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  12180. {
  12181. 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")));
  12182. }
  12183. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  12184. {
  12185. 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)
  12186. {
  12187. 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"));
  12188. }
  12189. 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)
  12190. {
  12191. 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"));
  12192. }
  12193. }
  12194. }
  12195. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  12196. {
  12197. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  12198. {
  12199. 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")));
  12200. }
  12201. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  12202. {
  12203. 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")));
  12204. }
  12205. }
  12206. }
  12207. }
  12208. }
  12209. }
  12210. json_object_put(GetReport);
  12211. /*
  12212. * TODO:
  12213. * 1. Response result
  12214. */
  12215. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12216. sendGetReportConfirmation(uuid);
  12217. return result;
  12218. }
  12219. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  12220. {
  12221. mtrace();
  12222. int result = FAIL;
  12223. int8_t gun_index = -1;
  12224. json_object *GetTransactionStatus;
  12225. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  12226. GetTransactionStatus = json_tokener_parse(payload);
  12227. if(!is_error(GetTransactionStatus))
  12228. {
  12229. /*
  12230. * TODO:
  12231. * 1. Check transaction locate which connector
  12232. */
  12233. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  12234. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  12235. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  12236. {
  12237. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  12238. }
  12239. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  12240. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  12241. }
  12242. json_object_put(GetTransactionStatus);
  12243. sendGetTransactionStatusConfirmation(uuid, gun_index);
  12244. return result;
  12245. }
  12246. int handleGetVariablesRequest(char *uuid, char *payload)
  12247. {
  12248. mtrace();
  12249. int result = FAIL;
  12250. json_object *GetVariables;
  12251. DEBUG_INFO("handleGetVariablesRequest...\n");
  12252. GetVariables = json_tokener_parse(payload);
  12253. if(!is_error(GetVariables))
  12254. {
  12255. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  12256. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  12257. // Required data
  12258. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  12259. {
  12260. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  12261. {
  12262. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  12263. {
  12264. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  12265. {
  12266. 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")));
  12267. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  12268. }
  12269. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  12270. {
  12271. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  12272. {
  12273. 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")));
  12274. }
  12275. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  12276. {
  12277. 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")));
  12278. }
  12279. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  12280. {
  12281. 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)
  12282. {
  12283. 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"));
  12284. }
  12285. 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)
  12286. {
  12287. 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"));
  12288. }
  12289. }
  12290. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  12291. }
  12292. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  12293. {
  12294. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  12295. {
  12296. 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")));
  12297. }
  12298. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  12299. {
  12300. 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")));
  12301. }
  12302. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  12303. }
  12304. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  12305. {
  12306. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  12307. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance) == 0) &&
  12308. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  12309. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance) == 0))
  12310. {
  12311. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  12312. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  12313. break;
  12314. }
  12315. else
  12316. {
  12317. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  12318. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  12319. }
  12320. }
  12321. }
  12322. }
  12323. }
  12324. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  12325. }
  12326. json_object_put(GetVariables);
  12327. return result;
  12328. }
  12329. int handleInstallCertificateRequest(char *uuid, char *payload)
  12330. {
  12331. mtrace();
  12332. int result = FAIL;
  12333. json_object *InstallCertificate;
  12334. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12335. InstallCertificate = json_tokener_parse(payload);
  12336. if(!is_error(InstallCertificate))
  12337. {
  12338. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  12339. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  12340. // Required data
  12341. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  12342. {
  12343. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12344. }
  12345. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  12346. {
  12347. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12348. }
  12349. }
  12350. json_object_put(InstallCertificate);
  12351. /*
  12352. * TODO:
  12353. * 1. Install certification preocess and response
  12354. */
  12355. if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]))
  12356. {
  12357. }
  12358. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]))
  12359. {
  12360. }
  12361. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]))
  12362. {
  12363. }
  12364. else
  12365. {
  12366. }
  12367. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12368. sendInstallCertificateConfirmation(uuid);
  12369. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12370. return result;
  12371. }
  12372. int handlePublishFirmwareRequest(char *uuid, char *payload)
  12373. {
  12374. mtrace();
  12375. int result = FAIL;
  12376. json_object *PublishFirmware;
  12377. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  12378. PublishFirmware = json_tokener_parse(payload);
  12379. if(!is_error(PublishFirmware))
  12380. {
  12381. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  12382. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  12383. // Required data
  12384. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  12385. {
  12386. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  12387. }
  12388. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  12389. {
  12390. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  12391. }
  12392. // Optional data
  12393. if(json_object_object_get(PublishFirmware, "location") != NULL)
  12394. {
  12395. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  12396. }
  12397. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  12398. {
  12399. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  12400. }
  12401. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  12402. {
  12403. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  12404. }
  12405. }
  12406. json_object_put(PublishFirmware);
  12407. /*
  12408. * TODO:
  12409. * 1. Publish firmware preocess and response
  12410. */
  12411. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12412. sendPublishFirmwareConfirmation(uuid);
  12413. return result;
  12414. }
  12415. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  12416. {
  12417. mtrace();
  12418. int result = FAIL;
  12419. int8_t gun_index = -1;
  12420. uint8_t tempIndex;
  12421. uint8_t isPeriodOverMax = FALSE;
  12422. uint8_t isProfileOverMax = FALSE;
  12423. uint8_t isTxProfile = TRUE;
  12424. uint8_t isAllowStart = TRUE;
  12425. uint8_t existProfileQuantity = 0;
  12426. uint8_t filename[128]={0};
  12427. uint8_t word[2048]={0};
  12428. char cmdBuf[128];
  12429. FILE *filePtr;
  12430. json_object *RemoteStartTransaction;
  12431. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  12432. RemoteStartTransaction = json_tokener_parse(payload);
  12433. if(!is_error(RemoteStartTransaction))
  12434. {
  12435. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  12436. {
  12437. gun_index = ((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))?(json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))-1):-1;
  12438. }
  12439. else
  12440. {
  12441. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12442. {
  12443. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  12444. {
  12445. gun_index = idx;
  12446. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", (gun_index+1));
  12447. break;
  12448. }
  12449. }
  12450. }
  12451. if(gun_index >= 0)
  12452. {
  12453. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  12454. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  12455. // Required data
  12456. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  12457. {
  12458. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  12459. }
  12460. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  12461. {
  12462. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  12463. {
  12464. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  12465. }
  12466. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  12467. {
  12468. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  12469. }
  12470. }
  12471. // Optional data
  12472. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  12473. {
  12474. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  12475. {
  12476. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  12477. }
  12478. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  12479. {
  12480. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  12481. }
  12482. }
  12483. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  12484. {
  12485. // Check periods is over max configuration
  12486. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  12487. {
  12488. isPeriodOverMax = TRUE;
  12489. }
  12490. // Check profile purpose is TxProfile
  12491. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  12492. {
  12493. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", (gun_index+1));
  12494. filePtr = fopen((char*)filename, "r");
  12495. if (!filePtr)
  12496. {
  12497. DEBUG_INFO("%s not exist, create it.\n", filename);
  12498. filePtr = fopen((char*)filename, "w+");
  12499. }
  12500. else
  12501. {
  12502. //Check Charging Profile Count
  12503. while(fscanf(filePtr, "%s", word) != EOF)
  12504. {
  12505. //DEBUG_INFO("word=%s\n",word);
  12506. if(strstr((char*)word, "chargingProfileId")!= NULL)
  12507. {
  12508. existProfileQuantity += 1;
  12509. }
  12510. }
  12511. }
  12512. fclose(filePtr);
  12513. }
  12514. else
  12515. {
  12516. isTxProfile = FALSE;
  12517. }
  12518. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  12519. isProfileOverMax = TRUE;
  12520. }
  12521. //check Transaction active
  12522. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  12523. {
  12524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12525. {
  12526. tempIndex = (gun_index == 2) ? 1: 0;
  12527. }
  12528. else
  12529. {
  12530. tempIndex = gun_index;
  12531. }
  12532. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12533. {
  12534. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  12535. {
  12536. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) == 0))
  12537. {
  12538. //Reserved
  12539. DEBUG_INFO("Reserved now! The idTag matches the idTag of Reservation!\n");
  12540. }
  12541. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) != 0))
  12542. {
  12543. //Reserved
  12544. DEBUG_INFO("Reserved now! The idTag does NOT match the idTag of Reservation! Reject it!\n");
  12545. isAllowStart = FALSE;
  12546. }
  12547. else
  12548. {
  12549. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12550. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  12551. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  12552. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  12553. {
  12554. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  12555. isAllowStart = FALSE;
  12556. }
  12557. }//END FOR ELSE
  12558. }
  12559. }// END FOR CHAdeMO_QUANTITY
  12560. }
  12561. else if(gunType[gun_index] == GUN_TYPE_CCS)
  12562. {
  12563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12564. {
  12565. tempIndex = (gun_index == 2) ? 1: 0;
  12566. }
  12567. else
  12568. {
  12569. tempIndex = gun_index;
  12570. }
  12571. for (int index = 0; index < CCS_QUANTITY; index++)
  12572. {
  12573. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12574. {
  12575. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) == 0))
  12576. {
  12577. //Reserved
  12578. DEBUG_INFO("Reserved now! The idTag matches the idTag of Reservation!\n");
  12579. }
  12580. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) != 0))
  12581. {
  12582. //Reserved
  12583. DEBUG_INFO("Reserved now! The idTag does NOT match the idTag of Reservation! Reject it!\n");
  12584. isAllowStart = FALSE;
  12585. }
  12586. else
  12587. {
  12588. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12589. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  12590. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  12591. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  12592. {
  12593. DEBUG_WARN("CCS connector not allow start\n.");
  12594. isAllowStart = FALSE;
  12595. }
  12596. }// END FOR ELSE
  12597. }
  12598. }// END FOR CCS_QUANTITY
  12599. }
  12600. else if(gunType[gun_index] == GUN_TYPE_GBT)
  12601. {
  12602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12603. {
  12604. tempIndex = (gun_index == 2) ? 1: 0;
  12605. }
  12606. else
  12607. {
  12608. tempIndex = gun_index;
  12609. }
  12610. for (int index = 0; index < GB_QUANTITY; index++)
  12611. {
  12612. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  12613. {
  12614. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) == 0))
  12615. {
  12616. //Reserved
  12617. DEBUG_INFO("Reserved now! The idTag matches the idTag of Reservation!\n");
  12618. }
  12619. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) != 0))
  12620. {
  12621. //Reserved
  12622. DEBUG_INFO("Reserved now! The idTag does NOT match the idTag of Reservation! Reject it!\n");
  12623. isAllowStart = FALSE;
  12624. }
  12625. else
  12626. {
  12627. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12628. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  12629. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  12630. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  12631. {
  12632. DEBUG_WARN("GB connector not allow start\n.");
  12633. isAllowStart = FALSE;
  12634. }
  12635. }// END FOR ELSE
  12636. }
  12637. } // END FOR GB_QUANTITY
  12638. }
  12639. else if(gunType[gun_index] == GUN_TYPE_DO)
  12640. {
  12641. tempIndex = gun_index;
  12642. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12643. {
  12644. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  12645. {
  12646. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) == 0))
  12647. {
  12648. //Reserved
  12649. DEBUG_INFO("Reserved now! The idTag matches the idTag of Reservation!\n");
  12650. }
  12651. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) != 0))
  12652. {
  12653. //Reserved
  12654. DEBUG_INFO("Reserved now! The idTag does NOT match the idTag of Reservation! Reject it!\n");
  12655. isAllowStart = FALSE;
  12656. }
  12657. else
  12658. {
  12659. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12660. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  12661. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  12662. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  12663. {
  12664. DEBUG_WARN("GB connector not allow start\n.");
  12665. isAllowStart = FALSE;
  12666. }
  12667. }// END FOR ELSE
  12668. }
  12669. } // END FOR GB_QUANTITY
  12670. }
  12671. else
  12672. {
  12673. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12674. {
  12675. tempIndex = 2;
  12676. }
  12677. else
  12678. {
  12679. tempIndex = gun_index;
  12680. }
  12681. for (int index = 0; index < AC_QUANTITY; index++)
  12682. {
  12683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  12684. {
  12685. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) == 0))
  12686. {
  12687. //Reserved
  12688. DEBUG_INFO("Reserved now! The idTag matches the idTag of Reservation!\n");
  12689. }
  12690. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken) != 0))
  12691. {
  12692. //Reserved
  12693. DEBUG_INFO("Reserved now! The idTag does NOT match the idTag of Reservation! Reject it!\n");
  12694. isAllowStart = FALSE;
  12695. }
  12696. else
  12697. {
  12698. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12699. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  12700. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  12701. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  12702. {
  12703. DEBUG_WARN("AC connector not allow start\n.");
  12704. isAllowStart = FALSE;
  12705. }
  12706. }//END FOR ELSE
  12707. }
  12708. }// END FOR AC_QUANTITY
  12709. }
  12710. }
  12711. // Profile replace or add info
  12712. if((gun_index >= 0) && !isPeriodOverMax && !isProfileOverMax && isTxProfile && isAllowStart)
  12713. {
  12714. if(strlen((char*)filename) > 0)
  12715. {
  12716. // Save profile to file
  12717. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", (gun_index+1));
  12718. system(cmdBuf);
  12719. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", (gun_index+1));
  12720. filePtr = fopen((char*)filename, "w");
  12721. fprintf(filePtr, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", (gun_index+1), json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  12722. fclose(filePtr);
  12723. }
  12724. ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq = ON;
  12725. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted] );
  12726. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  12727. result = PASS;
  12728. }
  12729. else
  12730. {
  12731. if(gun_index < 0)
  12732. DEBUG_WARN("Connector id is wrong.\n");
  12733. if(isPeriodOverMax)
  12734. DEBUG_WARN("Profile periods quantity is over spec.\n");
  12735. if(isProfileOverMax)
  12736. DEBUG_WARN("Profile quantity is over spec.\n");
  12737. if(!isTxProfile)
  12738. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  12739. if(!isAllowStart)
  12740. DEBUG_WARN("Target connector does not allow start.\n");
  12741. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index<0?0:gun_index)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  12742. }
  12743. }
  12744. json_object_put(RemoteStartTransaction);
  12745. sendRemoteStartTransactionConfirmation(uuid, (gun_index<0?0:gun_index));
  12746. return result;
  12747. }
  12748. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  12749. {
  12750. mtrace();
  12751. int result = FAIL;
  12752. int match = FALSE;
  12753. int GunNO = 0;
  12754. int tempIndex = 0;
  12755. char transactionIdStr[37];
  12756. int transactionIdIsNULL= TRUE;
  12757. json_object *RemoteStopTransaction;
  12758. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  12759. if(server_pending == TRUE)
  12760. {
  12761. return 0;
  12762. }
  12763. RemoteStopTransaction = json_tokener_parse(payload);
  12764. if(!is_error(RemoteStopTransaction))
  12765. {
  12766. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  12767. {
  12768. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  12769. transactionIdIsNULL = FALSE;
  12770. }
  12771. }
  12772. json_object_put(RemoteStopTransaction);
  12773. if(transactionIdIsNULL == FALSE)
  12774. {
  12775. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  12776. {
  12777. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  12778. {
  12779. //check Transaction active
  12780. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  12781. {
  12782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12783. {
  12784. tempIndex = ((gun_index==2) ? 1: 0);
  12785. }
  12786. else
  12787. {
  12788. tempIndex = gun_index;
  12789. }
  12790. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12791. {
  12792. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12793. {
  12794. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12795. {
  12796. match = TRUE;
  12797. GunNO = gun_index;
  12798. }
  12799. }
  12800. }// END FOR CHAdeMO_QUANTITY
  12801. }
  12802. else if(gunType[gun_index] == GUN_TYPE_CCS)
  12803. {
  12804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12805. {
  12806. tempIndex = ((gun_index==2) ? 1: 0);
  12807. }
  12808. else
  12809. {
  12810. tempIndex = gun_index;
  12811. }
  12812. for (int index = 0; index < CCS_QUANTITY; index++)
  12813. {
  12814. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12815. {
  12816. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12817. {
  12818. match = TRUE;
  12819. GunNO = gun_index;
  12820. }
  12821. }
  12822. }// END FOR CCS_QUANTITY
  12823. }
  12824. else if(gunType[gun_index] == GUN_TYPE_GBT)
  12825. {
  12826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12827. {
  12828. tempIndex = ((gun_index==2) ? 1: 0);
  12829. }
  12830. else
  12831. {
  12832. tempIndex = gun_index;
  12833. }
  12834. for (int index = 0; index < GB_QUANTITY; index++)
  12835. {
  12836. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12837. {
  12838. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12839. {
  12840. match = TRUE;
  12841. GunNO = gun_index;
  12842. }
  12843. }
  12844. }// END FOR GB_QUANTITY
  12845. }
  12846. else if(gunType[gun_index] == GUN_TYPE_DO)
  12847. {
  12848. tempIndex = gun_index;
  12849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12850. {
  12851. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12852. {
  12853. 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
  12854. {
  12855. match = TRUE;
  12856. GunNO = gun_index;
  12857. }
  12858. }
  12859. }// END FOR GB_QUANTITY
  12860. }
  12861. else
  12862. {
  12863. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12864. {
  12865. tempIndex = 2;
  12866. }
  12867. else
  12868. {
  12869. tempIndex = gun_index;
  12870. }
  12871. for (int index = 0; index < AC_QUANTITY; index++)
  12872. {
  12873. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12874. {
  12875. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12876. {
  12877. match = TRUE;
  12878. GunNO = gun_index;
  12879. }
  12880. }
  12881. }// END FOR CHAdeMO_QUANTITY
  12882. } // END FOR AC ELSE
  12883. }// CHECK IF ResponseTransactionId == transactionIdInt
  12884. }//END FOR
  12885. if( match == TRUE)
  12886. {
  12887. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  12888. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  12889. }
  12890. else
  12891. {
  12892. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  12893. }
  12894. }
  12895. else
  12896. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  12897. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  12898. return result;
  12899. }
  12900. int handleReserveNowRequest(char *uuid, char *payload)
  12901. {
  12902. mtrace();
  12903. int result = FAIL;
  12904. int connectorIdInt=0, reservationIdInt=0;
  12905. int tempIndex = 0;
  12906. json_object *ReserveNow;
  12907. DEBUG_INFO("handleReserveNowRequest ...\n");
  12908. ReserveNow = json_tokener_parse(payload);
  12909. if(!is_error(ReserveNow))
  12910. {
  12911. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  12912. {
  12913. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  12914. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  12915. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  12916. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  12917. }
  12918. // Required data
  12919. if(json_object_object_get(ReserveNow, "reservationId") != NULL)
  12920. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "reservationId"));
  12921. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  12922. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  12923. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  12924. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  12925. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  12926. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  12927. // Optional data
  12928. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  12929. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  12930. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  12931. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  12932. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  12933. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  12934. result = PASS;
  12935. }
  12936. json_object_put(ReserveNow);
  12937. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12938. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12939. {
  12940. //check Transaction active
  12941. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12942. {
  12943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12944. {
  12945. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12946. }
  12947. else
  12948. {
  12949. tempIndex = connectorIdInt -1;
  12950. }
  12951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12952. {
  12953. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12954. {
  12955. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12956. {
  12957. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12958. {
  12959. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12960. {
  12961. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12962. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12963. }
  12964. 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'))
  12965. {
  12966. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12967. }
  12968. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12969. {
  12970. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12971. }
  12972. else
  12973. {
  12974. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12975. }
  12976. }
  12977. 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
  12978. {
  12979. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12980. }
  12981. }
  12982. else
  12983. {
  12984. //replace reservation
  12985. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12986. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12987. }
  12988. }
  12989. } // END FOR CHAdeMO_QUANTITY
  12990. }
  12991. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12992. {
  12993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12994. {
  12995. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12996. }
  12997. else
  12998. {
  12999. tempIndex = connectorIdInt -1;
  13000. }
  13001. for (int index = 0; index < CCS_QUANTITY; index++)
  13002. {
  13003. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13004. {
  13005. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  13006. {
  13007. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  13008. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  13009. {
  13010. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13011. {
  13012. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13013. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13014. }
  13015. 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'))
  13016. {
  13017. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13018. }
  13019. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  13020. {
  13021. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13022. }
  13023. else
  13024. {
  13025. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13026. }
  13027. }
  13028. 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
  13029. {
  13030. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13031. }
  13032. }
  13033. else
  13034. {
  13035. //replace reservation
  13036. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13037. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13038. }
  13039. }
  13040. } // END FOR CCS_QUANTITY
  13041. }
  13042. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  13043. {
  13044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13045. {
  13046. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13047. }
  13048. else
  13049. {
  13050. tempIndex = connectorIdInt -1;
  13051. }
  13052. for (int index = 0; index < GB_QUANTITY; index++)
  13053. {
  13054. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13055. {
  13056. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  13057. {
  13058. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  13059. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  13060. {
  13061. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13062. {
  13063. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13064. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13065. }
  13066. 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'))
  13067. {
  13068. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13069. }
  13070. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  13071. {
  13072. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13073. }
  13074. else
  13075. {
  13076. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13077. }
  13078. }
  13079. 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
  13080. {
  13081. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13082. }
  13083. }
  13084. else
  13085. {
  13086. //replace reservation
  13087. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13088. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13089. }
  13090. }
  13091. }// END FOR GB_QUANTITY
  13092. }
  13093. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  13094. {
  13095. tempIndex = connectorIdInt -1;
  13096. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13097. {
  13098. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13099. {
  13100. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  13101. {
  13102. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  13103. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  13104. {
  13105. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13106. {
  13107. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13108. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13109. }
  13110. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  13111. {
  13112. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13113. }
  13114. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  13115. {
  13116. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13117. }
  13118. else
  13119. {
  13120. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13121. }
  13122. }
  13123. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  13124. {
  13125. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13126. }
  13127. }
  13128. else
  13129. {
  13130. //replace reservation
  13131. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13132. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13133. }
  13134. }
  13135. }// END FOR DO_QUANTITY
  13136. }
  13137. else
  13138. {
  13139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13140. {
  13141. tempIndex = 2;
  13142. }
  13143. else
  13144. {
  13145. tempIndex = (connectorIdInt -1);
  13146. }
  13147. for (int index = 0; index < AC_QUANTITY; index++)
  13148. {
  13149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13150. {
  13151. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  13152. {
  13153. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  13154. {
  13155. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13156. {
  13157. 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))
  13158. {
  13159. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13160. }
  13161. else
  13162. {
  13163. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13164. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13165. }
  13166. }
  13167. 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'))
  13168. {
  13169. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13170. }
  13171. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  13172. {
  13173. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13174. }
  13175. else
  13176. {
  13177. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13178. }
  13179. }
  13180. 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
  13181. {
  13182. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13183. }
  13184. }
  13185. else
  13186. {
  13187. //replace reservation
  13188. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13189. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13190. }
  13191. }
  13192. } // END FOR AC_QUANTITY
  13193. }
  13194. }
  13195. else if(connectorIdInt == 0)
  13196. {
  13197. //check Transaction active
  13198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13199. {
  13200. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  13201. {
  13202. 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'))
  13203. {
  13204. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13205. goto end;
  13206. }
  13207. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  13208. {
  13209. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13210. goto end;
  13211. }
  13212. 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
  13213. {
  13214. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13215. goto end;
  13216. }
  13217. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13218. {
  13219. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13220. goto end;
  13221. }
  13222. }
  13223. }// END FOR CHAdeMO_QUANTITY
  13224. for (int index = 0; index < CCS_QUANTITY; index++)
  13225. {
  13226. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  13227. {
  13228. 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'))
  13229. {
  13230. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13231. goto end;
  13232. }
  13233. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  13234. {
  13235. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13236. goto end;
  13237. }
  13238. 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
  13239. {
  13240. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13241. goto end;
  13242. }
  13243. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13244. {
  13245. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13246. goto end;
  13247. }
  13248. }
  13249. } // END FOR CCS_QUANTITY
  13250. for (int index = 0; index < GB_QUANTITY; index++)
  13251. {
  13252. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  13253. {
  13254. 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'))
  13255. {
  13256. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13257. goto end;
  13258. }
  13259. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  13260. {
  13261. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13262. goto end;
  13263. }
  13264. 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
  13265. {
  13266. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13267. goto end;
  13268. }
  13269. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13270. {
  13271. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13272. goto end;
  13273. }
  13274. }
  13275. } // END FOR GB_QUANTITY
  13276. for (int index = 0; index < AC_QUANTITY; index++)
  13277. {
  13278. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  13279. {
  13280. 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'))
  13281. {
  13282. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13283. goto end;
  13284. }
  13285. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  13286. {
  13287. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13288. goto end;
  13289. }
  13290. 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
  13291. {
  13292. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13293. goto end;
  13294. }
  13295. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13296. {
  13297. 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))
  13298. {
  13299. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13300. goto end;
  13301. }
  13302. }
  13303. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13304. {
  13305. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13306. goto end;
  13307. }
  13308. }
  13309. }// END FOR AC_QUANTITY
  13310. //The connectorId is 0
  13311. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  13312. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13313. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  13314. result = TRUE;
  13315. return result;
  13316. }
  13317. else
  13318. {
  13319. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13320. }
  13321. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  13322. {
  13323. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  13324. result = TRUE;
  13325. return result;
  13326. }
  13327. end:
  13328. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  13329. return result;
  13330. }
  13331. int handleResetRequest(char *uuid, char *payload)
  13332. {
  13333. mtrace();
  13334. int result = FAIL;
  13335. json_object *Reset = json_object_new_object();
  13336. DEBUG_INFO("handleResetRequest...\n");
  13337. Reset = json_tokener_parse(payload);
  13338. if(!is_error(Reset))
  13339. {
  13340. // Required data
  13341. if(json_object_object_get(Reset, "type") != NULL)
  13342. {
  13343. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  13344. }
  13345. if(json_object_object_get(Reset, "evseId") != NULL)
  13346. {
  13347. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  13348. }
  13349. }
  13350. json_object_put(Reset);
  13351. if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
  13352. {
  13353. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  13354. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  13355. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  13356. result = PASS;
  13357. }
  13358. else
  13359. {
  13360. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  13361. }
  13362. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  13363. sendResetConfirmation(uuid);
  13364. return result;
  13365. }
  13366. int handleSendLocalListRequest(char *uuid, char *payload)
  13367. {
  13368. mtrace();
  13369. int result = FAIL;
  13370. char updateTypestr[15]={0};
  13371. int checkState_Faulted = FALSE;
  13372. json_object *SendLocalList;
  13373. DEBUG_INFO("handleSendLocalListRequest...\n");
  13374. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  13375. {
  13376. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  13377. goto end;
  13378. }
  13379. SendLocalList = json_tokener_parse(payload);
  13380. if(!is_error(SendLocalList))
  13381. {
  13382. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  13383. // Required data
  13384. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  13385. {
  13386. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  13387. }
  13388. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  13389. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  13390. // Optional data
  13391. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  13392. {
  13393. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  13394. {
  13395. // Required data
  13396. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  13397. {
  13398. 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")));
  13399. 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")));
  13400. }
  13401. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  13402. {
  13403. 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")));
  13404. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  13405. 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")));
  13406. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  13407. 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"));
  13408. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  13409. {
  13410. 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")));
  13411. 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")));
  13412. }
  13413. }
  13414. }
  13415. }
  13416. }
  13417. json_object_put(SendLocalList);
  13418. //check Charge Point state
  13419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13420. {
  13421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13422. {
  13423. checkState_Faulted = TRUE; //OCPP Status: Faulted
  13424. }
  13425. }
  13426. for (int index = 0; index < CCS_QUANTITY; index++)
  13427. {
  13428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13429. {
  13430. checkState_Faulted = TRUE; //OCPP Status
  13431. }
  13432. }
  13433. for (int index = 0; index < GB_QUANTITY; index++)
  13434. {
  13435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13436. {
  13437. checkState_Faulted = TRUE; //OCPP Status: Faulted
  13438. }
  13439. }
  13440. for (int index = 0; index < AC_QUANTITY; index++)
  13441. {
  13442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13443. {
  13444. checkState_Faulted = TRUE; //OCPP Status: Faulted
  13445. }
  13446. }
  13447. if(checkState_Faulted == TRUE)
  13448. {
  13449. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  13450. goto end;
  13451. }
  13452. // Check update type
  13453. if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  13454. {
  13455. //Local list full update
  13456. DEBUG_INFO("Local list full update.\n");
  13457. DB_getListVerion();
  13458. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  13459. {
  13460. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  13461. goto end;
  13462. }
  13463. DB_cleanLocalList();
  13464. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  13465. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  13466. }
  13467. else if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  13468. {
  13469. //Local list different update
  13470. DEBUG_INFO("Local list different update.\n");
  13471. DB_getListVerion();
  13472. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  13473. {
  13474. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  13475. goto end;
  13476. }
  13477. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  13478. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  13479. }
  13480. else
  13481. {
  13482. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  13483. goto end;
  13484. }
  13485. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  13486. end:
  13487. sendSendLocalListConfirmation(uuid);
  13488. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13489. return result;
  13490. }
  13491. int handleSetChargingProfileRequest(char *uuid, char *payload)
  13492. {
  13493. mtrace();
  13494. int result = FAIL;
  13495. int8_t gun_index = -1;
  13496. uint8_t isPeriodOverMax = FALSE;
  13497. uint8_t isProfileOverMax = FALSE;
  13498. uint8_t isConnectorMismatch = FALSE;
  13499. uint8_t existProfileQuantity = 0;
  13500. uint8_t filename[128]={0};
  13501. uint8_t word[2048]={0};
  13502. FILE *filePtr;
  13503. json_object *SetChargingProfile;
  13504. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  13505. SetChargingProfile = json_tokener_parse(payload);
  13506. if(!is_error(SetChargingProfile))
  13507. {
  13508. // Required data
  13509. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  13510. {
  13511. gun_index = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  13512. }
  13513. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  13514. {
  13515. // Check periods is over max configuration
  13516. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  13517. {
  13518. isPeriodOverMax = TRUE;
  13519. }
  13520. // Check periods is over max configuration
  13521. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  13522. {
  13523. if(gun_index == 0)
  13524. {
  13525. sprintf((char*)filename, ChargePointMaxProfile_JSON);
  13526. filePtr = fopen((char*)filename, "r");
  13527. if (!filePtr)
  13528. {
  13529. DEBUG_INFO("%s not exist, create it.\n", ChargePointMaxProfile_JSON);
  13530. filePtr = fopen((char*)filename, "w+");
  13531. }
  13532. else
  13533. {
  13534. //Check Charging Profile Count
  13535. while(fscanf(filePtr, "%s", word) != EOF)
  13536. {
  13537. //DEBUG_INFO("word=%s\n",word);
  13538. if(strstr((char*)word, "chargingProfileId")!= NULL)
  13539. {
  13540. existProfileQuantity += 1;
  13541. }
  13542. }
  13543. }
  13544. fclose(filePtr);
  13545. }
  13546. else
  13547. isConnectorMismatch = TRUE;
  13548. }
  13549. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  13550. {
  13551. if(gun_index < 5)
  13552. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", gun_index);
  13553. else
  13554. isConnectorMismatch = TRUE;
  13555. if(!isConnectorMismatch)
  13556. {
  13557. filePtr = fopen((char*)filename, "r");
  13558. if (!filePtr)
  13559. {
  13560. DEBUG_INFO("%s not exist, create it.\n", filename);
  13561. filePtr = fopen((char*)filename, "w+");
  13562. }
  13563. else
  13564. {
  13565. //Check Charging Profile Count
  13566. while(fscanf(filePtr, "%s", word) != EOF)
  13567. {
  13568. //DEBUG_INFO("word=%s\n",word);
  13569. if(strstr((char*)word, "chargingProfileId")!= NULL)
  13570. {
  13571. existProfileQuantity += 1;
  13572. }
  13573. }
  13574. }
  13575. fclose(filePtr);
  13576. }
  13577. }
  13578. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13579. {
  13580. if(gun_index>0)
  13581. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  13582. else
  13583. isConnectorMismatch = TRUE;
  13584. if(!isConnectorMismatch)
  13585. {
  13586. filePtr = fopen((char*)filename, "r");
  13587. if (!filePtr)
  13588. {
  13589. DEBUG_INFO("%s not exist, create it.\n", filename);
  13590. filePtr = fopen((char*)filename, "w+");
  13591. }
  13592. else
  13593. {
  13594. //Check Charging Profile Count
  13595. while(fscanf(filePtr, "%s", word) != EOF)
  13596. {
  13597. //DEBUG_INFO("word=%s\n",word);
  13598. if(strstr((char*)word, "chargingProfileId")!= NULL)
  13599. {
  13600. existProfileQuantity += 1;
  13601. }
  13602. }
  13603. }
  13604. fclose(filePtr);
  13605. }
  13606. }
  13607. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  13608. {
  13609. }
  13610. else
  13611. {
  13612. }
  13613. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  13614. isProfileOverMax = TRUE;
  13615. }
  13616. // Profile replace or add info
  13617. if((gun_index > -1) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch)
  13618. {
  13619. FILE *infile;
  13620. FILE *outfile;
  13621. char tmpProfileName[32];
  13622. char rmFileCmd[128];
  13623. char tempchargingProfilePurposeStr[30]={0};
  13624. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  13625. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfile");
  13626. infile = fopen ((char*)filename, "r");
  13627. outfile = fopen ((char*)tmpProfileName, "w");
  13628. int d = fgetc(infile);
  13629. rewind(infile);
  13630. if(d == EOF)
  13631. {
  13632. // Profile is empty
  13633. fprintf(outfile,"%s\n", payload);
  13634. fclose(infile);
  13635. fclose(outfile);
  13636. sprintf(rmFileCmd,"rm -f %s",filename);
  13637. system(rmFileCmd);
  13638. rename((char*)tmpProfileName, (char*)filename);
  13639. }
  13640. else
  13641. {
  13642. // Profile is not empty
  13643. char buf[2048]={0};
  13644. int ChargingProfileAdded = FALSE;
  13645. while (fgets(buf, sizeof(buf), infile) != NULL)
  13646. {
  13647. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  13648. json_object *tmpChargingProfile;
  13649. tmpChargingProfile = json_tokener_parse(buf);
  13650. if(!is_error(tmpChargingProfile))
  13651. {
  13652. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  13653. {
  13654. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  13655. }
  13656. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13657. {
  13658. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13659. {
  13660. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13661. }
  13662. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13663. {
  13664. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13665. }
  13666. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  13667. {
  13668. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  13669. }
  13670. }
  13671. }
  13672. json_object_put(tmpChargingProfile);
  13673. if((tempconnectorIdInt == gun_index) &&
  13674. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"))))
  13675. {
  13676. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"))) &&
  13677. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  13678. {
  13679. //DEBUG_INFO("update set chargingProfile to file -0\n");
  13680. if(ChargingProfileAdded == FALSE)
  13681. {
  13682. fprintf(outfile,"%s\n",payload);
  13683. ChargingProfileAdded = TRUE;
  13684. }
  13685. }
  13686. else
  13687. {
  13688. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  13689. {
  13690. if(ChargingProfileAdded == FALSE)
  13691. {
  13692. fprintf(outfile,"%s\n",buf);
  13693. fprintf(outfile,"%s\n",payload);
  13694. ChargingProfileAdded = TRUE;
  13695. }
  13696. else
  13697. {
  13698. fprintf(outfile,"%s\n",buf);
  13699. }
  13700. }
  13701. else
  13702. {
  13703. if(ChargingProfileAdded == FALSE)
  13704. {
  13705. fprintf(outfile,"%s\n",buf);
  13706. fprintf(outfile,"%s\n",payload);
  13707. ChargingProfileAdded = TRUE;
  13708. }
  13709. else
  13710. {
  13711. fprintf(outfile,"%s\n",buf);
  13712. }
  13713. }
  13714. }
  13715. }
  13716. else
  13717. {
  13718. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId")))
  13719. {
  13720. if(ChargingProfileAdded == FALSE)
  13721. {
  13722. fprintf(outfile,"%s\n",buf);
  13723. fprintf(outfile,"%s\n",payload);
  13724. ChargingProfileAdded = TRUE;
  13725. }
  13726. else
  13727. {
  13728. fprintf(outfile,"%s\n",buf);
  13729. }
  13730. }
  13731. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  13732. {
  13733. if(ChargingProfileAdded == FALSE)
  13734. {
  13735. fprintf(outfile,"%s\n",buf);
  13736. fprintf(outfile,"%s\n",payload);
  13737. ChargingProfileAdded = TRUE;
  13738. }
  13739. else
  13740. {
  13741. fprintf(outfile,"%s\n",buf);
  13742. }
  13743. }
  13744. else
  13745. {
  13746. if(ChargingProfileAdded == FALSE)
  13747. {
  13748. fprintf(outfile,"%s\n",buf);
  13749. fprintf(outfile,"%s\n",payload);
  13750. ChargingProfileAdded = TRUE;
  13751. }
  13752. else
  13753. {
  13754. fprintf(outfile,"%s\n",buf);
  13755. }
  13756. }
  13757. }
  13758. } // end of while loop
  13759. fclose(infile);
  13760. fclose(outfile);
  13761. sprintf(rmFileCmd,"rm -f %s",filename);
  13762. system(rmFileCmd);
  13763. rename((char*)tmpProfileName, (char*)filename);
  13764. }
  13765. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  13766. result = PASS;
  13767. }
  13768. else
  13769. {
  13770. if(gun_index == -1)
  13771. DEBUG_WARN("Connector id is wrong.\n");
  13772. if(isConnectorMismatch)
  13773. DEBUG_WARN("Connector id is mismatch.\n");
  13774. if(isPeriodOverMax)
  13775. DEBUG_WARN("Profile periods quantity is over spec.\n");
  13776. if(isProfileOverMax)
  13777. DEBUG_WARN("Profile quantity is over spec.\n");
  13778. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  13779. }
  13780. }
  13781. json_object_put(SetChargingProfile);
  13782. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  13783. {
  13784. if(gun_index == 0)
  13785. {
  13786. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13787. {
  13788. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  13789. }
  13790. }
  13791. else
  13792. checkCompositeSchedule(gun_index, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index-1], 0, TRUE);
  13793. }
  13794. sendSetChargingProfileConfirmation(uuid, (gun_index==0?gun_index:gun_index-1));
  13795. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13796. return result;
  13797. }
  13798. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  13799. {
  13800. mtrace();
  13801. int result = FAIL;
  13802. json_object *SetDisplayMessage;
  13803. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  13804. SetDisplayMessage = json_tokener_parse(payload);
  13805. if(!is_error(SetDisplayMessage))
  13806. {
  13807. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  13808. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  13809. // Required data
  13810. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  13811. {
  13812. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  13813. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  13814. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  13815. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  13816. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  13817. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  13818. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  13819. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  13820. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  13821. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  13822. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  13823. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  13824. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  13825. {
  13826. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  13827. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.message.format, "%s",json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format")));
  13828. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  13829. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.message.language, "%s",json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language")));
  13830. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  13831. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.message.content, "%s",json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content")));
  13832. }
  13833. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  13834. {
  13835. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  13836. 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")));
  13837. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  13838. 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")));
  13839. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  13840. {
  13841. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  13842. 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"));
  13843. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  13844. 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"));
  13845. }
  13846. }
  13847. }
  13848. }
  13849. json_object_put(SetDisplayMessage);
  13850. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  13851. sendSetDisplayMessagesConfirmation(uuid);
  13852. // Announce CSU there is display request come from server
  13853. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  13854. return result;
  13855. }
  13856. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  13857. {
  13858. mtrace();
  13859. int result = FAIL;
  13860. json_object *SetMonitoringBase;
  13861. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  13862. SetMonitoringBase = json_tokener_parse(payload);
  13863. if(!is_error(SetMonitoringBase))
  13864. {
  13865. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  13866. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  13867. // Required data
  13868. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  13869. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  13870. }
  13871. json_object_put(SetMonitoringBase);
  13872. /*
  13873. * TODO:
  13874. * 1. Configure monitor base and response
  13875. */
  13876. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13877. sendSetMonitoringBaseConfirmation(uuid);
  13878. return result;
  13879. }
  13880. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  13881. {
  13882. mtrace();
  13883. int result = FAIL;
  13884. json_object *SetMonitoringLevel;
  13885. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  13886. SetMonitoringLevel = json_tokener_parse(payload);
  13887. if(!is_error(SetMonitoringLevel))
  13888. {
  13889. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  13890. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  13891. // Required data
  13892. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  13893. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  13894. }
  13895. json_object_put(SetMonitoringLevel);
  13896. /*
  13897. * TODO:
  13898. * Configure monitor status and response
  13899. */
  13900. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13901. sendSetMonitoringLevelConfirmation(uuid);
  13902. return result;
  13903. }
  13904. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  13905. {
  13906. mtrace();
  13907. int result = FAIL;
  13908. json_object *SetNetworkProfile;
  13909. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  13910. SetNetworkProfile = json_tokener_parse(payload);
  13911. if(!is_error(SetNetworkProfile))
  13912. {
  13913. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  13914. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  13915. // Required data
  13916. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  13917. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  13918. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  13919. {
  13920. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  13921. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  13922. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  13923. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  13924. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  13925. {
  13926. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  13927. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  13928. }
  13929. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  13930. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  13931. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  13932. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  13933. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  13934. {
  13935. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  13936. 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")));
  13937. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  13938. 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")));
  13939. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  13940. 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")));
  13941. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  13942. 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")));
  13943. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  13944. 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")));
  13945. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  13946. 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")));
  13947. }
  13948. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  13949. {
  13950. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  13951. {
  13952. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  13953. 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")));
  13954. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  13955. }
  13956. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  13957. {
  13958. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  13959. 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")));
  13960. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  13961. }
  13962. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  13963. {
  13964. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  13965. 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")));
  13966. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  13967. }
  13968. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  13969. 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"));
  13970. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  13971. 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")));
  13972. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  13973. 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"));
  13974. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  13975. 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")));
  13976. }
  13977. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  13978. }
  13979. }
  13980. json_object_put(SetNetworkProfile);
  13981. /*
  13982. * TODO:
  13983. * 1. Process network configuration and response
  13984. */
  13985. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  13986. {
  13987. }
  13988. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  13989. {
  13990. }
  13991. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  13992. {
  13993. }
  13994. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  13995. {
  13996. }
  13997. else
  13998. {
  13999. }
  14000. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  14001. {
  14002. }
  14003. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  14004. {
  14005. }
  14006. else
  14007. {
  14008. }
  14009. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  14010. {
  14011. }
  14012. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  14013. {
  14014. }
  14015. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  14016. {
  14017. }
  14018. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  14019. {
  14020. }
  14021. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  14022. {
  14023. }
  14024. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  14025. {
  14026. }
  14027. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  14028. {
  14029. }
  14030. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  14031. {
  14032. }
  14033. else
  14034. {
  14035. }
  14036. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  14037. {
  14038. }
  14039. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  14040. {
  14041. }
  14042. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  14043. {
  14044. }
  14045. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  14046. {
  14047. }
  14048. else
  14049. {
  14050. }
  14051. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  14052. {
  14053. }
  14054. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  14055. {
  14056. }
  14057. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  14058. {
  14059. }
  14060. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  14061. {
  14062. }
  14063. else
  14064. {
  14065. }
  14066. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  14067. sendSetNetworkProfileConfirmation(uuid);
  14068. return result;
  14069. }
  14070. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  14071. {
  14072. mtrace();
  14073. int result = FAIL;
  14074. json_object *SetVariableMonitoring;
  14075. uint8_t variableQuantity = 0;
  14076. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  14077. SetVariableMonitoring = json_tokener_parse(payload);
  14078. if(!is_error(SetVariableMonitoring))
  14079. {
  14080. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  14081. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  14082. // Required data
  14083. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  14084. {
  14085. variableQuantity++;
  14086. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  14087. {
  14088. 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"));
  14089. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  14090. }
  14091. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  14092. {
  14093. 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"));
  14094. }
  14095. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  14096. {
  14097. 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")));
  14098. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  14099. }
  14100. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  14101. {
  14102. 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"));
  14103. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  14104. }
  14105. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  14106. {
  14107. 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"));
  14108. }
  14109. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component") != NULL)
  14110. {
  14111. 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)
  14112. {
  14113. 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")));
  14114. }
  14115. 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)
  14116. {
  14117. 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")));
  14118. }
  14119. 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)
  14120. {
  14121. 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)
  14122. {
  14123. 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"));
  14124. }
  14125. 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)
  14126. {
  14127. 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"));
  14128. }
  14129. }
  14130. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  14131. }
  14132. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable") != NULL)
  14133. {
  14134. 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)
  14135. {
  14136. 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")));
  14137. }
  14138. 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)
  14139. {
  14140. 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")));
  14141. }
  14142. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  14143. }
  14144. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  14145. }
  14146. }
  14147. json_object_put(SetVariableMonitoring);
  14148. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  14149. return result;
  14150. }
  14151. int handleSetVariablesRequest(char *uuid, char *payload)
  14152. {
  14153. mtrace();
  14154. int result = FAIL;
  14155. json_object *SetVariables;
  14156. DEBUG_INFO("handleSetVariablesRequest...\n");
  14157. SetVariables = json_tokener_parse(payload);
  14158. if(!is_error(SetVariables))
  14159. {
  14160. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  14161. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  14162. // Required data
  14163. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  14164. {
  14165. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  14166. {
  14167. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  14168. {
  14169. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  14170. {
  14171. 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")));
  14172. }
  14173. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  14174. {
  14175. 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")));
  14176. }
  14177. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  14178. {
  14179. 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)
  14180. {
  14181. 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"));
  14182. }
  14183. 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)
  14184. {
  14185. 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"));
  14186. }
  14187. }
  14188. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  14189. }
  14190. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  14191. {
  14192. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  14193. {
  14194. 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")));
  14195. }
  14196. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  14197. {
  14198. 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")));
  14199. }
  14200. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  14201. }
  14202. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  14203. {
  14204. 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")));
  14205. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  14206. }
  14207. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  14208. {
  14209. 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")));
  14210. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  14211. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  14212. {
  14213. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  14214. (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) &&
  14215. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  14216. (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))
  14217. {
  14218. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  14219. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  14220. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  14221. {
  14222. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  14223. }
  14224. else
  14225. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  14226. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  14227. {
  14228. ChageWebSocketPingInterval(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value));
  14229. }
  14230. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  14231. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  14232. {
  14233. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  14234. SetOcppConnStatus(FALSE);
  14235. }
  14236. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  14237. {
  14238. HeartBeatWaitTime = (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value)<10) ? 10 : atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  14239. }
  14240. }
  14241. }
  14242. }
  14243. }
  14244. }
  14245. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  14246. }
  14247. json_object_put(SetVariables);
  14248. return result;
  14249. }
  14250. int handleTriggerMessageRequest(char *uuid, char *payload)
  14251. {
  14252. mtrace();
  14253. int result = FAIL;
  14254. int connectorIdIsNULL = FALSE;
  14255. int connectorIdInt =0;
  14256. json_object *TriggerMessage;
  14257. DEBUG_INFO("handleTriggerMessageRequest\n");
  14258. TriggerMessage = json_tokener_parse(payload);
  14259. if(!is_error(TriggerMessage))
  14260. {
  14261. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  14262. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  14263. // Required data
  14264. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  14265. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  14266. // Optional data
  14267. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  14268. {
  14269. // Required data
  14270. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  14271. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  14272. // Optional data
  14273. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  14274. {
  14275. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  14276. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  14277. }
  14278. else
  14279. connectorIdIsNULL = TRUE;
  14280. }
  14281. else
  14282. connectorIdIsNULL = TRUE;
  14283. }
  14284. json_object_put(TriggerMessage);
  14285. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  14286. {
  14287. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  14288. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  14289. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  14290. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  14291. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  14292. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  14293. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  14294. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  14295. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  14296. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  14297. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  14298. {
  14299. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  14300. sendTriggerMessageConfirmation(uuid);
  14301. return TRUE;
  14302. }
  14303. else
  14304. {
  14305. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  14306. sendTriggerMessageConfirmation(uuid);
  14307. }
  14308. }
  14309. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  14310. {
  14311. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  14312. sendTriggerMessageConfirmation(uuid);
  14313. return TRUE;
  14314. }
  14315. //==========================
  14316. // Trigger message
  14317. //==========================
  14318. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  14319. {
  14320. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  14321. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  14322. {
  14323. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  14324. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  14325. }
  14326. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14327. }
  14328. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  14329. {
  14330. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  14331. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  14332. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14333. }
  14334. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  14335. {
  14336. if(DB_updateBootType(BootReasonEnumType_Triggered))
  14337. server_sign = FALSE;
  14338. }
  14339. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  14340. {
  14341. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval);
  14342. }
  14343. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  14344. {
  14345. if(connectorIdIsNULL == FALSE)
  14346. {
  14347. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  14348. {
  14349. cpinitateMsg.bits[connectorIdInt-1].TriggerMeterValueReq = ON;
  14350. }
  14351. }
  14352. else
  14353. {
  14354. for(int idx=0;idx< gunTotalNumber;idx++)
  14355. {
  14356. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  14357. }
  14358. }
  14359. }
  14360. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  14361. {
  14362. if(connectorIdIsNULL == FALSE)
  14363. {
  14364. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  14365. {
  14366. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = ON;
  14367. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  14368. }
  14369. }
  14370. else
  14371. {
  14372. for(int idx=0;idx< gunTotalNumber;idx++)
  14373. {
  14374. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  14375. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  14376. }
  14377. }
  14378. }
  14379. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  14380. {
  14381. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  14382. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  14383. {
  14384. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  14385. }
  14386. }
  14387. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  14388. {
  14389. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  14390. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  14391. {
  14392. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certV2G.csr -nodes -keyout /Storage/OCPP/certV2G.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  14393. }
  14394. }
  14395. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  14396. {
  14397. if(connectorIdIsNULL == FALSE)
  14398. {
  14399. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  14400. {
  14401. cpinitateMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  14402. }
  14403. }
  14404. else
  14405. {
  14406. for(int idx=0;idx< gunTotalNumber;idx++)
  14407. cpinitateMsg.bits[idx].TransactionEventReq = ON;
  14408. }
  14409. }
  14410. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  14411. {
  14412. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  14413. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  14414. {
  14415. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  14416. }
  14417. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  14418. {
  14419. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certV2G.csr -nodes -keyout /Storage/OCPP/certV2G.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  14420. }
  14421. }
  14422. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  14423. {
  14424. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  14425. }
  14426. return result;
  14427. }
  14428. int handleUnlockConnectorRequest(char *uuid, char *payload)
  14429. {
  14430. mtrace();
  14431. int result = FAIL;
  14432. int connectorIdInt =0;
  14433. int tempIndex = 0;
  14434. json_object *UnlockConnector;
  14435. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  14436. UnlockConnector = json_tokener_parse(payload);
  14437. if(!is_error(UnlockConnector))
  14438. {
  14439. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  14440. {
  14441. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  14442. }
  14443. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  14444. {
  14445. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  14446. }
  14447. }
  14448. json_object_put(UnlockConnector);
  14449. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  14450. if(gunTotalNumber == 0)
  14451. {
  14452. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  14453. goto end;
  14454. }
  14455. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  14456. {
  14457. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  14458. goto end;
  14459. }
  14460. else
  14461. {
  14462. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  14463. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  14464. //check Transaction active
  14465. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  14466. {
  14467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14468. {
  14469. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14470. }
  14471. else
  14472. {
  14473. tempIndex = connectorIdInt -1;
  14474. }
  14475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14476. {
  14477. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  14478. {
  14479. //stop Transaction
  14480. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14481. }
  14482. }
  14483. }
  14484. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  14485. {
  14486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14487. {
  14488. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14489. }
  14490. else
  14491. {
  14492. tempIndex = connectorIdInt -1;
  14493. }
  14494. for (int index = 0; index < CCS_QUANTITY; index++)
  14495. {
  14496. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  14497. {
  14498. //stop Transaction
  14499. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14500. }
  14501. }
  14502. }
  14503. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  14504. {
  14505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14506. {
  14507. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14508. }
  14509. else
  14510. {
  14511. tempIndex = connectorIdInt -1;
  14512. }
  14513. for (int index = 0; index < GB_QUANTITY; index++)
  14514. {
  14515. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  14516. {
  14517. //stop Transaction
  14518. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14519. }
  14520. }
  14521. }
  14522. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  14523. {
  14524. tempIndex = connectorIdInt -1;
  14525. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14526. {
  14527. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  14528. {
  14529. //stop Transaction
  14530. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14531. }
  14532. }
  14533. }
  14534. else
  14535. {
  14536. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14537. {
  14538. tempIndex = 2;
  14539. }
  14540. else
  14541. {
  14542. tempIndex = connectorIdInt-1;
  14543. }
  14544. for (int index = 0; index < AC_QUANTITY; index++)
  14545. {
  14546. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  14547. {
  14548. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14549. }
  14550. }
  14551. }
  14552. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  14553. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  14554. result = TRUE;
  14555. return result;
  14556. }
  14557. end:
  14558. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorConf = ON;
  14559. return result;
  14560. }
  14561. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  14562. {
  14563. mtrace();
  14564. int result = FAIL;
  14565. json_object *UnpublishFirmware;
  14566. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  14567. UnpublishFirmware = json_tokener_parse(payload);
  14568. if(!is_error(UnpublishFirmware))
  14569. {
  14570. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  14571. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  14572. // Required data
  14573. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  14574. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  14575. }
  14576. json_object_put(UnpublishFirmware);
  14577. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  14578. /*
  14579. * TODO:
  14580. * 1. Check unpublished status
  14581. */
  14582. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  14583. sendUnpublishFirmwareConfirmation(uuid);
  14584. return result;
  14585. }
  14586. static char UpdateFirmwarepayloadData[512]={0};
  14587. void *UpdateFirmwareProcess(void *data)
  14588. {
  14589. pthread_detach(pthread_self());
  14590. mtrace();
  14591. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14592. int port=0;
  14593. int isSuccess = 0;
  14594. char ftpbuf[1024];
  14595. char temp[1024];
  14596. char * pch;
  14597. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  14598. json_object *UpdateFirmware;
  14599. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  14600. if(!is_error(UpdateFirmware))
  14601. {
  14602. // Required data
  14603. if(json_object_object_get(UpdateFirmware, "requestId"))
  14604. {
  14605. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  14606. }
  14607. if(json_object_object_get(UpdateFirmware, "firmware"))
  14608. {
  14609. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  14610. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  14611. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  14612. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  14613. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  14614. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  14615. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  14616. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  14617. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  14618. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  14619. }
  14620. // Optional data
  14621. if(json_object_object_get(UpdateFirmware, "retries"))
  14622. {
  14623. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  14624. }
  14625. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  14626. {
  14627. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  14628. }
  14629. }
  14630. json_object_put(UpdateFirmware);
  14631. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14632. memset(path, 0, ARRAY_SIZE(path));
  14633. // Wait retrieveData
  14634. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  14635. {
  14636. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14637. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  14638. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14639. do
  14640. {
  14641. sleep(1);
  14642. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  14643. }
  14644. system("rm -f /mnt/*");
  14645. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  14646. {
  14647. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14648. sprintf(ftppath,"/%s", path);
  14649. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  14650. DEBUG_INFO("protocol: %s\n",protocol);
  14651. DEBUG_INFO("host: %s\n",host);
  14652. DEBUG_INFO("path: %s\n",path);
  14653. DEBUG_INFO("ftppath: %s\n",ftppath);
  14654. int ftppathlen=strlen(ftppath);
  14655. int i=1;
  14656. char filenametemp[50];
  14657. while(i < ftppathlen)
  14658. {
  14659. int len=ftppathlen-i;
  14660. if(ftppath[len]== 47) // '/' ascll code: 47
  14661. {
  14662. DEBUG_INFO("compare '/' all right\n");
  14663. break;
  14664. }
  14665. i=i+1;
  14666. }
  14667. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14668. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14669. filenametemp[i+1] = 0;
  14670. do
  14671. {
  14672. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14673. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  14674. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14675. sleep(3);
  14676. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  14677. if(!isSuccess)
  14678. {
  14679. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14680. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  14681. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14682. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  14683. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14684. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  14685. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14686. }
  14687. else
  14688. {
  14689. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14690. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  14691. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14692. }
  14693. ShmOCPP20Data->UpdateFirmware.retries--;
  14694. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  14695. }
  14696. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  14697. {
  14698. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14699. memset(temp, 0, ARRAY_SIZE(temp));
  14700. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  14701. int ftppathlen=strlen(ftpbuf);
  14702. int i=1;
  14703. char filenametemp[50];
  14704. while(i < ftppathlen)
  14705. {
  14706. int len=ftppathlen-i;
  14707. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14708. {
  14709. DEBUG_INFO(" compare '/' all right\n");
  14710. break;
  14711. }
  14712. i=i+1;
  14713. }
  14714. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14715. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  14716. filenametemp[i+1] = 0;
  14717. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14718. pch=strchr(temp,'@');
  14719. if(pch==NULL)
  14720. {
  14721. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14722. protocol, host, &port, path);
  14723. strcpy(user,"anonymous");
  14724. strcpy(password,"");
  14725. }
  14726. else
  14727. {
  14728. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14729. protocol, user, password, host, &port, path);
  14730. }
  14731. sscanf(host,"%[^/]%s",host1, path1);
  14732. sprintf(ftppath,"%s", path1);
  14733. if(port == 0)
  14734. {
  14735. port = 21;
  14736. }
  14737. do
  14738. {
  14739. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14740. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  14741. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14742. sleep(3);
  14743. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  14744. if(!isSuccess)
  14745. {
  14746. //BulldogUtil.sleepMs(interval*1000);
  14747. DEBUG_INFO("Update firmware request and download file fail.\n");
  14748. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14749. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  14750. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14751. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  14752. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14753. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  14754. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14755. }
  14756. else
  14757. {
  14758. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14759. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  14760. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14761. }
  14762. ShmOCPP20Data->UpdateFirmware.retries--;
  14763. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  14764. }
  14765. else
  14766. {
  14767. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14768. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  14769. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14770. sleep(1);
  14771. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  14772. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  14773. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14774. }
  14775. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  14776. interLock.isUpdateFirmwareGoing = OFF;
  14777. pthread_exit(NULL);
  14778. }
  14779. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  14780. {
  14781. mtrace();
  14782. int result = FAIL;
  14783. pthread_t t;
  14784. sendUpdateFirmwareConfirmation(uuid);
  14785. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  14786. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  14787. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  14788. if(!interLock.isUpdateFirmwareGoing)
  14789. {
  14790. interLock.isUpdateFirmwareGoing = ON;
  14791. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  14792. }
  14793. else
  14794. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  14795. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  14796. return result;
  14797. }
  14798. int handleUnknownRequest(char *uuid, char *payload)
  14799. {
  14800. mtrace();
  14801. int result = FAIL;
  14802. DEBUG_INFO("handleUnknownRequest...\n");
  14803. sendUnknownConfirmation(uuid);
  14804. result = PASS;
  14805. return result;
  14806. }
  14807. //==========================================
  14808. // Handle server response routine
  14809. //==========================================
  14810. void handleAuthorizeResponse(char *payload, int gun_index)
  14811. {
  14812. mtrace();
  14813. DEBUG_INFO("handleAuthorizeResponse...\n");
  14814. json_object *Authorize;
  14815. Authorize = json_tokener_parse(payload);
  14816. if(!is_error(Authorize))
  14817. {
  14818. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  14819. {
  14820. // Required data
  14821. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  14822. // Optional data
  14823. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "cacheExpiryDateTime") != NULL)
  14824. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  14825. else
  14826. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  14827. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "chargingPriority") != NULL)
  14828. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  14829. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language1") != NULL)
  14830. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  14831. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "evseId") != NULL)
  14832. {
  14833. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTagInfo"), "evseId"));idx++)
  14834. {
  14835. 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));
  14836. }
  14837. }
  14838. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language2") != NULL)
  14839. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  14840. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "groupIdToken") != NULL)
  14841. {
  14842. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  14843. 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")));
  14844. else
  14845. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  14846. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  14847. 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")));
  14848. }
  14849. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "personalMessage") != NULL)
  14850. {
  14851. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  14852. 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")));
  14853. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  14854. 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")));
  14855. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  14856. 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")));
  14857. }
  14858. }
  14859. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  14860. {
  14861. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  14862. }
  14863. }
  14864. json_object_put(Authorize);
  14865. //Update idTag information to authorization cache if supported
  14866. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  14867. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  14868. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&
  14869. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  14870. {
  14871. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  14872. }
  14873. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  14874. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  14875. authorizeRetryTimes = 0;
  14876. }
  14877. void handleBootNotificationResponse(char *payload, int gun_index)
  14878. {
  14879. mtrace();
  14880. char statusStr[12]={0};
  14881. char currentTimeStr[30]={0};
  14882. int intervalInt = 0;
  14883. DEBUG_INFO("handleBootNotificationResponse...\n");
  14884. json_object *BootNotification;
  14885. BootNotification = json_tokener_parse(payload);
  14886. if(!is_error(BootNotification))
  14887. {
  14888. // Required data
  14889. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14890. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14891. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14892. }
  14893. json_object_put(BootNotification);
  14894. DEBUG_INFO("statusStr: %s\n", statusStr);
  14895. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  14896. BootNotificationInterval = intervalInt;
  14897. HeartBeatWaitTime = intervalInt;
  14898. //write back to ShmOCPP20Data->BootNotification
  14899. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  14900. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  14901. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  14902. {
  14903. server_sign = TRUE;
  14904. server_pending =FALSE;
  14905. DB_updateBootType(BootReasonEnumType_PowerUp);
  14906. }
  14907. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  14908. {
  14909. server_pending = TRUE;
  14910. }
  14911. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  14912. srand(time(NULL));
  14913. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  14914. SetOcppConnStatus(TRUE);
  14915. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  14916. }
  14917. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  14918. {
  14919. mtrace();
  14920. json_object *ClearedChargingLimit;
  14921. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  14922. ClearedChargingLimit = json_tokener_parse(payload);
  14923. if(!is_error(ClearedChargingLimit))
  14924. {
  14925. // Required data
  14926. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  14927. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  14928. }
  14929. json_object_put(ClearedChargingLimit);
  14930. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  14931. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  14932. }
  14933. void handleDataTransferResponse(char *payload, int gun_index)
  14934. {
  14935. mtrace();
  14936. json_object *DataTrans;
  14937. DEBUG_INFO("handleDataTransferResponse...\n");
  14938. DataTrans = json_tokener_parse(payload);
  14939. if(!is_error(DataTrans))
  14940. {
  14941. // Required data
  14942. if(json_object_object_get(DataTrans,"status") != NULL)
  14943. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  14944. // Optional data
  14945. if(json_object_object_get(DataTrans,"data") != NULL)
  14946. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  14947. }
  14948. json_object_put(DataTrans);
  14949. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  14950. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  14951. }
  14952. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14953. {
  14954. mtrace();
  14955. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14956. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  14957. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  14958. }
  14959. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  14960. {
  14961. mtrace();
  14962. json_object *Get15118EVCertificate;
  14963. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  14964. Get15118EVCertificate = json_tokener_parse(payload);
  14965. if(!is_error(Get15118EVCertificate))
  14966. {
  14967. // Required data
  14968. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  14969. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  14970. // Optional data
  14971. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  14972. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  14973. }
  14974. json_object_put(Get15118EVCertificate);
  14975. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  14976. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  14977. }
  14978. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  14979. {
  14980. mtrace();
  14981. json_object *GetCertificateStatus;
  14982. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  14983. GetCertificateStatus = json_tokener_parse(payload);
  14984. if(!is_error(GetCertificateStatus))
  14985. {
  14986. // Required data
  14987. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  14988. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  14989. // Optional data
  14990. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  14991. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  14992. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  14993. {
  14994. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  14995. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  14996. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  14997. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  14998. }
  14999. }
  15000. json_object_put(GetCertificateStatus);
  15001. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  15002. {
  15003. /*
  15004. * TODO:
  15005. * 1. If get certificate response accepted process something here
  15006. */
  15007. }
  15008. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  15009. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  15010. }
  15011. void handleHeartbeatResponse(char *payload, int gun_index)
  15012. {
  15013. mtrace();
  15014. DEBUG_INFO("handleHeartbeatResponse...\n");
  15015. json_object *Heartbeat;
  15016. Heartbeat = json_tokener_parse(payload);
  15017. if(!is_error(Heartbeat))
  15018. {
  15019. // Required data
  15020. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  15021. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15022. }
  15023. json_object_put(Heartbeat);
  15024. if(FirstHeartBeat == OFF)
  15025. {
  15026. FirstHeartBeat = ON;
  15027. DEBUG_INFO("FirstHeartBeat \n");
  15028. }
  15029. HeartBeatWithNOResponse = 0;
  15030. clientTime.Heartbeat=time((time_t*)NULL);
  15031. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  15032. }
  15033. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15034. {
  15035. mtrace();
  15036. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15037. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  15038. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  15039. }
  15040. void handleMeterValuesResponse(char *payload, int gun_index)
  15041. {
  15042. mtrace();
  15043. DEBUG_INFO("handleMeterValuesResponse...\n");
  15044. }
  15045. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  15046. {
  15047. mtrace();
  15048. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  15049. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  15050. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  15051. }
  15052. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  15053. {
  15054. mtrace();
  15055. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  15056. }
  15057. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  15058. {
  15059. mtrace();
  15060. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  15061. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  15062. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  15063. }
  15064. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  15065. {
  15066. mtrace();
  15067. json_object *NotifyEVChargingNeeds;
  15068. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  15069. NotifyEVChargingNeeds = json_tokener_parse(payload);
  15070. if(!is_error(NotifyEVChargingNeeds))
  15071. {
  15072. // Required data
  15073. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  15074. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  15075. }
  15076. json_object_put(NotifyEVChargingNeeds);
  15077. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  15078. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  15079. }
  15080. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  15081. {
  15082. mtrace();
  15083. json_object *NotifyEVChargingSchedule;
  15084. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  15085. NotifyEVChargingSchedule = json_tokener_parse(payload);
  15086. if(!is_error(NotifyEVChargingSchedule))
  15087. {
  15088. // Required data
  15089. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  15090. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  15091. }
  15092. json_object_put(NotifyEVChargingSchedule);
  15093. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleReq = OFF;
  15094. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleConf = ON;
  15095. }
  15096. void handleNotifyEventResponse(char *payload, int gun_index)
  15097. {
  15098. mtrace();
  15099. DEBUG_INFO("handleNotifyEventResponse...\n");
  15100. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  15101. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  15102. }
  15103. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  15104. {
  15105. mtrace();
  15106. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  15107. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  15108. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  15109. }
  15110. void handleNotifyReportResponse(char *payload, int gun_index)
  15111. {
  15112. mtrace();
  15113. DEBUG_INFO("handleNotifyReportResponse...\n");
  15114. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  15115. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  15116. }
  15117. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15118. {
  15119. mtrace();
  15120. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  15121. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  15122. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  15123. }
  15124. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  15125. {
  15126. mtrace();
  15127. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  15128. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  15129. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  15130. }
  15131. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  15132. {
  15133. mtrace();
  15134. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  15135. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  15136. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  15137. }
  15138. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15139. {
  15140. mtrace();
  15141. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15142. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  15143. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  15144. }
  15145. void handleSignCertificateResponse(char *payload, int gun_index)
  15146. {
  15147. mtrace();
  15148. json_object *SignCertificate;
  15149. DEBUG_INFO("handleSignCertificateResponse...\n");
  15150. SignCertificate = json_tokener_parse(payload);
  15151. if(!is_error(SignCertificate))
  15152. {
  15153. // Required data
  15154. if(json_object_object_get(SignCertificate,"status") != NULL)
  15155. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  15156. // Optional data
  15157. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  15158. {
  15159. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  15160. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  15161. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  15162. }
  15163. }
  15164. json_object_put(SignCertificate);
  15165. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  15166. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  15167. }
  15168. void handleStatusNotificationResponse(char *payload, int gun_index)
  15169. {
  15170. mtrace();
  15171. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  15172. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  15173. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  15174. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  15175. }
  15176. void handleTransactionEvenResponse(char *payload, int gun_index)
  15177. {
  15178. mtrace();
  15179. json_object *TransactionEven;
  15180. DEBUG_INFO("handleTransactionEvenResponse...\n");
  15181. TransactionEven = json_tokener_parse(payload);
  15182. if(!is_error(TransactionEven))
  15183. {
  15184. // Required data
  15185. // Optional data
  15186. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  15187. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  15188. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  15189. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  15190. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  15191. {
  15192. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  15193. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  15194. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15195. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  15196. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  15197. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  15198. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  15199. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  15200. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  15201. {
  15202. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  15203. 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")));
  15204. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  15205. 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")));
  15206. }
  15207. }
  15208. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  15209. {
  15210. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  15211. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  15212. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  15213. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  15214. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  15215. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  15216. }
  15217. }
  15218. json_object_put(TransactionEven);
  15219. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  15220. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  15221. }
  15222. //==========================================
  15223. // Handle Error routine
  15224. //==========================================
  15225. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15226. {
  15227. mtrace();
  15228. #ifdef SystemLogMessage
  15229. DEBUG_INFO("errorCode: %s\n", errorCode);
  15230. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15231. DEBUG_INFO("errorDetails: %s\n", payload);
  15232. #endif
  15233. }
  15234. //===============================================
  15235. // Common routine
  15236. //===============================================
  15237. int initialConfigurationTable(void)
  15238. {
  15239. DEBUG_INFO("initialConfigurationTable...\n");
  15240. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  15241. DB_variableIsCreate();
  15242. DB_variableLoadFromDb();
  15243. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  15244. {
  15245. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  15246. DB_variableClear();
  15247. DB_variableIsCreate();
  15248. DB_variableLoadFromDb();
  15249. }
  15250. DB_getNetworkProfileFromDb();
  15251. return 0;
  15252. }
  15253. int TransactionMessageAttemptsGet(void)
  15254. {
  15255. return TransactionMessageAttemptsValue;
  15256. }
  15257. int FirstHeartBeatResponse(void)
  15258. {
  15259. return FirstHeartBeat;
  15260. }
  15261. int TransactionMessageRetryIntervalGet(void)
  15262. {
  15263. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15264. }
  15265. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15266. {
  15267. int result = TRUE;
  15268. char rmFileCmd[100]={0};
  15269. char FilePath[100]={0};
  15270. char ftpbuf[200];
  15271. int systemresult;
  15272. sprintf(FilePath,"/mnt/%s",filename);
  15273. system("ping 8.8.8.8 &");
  15274. if((access(FilePath,F_OK))!=-1)
  15275. {
  15276. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15277. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15278. system(rmFileCmd);
  15279. }
  15280. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15281. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15282. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15283. systemresult = system(ftpbuf);
  15284. if(systemresult != 0)
  15285. {
  15286. DEBUG_INFO("http DownLoad error!\n");
  15287. result = FALSE;
  15288. }
  15289. system("pkill ping");
  15290. return result;
  15291. }
  15292. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15293. {
  15294. int result = TRUE;
  15295. char rmFileCmd[100]={0};
  15296. char FilePath[100]={0};
  15297. char ftpbuf[200];
  15298. int systemresult;
  15299. sprintf(FilePath,"/mnt/%s",filename);
  15300. system("ping 8.8.8.8 &");
  15301. if((access(FilePath,F_OK))!=-1)
  15302. {
  15303. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15304. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15305. system(rmFileCmd);
  15306. }
  15307. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15308. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15309. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15310. systemresult = system(ftpbuf);
  15311. if(systemresult != 0)
  15312. {
  15313. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15314. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15315. systemresult = system(ftpbuf);
  15316. if(systemresult != 0)
  15317. {
  15318. DEBUG_WARN("wget error!\n");
  15319. result = FALSE;
  15320. }
  15321. }
  15322. system("pkill ping");
  15323. return result;
  15324. }
  15325. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15326. {
  15327. char rmFileCmd[100]={0};
  15328. char FilePath[100]={0};
  15329. char buf[512];
  15330. int systemresult = 0;
  15331. //DEBUG_INFO("filename=%s\n",filename);
  15332. //DEBUG_INFO("url=%s\n",url);
  15333. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15334. if((access(FilePath,F_OK))!=-1)
  15335. {
  15336. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15337. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15338. system(rmFileCmd);
  15339. }
  15340. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15341. if(fp == NULL)
  15342. {
  15343. DEBUG_INFO("log is NULL\n");
  15344. return FALSE;
  15345. }
  15346. else
  15347. {
  15348. fprintf(fp, "%s\n", url);
  15349. fprintf(fp, "%s\n", filename);
  15350. fclose(fp);
  15351. }
  15352. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15353. if(phpFP == NULL)
  15354. {
  15355. DEBUG_INFO("PHP upload fail.\n");
  15356. return FALSE;
  15357. }
  15358. else
  15359. {
  15360. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15361. {
  15362. if(strstr(buf, "result") != NULL)
  15363. {
  15364. sscanf(buf, "result: %d", &systemresult);
  15365. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15366. }
  15367. }
  15368. pclose(phpFP);
  15369. }
  15370. if(systemresult != 1)
  15371. {
  15372. DEBUG_INFO("HTTP upload error!\n");
  15373. return FALSE;
  15374. }
  15375. return TRUE;
  15376. }
  15377. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15378. {
  15379. struct hostent* server;
  15380. char *IPbuffer;
  15381. char ftpbuf[200];
  15382. int systemresult;
  15383. // To retrieve host information
  15384. server = gethostbyname(location);
  15385. // To convert an Internet network
  15386. // address into ASCII string
  15387. IPbuffer = inet_ntoa(*((struct in_addr*)
  15388. server->h_addr_list[0]));
  15389. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15390. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15391. /* format : ftpput -u username -p passwd IP target source*/
  15392. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15393. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15394. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15395. systemresult = system(ftpbuf);
  15396. DEBUG_INFO("systemresult=%d\n",systemresult);
  15397. if(systemresult != 0)
  15398. {
  15399. DEBUG_INFO("ftpput error!\n");
  15400. return FALSE;
  15401. }
  15402. return TRUE;
  15403. }
  15404. //=========================================
  15405. // Routine
  15406. //=========================================
  15407. int GetOcppServerURL()
  15408. {
  15409. int result = FALSE;
  15410. struct yuarel url;
  15411. char urlStr[512];
  15412. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15413. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15414. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15415. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  15416. {
  15417. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  15418. if(yuarel_parse(&url, urlStr) != -1)
  15419. {
  15420. sprintf(OcppProtocol, "%s", url.scheme);
  15421. sprintf(OcppHost, "%s", url.host);
  15422. if(url.path == NULL)
  15423. OcppTempPath[0] = '\0';
  15424. else
  15425. sprintf(OcppTempPath, "%s", url.path);
  15426. if(url.port == 0)
  15427. {
  15428. if(strcmp(OcppProtocol, "wss") == 0)
  15429. OcppPort = 443;
  15430. else
  15431. OcppPort = 80;
  15432. }
  15433. else
  15434. OcppPort = url.port;
  15435. result = TRUE;
  15436. }
  15437. }
  15438. else
  15439. {
  15440. strcpy(OcppHost,"");
  15441. }
  15442. return result;
  15443. }
  15444. int GetOcppPath()
  15445. {
  15446. int result = FALSE;
  15447. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15448. {
  15449. if(OcppTempPath == NULL)
  15450. {
  15451. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15452. }
  15453. else
  15454. {
  15455. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15456. }
  15457. result = TRUE;
  15458. }
  15459. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  15460. {
  15461. if(OcppTempPath == NULL)
  15462. {
  15463. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  15464. }
  15465. else
  15466. {
  15467. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  15468. }
  15469. result = TRUE;
  15470. }
  15471. else
  15472. {
  15473. strcpy(OcppPath,"");
  15474. }
  15475. return result;
  15476. }
  15477. int GetOcppPort()
  15478. {
  15479. return OcppPort;
  15480. }
  15481. int GetOcppConnStatus(void)
  15482. {
  15483. return ShmOCPP20Data->OcppConnStatus;
  15484. }
  15485. void SetOcppConnStatus(uint8_t status)
  15486. {
  15487. ShmOCPP20Data->OcppConnStatus = status;
  15488. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15489. }
  15490. int GetHeartBeatWithNOResponse(void)
  15491. {
  15492. return HeartBeatWithNOResponse;
  15493. }
  15494. void SetHeartBeatWithNOResponse(void)
  15495. {
  15496. HeartBeatWithNOResponse = 0;
  15497. }
  15498. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15499. void storeTempStopTransaction(int gun_index)
  15500. {
  15501. char TempStopTransaction[256];
  15502. char message[1024*20]={0};
  15503. char guid[37]={0};
  15504. uint8_t tempIndex;
  15505. json_object *TransactionEvent = json_object_new_object();
  15506. json_object *transactionInfo = json_object_new_object();
  15507. json_object *idToken = json_object_new_object();
  15508. json_object *evse = json_object_new_object();
  15509. json_object *meterValues = json_object_new_array();
  15510. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  15511. DEBUG_INFO("storeTempStopTransaction...\n");
  15512. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15513. {
  15514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15515. {
  15516. tempIndex = ((gun_index==2) ? 1: 0);
  15517. }
  15518. else
  15519. {
  15520. tempIndex = gun_index;
  15521. }
  15522. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15523. {
  15524. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15525. {
  15526. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15527. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15528. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15529. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15530. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  15531. {
  15532. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  15533. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  15534. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  15535. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15536. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  15537. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  15538. {
  15539. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  15540. }
  15541. else
  15542. {
  15543. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  15544. }
  15545. }
  15546. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  15547. {
  15548. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15549. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  15550. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  15551. }
  15552. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  15553. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  15554. ) //S_PRECHARGE
  15555. {
  15556. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  15557. {
  15558. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  15559. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  15560. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  15561. }
  15562. if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
  15563. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15564. else
  15565. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15566. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  15567. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15568. }
  15569. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  15570. {
  15571. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15572. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15573. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15574. }
  15575. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  15576. {
  15577. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15578. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15579. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15580. }
  15581. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  15582. {
  15583. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15584. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  15585. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15586. }
  15587. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  15588. {
  15589. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15590. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15591. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15592. }
  15593. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  15594. {
  15595. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15596. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15597. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15598. }
  15599. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  15600. {
  15601. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15602. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15603. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15604. }
  15605. } //end of the same index
  15606. }//end of for CHAdeMO_QUANTITY
  15607. }
  15608. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15609. {
  15610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15611. {
  15612. tempIndex = ((gun_index==2) ? 1: 0);
  15613. }
  15614. else
  15615. {
  15616. tempIndex = gun_index;
  15617. }
  15618. for (int index = 0; index < CCS_QUANTITY; index++)
  15619. {
  15620. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15621. {
  15622. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15623. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15624. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15625. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15627. {
  15628. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  15629. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  15630. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  15631. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15632. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  15633. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  15634. {
  15635. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  15636. }
  15637. else
  15638. {
  15639. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  15640. }
  15641. }
  15642. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  15643. {
  15644. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15645. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  15646. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  15647. }
  15648. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  15649. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  15650. ) //S_PRECHARGE
  15651. {
  15652. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  15653. {
  15654. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  15655. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  15656. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  15657. }
  15658. if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
  15659. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15660. else
  15661. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15662. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  15663. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15664. }
  15665. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  15666. {
  15667. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15668. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15669. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15670. }
  15671. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  15672. {
  15673. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15674. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15675. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15676. }
  15677. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  15678. {
  15679. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15680. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  15681. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15682. }
  15683. 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
  15684. {
  15685. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15686. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15687. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15688. }
  15689. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  15690. {
  15691. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15692. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15693. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15694. }
  15695. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  15696. {
  15697. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15698. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15699. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15700. }
  15701. } //end of the same index
  15702. } // end of for CCS_QUANTITY
  15703. }
  15704. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15705. {
  15706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15707. {
  15708. tempIndex = ((gun_index==2) ? 1: 0);
  15709. }
  15710. else
  15711. {
  15712. tempIndex = gun_index;
  15713. }
  15714. for (int index = 0; index < GB_QUANTITY; index++)
  15715. {
  15716. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15717. {
  15718. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15719. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15720. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15721. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15722. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15723. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15724. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15725. } //end of the same index
  15726. } // end of for GB_QUANTITY
  15727. }
  15728. else if(gunType[gun_index] == GUN_TYPE_DO)
  15729. {
  15730. tempIndex = gun_index;
  15731. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15732. {
  15733. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15734. {
  15735. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15736. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15737. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15738. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15739. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15740. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15741. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15742. } //end of the same index
  15743. }
  15744. }
  15745. else
  15746. {
  15747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15748. {
  15749. tempIndex = 2;
  15750. }
  15751. else
  15752. {
  15753. tempIndex = gun_index;
  15754. }
  15755. for (int index = 0; index < AC_QUANTITY; index++)
  15756. {
  15757. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15758. {
  15759. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15760. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15761. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15762. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15763. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15764. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15765. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15766. }//end of the same index
  15767. }//end of for AC_QUANTITY
  15768. }
  15769. // Message
  15770. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  15771. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  15772. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  15773. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  15774. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  15775. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  15776. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  15777. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  15778. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  15779. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  15780. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  15781. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  15782. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  15783. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  15784. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  15785. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  15786. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  15787. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  15788. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  15789. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  15790. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  15791. {
  15792. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  15793. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  15794. json_object_object_add(TransactionEvent, "idToken", idToken);
  15795. }
  15796. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  15797. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  15798. json_object_object_add(TransactionEvent, "evse", evse);
  15799. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  15800. {
  15801. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  15802. {
  15803. json_object *meterValue = json_object_new_object();
  15804. json_object *sampledValues = json_object_new_array();
  15805. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  15806. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  15807. {
  15808. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  15809. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0)))
  15810. {
  15811. json_object *sampledValue = json_object_new_object();
  15812. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  15813. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  15814. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  15815. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  15816. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  15817. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  15818. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  15819. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  15820. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  15821. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  15822. {
  15823. json_object *unitOfMeasure = json_object_new_object();
  15824. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  15825. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  15826. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  15827. }
  15828. json_object_array_add(sampledValues, sampledValue);
  15829. }
  15830. }
  15831. json_object_object_add(meterValue, "sampledValue", sampledValues);
  15832. json_object_array_add(meterValues, meterValue);
  15833. }
  15834. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  15835. }
  15836. random_uuid(guid);
  15837. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  15838. , guid
  15839. , "TransactionEvent"
  15840. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  15841. json_object_put(TransactionEvent);
  15842. // open file for writing
  15843. FILE *outfile;
  15844. outfile = fopen (TempStopTransaction, "w+");
  15845. //DEBUG_INFO("data = %s\n", queuedata);
  15846. fputs(message, outfile);
  15847. fputs("\n", outfile);
  15848. fclose (outfile);
  15849. }
  15850. void checkTempStopTransaction(int gun_index)
  15851. {
  15852. FILE *fptr1;
  15853. char ch;
  15854. char str[QUEUE_MESSAGE_LENGTH]={0};
  15855. char guid[37]={0};
  15856. char tempdata[65]={0};
  15857. char TempStopTransaction[256];
  15858. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  15859. fptr1 = fopen(TempStopTransaction, "r");
  15860. if (!fptr1)
  15861. {
  15862. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  15863. return ;
  15864. }
  15865. ch=fgetc(fptr1);
  15866. rewind(fptr1);
  15867. if(ch!=EOF)
  15868. {
  15869. // copy all contents to the temporary file except the specific line
  15870. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15871. {
  15872. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15873. if(str[0]=='\0')
  15874. {
  15875. break;
  15876. }
  15877. strncpy(guid, str+4, 36); //copy guid
  15878. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  15879. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15880. {
  15881. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15882. }
  15883. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15884. memset(str,0,ARRAY_SIZE(str));
  15885. }
  15886. }
  15887. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15888. fclose(fptr1);
  15889. remove(TempStopTransaction); // remove the original file
  15890. }
  15891. int GetWebSocketPingInterval(void)
  15892. {
  15893. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  15894. }
  15895. int GetServerSign(void)
  15896. {
  15897. return server_sign;
  15898. }
  15899. uint8_t GetOcppSecurityProfile()
  15900. {
  15901. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  15902. }
  15903. void GetOcppChargerBoxId(uint8_t *data)
  15904. {
  15905. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15906. }
  15907. void GetOcppSecurityPassword(uint8_t *data)
  15908. {
  15909. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  15910. }
  15911. void SetServerSign(int value)
  15912. {
  15913. server_sign = value;
  15914. }
  15915. int GetBootNotificationInterval(void)
  15916. {
  15917. return BootNotificationInterval;
  15918. }
  15919. int GetInternetConn(void)
  15920. {
  15921. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15922. }
  15923. int GetBackendConnectionTimeout(void)
  15924. {
  15925. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15926. }
  15927. int isConnectorInitMode(int gun_index)
  15928. {
  15929. int tempIndex = 0;
  15930. int result = TRUE;
  15931. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15932. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15933. {
  15934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15935. {
  15936. tempIndex = ((gun_index==2) ? 1: 0);
  15937. }
  15938. else
  15939. {
  15940. tempIndex = gun_index;
  15941. }
  15942. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15943. {
  15944. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15945. {
  15946. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15947. } //end of the same index
  15948. }//end of for CHAdeMO_QUANTITY
  15949. }
  15950. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15951. {
  15952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15953. {
  15954. tempIndex = ((gun_index==2) ? 1: 0);
  15955. }
  15956. else
  15957. {
  15958. tempIndex = gun_index;
  15959. }
  15960. for (int index = 0; index < CCS_QUANTITY; index++)
  15961. {
  15962. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15963. {
  15964. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15965. } //end of the same index
  15966. } // end of for CCS_QUANTITY
  15967. }
  15968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15969. {
  15970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15971. {
  15972. tempIndex = ((gun_index==2) ? 1: 0);
  15973. }
  15974. else
  15975. {
  15976. tempIndex = gun_index;
  15977. }
  15978. for (int index = 0; index < GB_QUANTITY; index++)
  15979. {
  15980. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15981. {
  15982. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15983. } //end of the same index
  15984. } // end of for GB_QUANTITY
  15985. }
  15986. else if(gunType[gun_index] == GUN_TYPE_DO)
  15987. {
  15988. tempIndex = gun_index;
  15989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15990. {
  15991. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15992. {
  15993. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15994. } //end of the same index
  15995. }
  15996. }
  15997. else
  15998. {
  15999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16000. {
  16001. tempIndex = 2;
  16002. }
  16003. else
  16004. {
  16005. tempIndex = gun_index;
  16006. }
  16007. for (int index = 0; index < AC_QUANTITY; index++)
  16008. {
  16009. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16010. {
  16011. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16012. }//end of the same index
  16013. }//end of for AC_QUANTITY
  16014. }
  16015. return result;
  16016. }
  16017. void refreshProcDogTimer()
  16018. {
  16019. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  16020. }
  16021. void InitialSystemValue(void)
  16022. {
  16023. int connectorIndex = 0;
  16024. gunTotalNumber=0;
  16025. SystemInitial = 0;
  16026. localversion=0;
  16027. BootNotificationInterval = 10;
  16028. authorizeRetryTimes = 0;
  16029. GunStatusInterval = 10;
  16030. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  16031. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  16032. //Hear Beat
  16033. HeartBeatWithNOResponse = 0;
  16034. HeartBeatCountPerHour = 0;
  16035. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  16036. FirstHeartBeat = 0;
  16037. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  16038. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  16039. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16040. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16041. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16042. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16043. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16044. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16045. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16046. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16047. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16048. memset(gunType, 0, ARRAY_SIZE(gunType));
  16049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16050. {
  16051. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16052. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16053. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16054. {
  16055. // DO series
  16056. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16057. {
  16058. SystemInitial = SystemInitial + 1;
  16059. gunTotalNumber = gunTotalNumber + 1;
  16060. gunType[connectorIndex] = GUN_TYPE_DO;
  16061. connectorIndex = connectorIndex + 1;
  16062. }
  16063. }
  16064. else
  16065. {
  16066. // DM, DW, DS series
  16067. //check connector / socket type (index: 8, 9, 10)
  16068. for(int index=7; index <10 ; index++)
  16069. {
  16070. if(index != 8)
  16071. {
  16072. // DC Connector
  16073. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16074. {
  16075. SystemInitial = SystemInitial + 1;
  16076. gunTotalNumber = gunTotalNumber + 1;
  16077. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16078. connectorIndex = connectorIndex + 1;
  16079. }
  16080. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16081. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16082. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16083. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16084. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16085. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16086. {
  16087. SystemInitial = SystemInitial + 1;
  16088. gunTotalNumber = gunTotalNumber + 1;
  16089. gunType[connectorIndex] = GUN_TYPE_CCS;
  16090. connectorIndex = connectorIndex + 1;
  16091. }
  16092. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16093. {
  16094. SystemInitial = SystemInitial + 1;
  16095. gunTotalNumber = gunTotalNumber + 1;
  16096. gunType[connectorIndex] = GUN_TYPE_GBT;
  16097. connectorIndex = connectorIndex + 1;
  16098. }
  16099. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16100. {
  16101. SystemInitial = SystemInitial + 1;
  16102. gunTotalNumber = gunTotalNumber + 1;
  16103. gunType[connectorIndex] = GUN_TYPE_DO;
  16104. connectorIndex = connectorIndex + 1;
  16105. }
  16106. }
  16107. else
  16108. {
  16109. // AC Connector
  16110. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16111. {
  16112. SystemInitial = SystemInitial + 1;
  16113. gunTotalNumber = gunTotalNumber + 1;
  16114. gunType[connectorIndex] = GUN_TYPE_AC;
  16115. connectorIndex = connectorIndex + 1;
  16116. }
  16117. }
  16118. }
  16119. }
  16120. //DEBUG_INFO("DC ...\n");
  16121. }
  16122. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16123. {
  16124. //check connector / socket type (index: 8, 9, 10)
  16125. for(int index=7; index <10 ; index++)
  16126. {
  16127. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16128. {
  16129. SystemInitial = SystemInitial + 1;
  16130. gunTotalNumber = gunTotalNumber + 1;
  16131. gunType[connectorIndex] = GUN_TYPE_AC;
  16132. connectorIndex = connectorIndex + 1;
  16133. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16134. }
  16135. }
  16136. }
  16137. //Status && ConnectorPlugIn Setting
  16138. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16139. {
  16140. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16141. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16142. }
  16143. for (int index = 0; index < CCS_QUANTITY; index++)
  16144. {
  16145. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16146. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16147. }
  16148. for (int index = 0; index < GB_QUANTITY; index++)
  16149. {
  16150. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16151. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16152. }
  16153. for (int index = 0; index < AC_QUANTITY; index++)
  16154. {
  16155. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16156. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16157. }
  16158. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16159. {
  16160. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16161. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16162. }
  16163. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16164. {
  16165. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  16166. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  16167. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  16168. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16169. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  16170. memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  16171. }
  16172. clientTime.Heartbeat=time((time_t*)NULL);
  16173. sleep(1);
  16174. }
  16175. void LWS_Send(char *str)
  16176. {
  16177. //=====================================================
  16178. // Check InternetConn 0: disconnected, 1: connected
  16179. //====================================================
  16180. if(GetOcppConnStatus() == 0)
  16181. {
  16182. DEBUG_INFO("offline now !!!\n");
  16183. return;
  16184. }
  16185. // Only disable isWebsocketSendable operation initiated by charger
  16186. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16187. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16188. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  16189. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16190. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16191. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  16192. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  16193. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16194. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16195. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16196. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  16197. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  16198. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  16199. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  16200. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  16201. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  16202. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  16203. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  16204. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  16205. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  16206. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  16207. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16208. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16209. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16210. || (strstr((char*)str, "\"TransactionEven\"") != NULL))
  16211. {
  16212. isWebsocketSendable = OFF;
  16213. }
  16214. pthread_mutex_lock(&lock_send);
  16215. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16216. sprintf((char *)SendBuffer, "%s", str);
  16217. SendBufLen = strlen(str);
  16218. pthread_mutex_unlock(&lock_send);
  16219. lws_callback_on_writable(wsi_client);
  16220. //lws_service(context, 0);
  16221. //sleep(1);
  16222. }
  16223. void LWS_SendNow(char *str)
  16224. {
  16225. //=====================================================
  16226. // Check InternetConn 0: disconnected, 1: connected
  16227. //====================================================
  16228. if(GetOcppConnStatus() == 0)
  16229. {
  16230. DEBUG_INFO("offline now !!!\n");
  16231. return;
  16232. }
  16233. // Only disable isWebsocketSendable operation initiated by charger
  16234. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16235. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16236. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  16237. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16238. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16239. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  16240. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  16241. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16242. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16243. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16244. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  16245. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  16246. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  16247. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  16248. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  16249. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  16250. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  16251. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  16252. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  16253. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  16254. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  16255. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16256. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16257. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16258. || (strstr((char*)str, "\"TransactionEven\"") != NULL))
  16259. {
  16260. isWebsocketSendable = OFF;
  16261. }
  16262. pthread_mutex_lock(&lock_send);
  16263. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16264. sprintf((char *)SendBuffer, "%s", str);
  16265. SendBufLen = strlen(str);
  16266. pthread_mutex_unlock(&lock_send);
  16267. lws_callback_on_writable(wsi_client);
  16268. lws_service(context, 0);
  16269. //sleep(1);
  16270. }