MessageHandler.c 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *SecurityEventEnumTypeStr[] = {
  50. MACROSTR(FirmwareUpdated),
  51. MACROSTR(FailedToAuthenticateAtCsms),
  52. MACROSTR(CsmsFailedToAuthenticate),
  53. MACROSTR(SettingSystemTime),
  54. MACROSTR(StartupOfTheDevice),
  55. MACROSTR(ResetOrReboot),
  56. MACROSTR(SecurityLogWasCleared),
  57. MACROSTR(ReconfigurationOfSecurityParameters),
  58. MACROSTR(MemoryExhaustion),
  59. MACROSTR(InvalidMessages),
  60. MACROSTR(AttemptedReplayAttacks),
  61. MACROSTR(TamperDetectionActivated),
  62. MACROSTR(InvalidFirmwareSignature),
  63. MACROSTR(InvalidFirmwareSigningCertificate),
  64. MACROSTR(InvalidCsmsCertificate),
  65. MACROSTR(InvalidChargingStationCertificate),
  66. MACROSTR(InvalidTLSVersion),
  67. MACROSTR(InvalidTLSCipherSuite)
  68. };
  69. static char *CancelReservationStatusEnumTypeStr[] = {
  70. MACROSTR(Accepted),
  71. MACROSTR(Rejected)
  72. };
  73. static char *CertificateActionEnumTypeStr[] = {
  74. MACROSTR(Install),
  75. MACROSTR(Update)
  76. };
  77. static char *CertificateSignedStatusEnumTypeStr[] = {
  78. MACROSTR(Accepted),
  79. MACROSTR(Rejected)
  80. };
  81. static char *CertificateSigningUseEnumTypeStr[] = {
  82. MACROSTR(ChargingStationCertificate),
  83. MACROSTR(V2GCertificate)
  84. };
  85. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  86. MACROSTR(Accepted),
  87. MACROSTR(Rejected),
  88. MACROSTR(Scheduled)
  89. };
  90. #if 0
  91. static char *ChargingLimitSourceEnumTypeStr[] = {
  92. MACROSTR(EMS),
  93. MACROSTR(Other),
  94. MACROSTR(SO),
  95. MACROSTR(CSO)
  96. };
  97. #endif
  98. static char *ChargingProfileKindEnumTypeStr[] = {
  99. MACROSTR(Absolute),
  100. MACROSTR(Recurring),
  101. MACROSTR(Relative)
  102. };
  103. static char *ChargingProfilePurposeEnumTypeStr[] = {
  104. MACROSTR(ChargingStationExternalConstraints),
  105. MACROSTR(ChargingStationMaxProfile),
  106. MACROSTR(TxDefaultProfile),
  107. MACROSTR(TxProfile)
  108. };
  109. static char *ChargingProfileStatusEnumTypeStr[] = {
  110. MACROSTR(Accepted),
  111. MACROSTR(Rejected)
  112. };
  113. static char *ChargingRateUnitEnumTypeStr[] = {
  114. MACROSTR(W),
  115. MACROSTR(A)
  116. };
  117. static char *ChargingStateEnumTypeStr[] = {
  118. MACROSTR(Charging),
  119. MACROSTR(EVConnected),
  120. MACROSTR(SuspendedEV),
  121. MACROSTR(SuspendedEVSE),
  122. MACROSTR(Idle)
  123. };
  124. static char *ClearCacheStatusEnumTypeStr[] = {
  125. MACROSTR(Accepted),
  126. MACROSTR(Rejected)
  127. };
  128. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  129. MACROSTR(Accepted),
  130. MACROSTR(Unknown)
  131. };
  132. static char *ClearMessageStatusEnumTypeStr[] = {
  133. MACROSTR(Accepted),
  134. MACROSTR(Unknown)
  135. };
  136. static char *ClearMonitoringStatusEnumTypeStr[] = {
  137. MACROSTR(Accepted),
  138. MACROSTR(Rejected),
  139. MACROSTR(NotFound)
  140. };
  141. static char *ComponentCriterionEnumTypeStr[] = {
  142. MACROSTR(Active),
  143. MACROSTR(Available),
  144. MACROSTR(Enabled),
  145. MACROSTR(Problem)
  146. };
  147. #if 0
  148. static char *ConnectorEnumTypeStr[] = {
  149. MACROSTR(cCCS1),
  150. MACROSTR(cCCS2),
  151. MACROSTR(cG105),
  152. MACROSTR(cTesla),
  153. MACROSTR(cType1),
  154. MACROSTR(cType2),
  155. MACROSTR(s309-1P-16A),
  156. MACROSTR(s309-1P-32A),
  157. MACROSTR(s309-3P-16A),
  158. MACROSTR(s309-3P-32A),
  159. MACROSTR(sBS1361),
  160. MACROSTR(sCEE-7-7),
  161. MACROSTR(sType2),
  162. MACROSTR(sType3),
  163. MACROSTR(Other1PhMax16A),
  164. MACROSTR(Other1PhOver16A),
  165. MACROSTR(Other3Ph),
  166. MACROSTR(Pan),
  167. MACROSTR(wInductive),
  168. MACROSTR(wResonant),
  169. MACROSTR(Undetermined),
  170. MACROSTR(Unknown)
  171. };
  172. #endif
  173. static char *ConnectorStatusEnumTypeStr[] = {
  174. MACROSTR(Available),
  175. MACROSTR(Occupied),
  176. MACROSTR(Reserved),
  177. MACROSTR(Unavailable),
  178. MACROSTR(Faulted)
  179. };
  180. #if 0
  181. static char *CostKindEnumTypeStr[] = {
  182. MACROSTR(CarbonDioxideEmission),
  183. MACROSTR(RelativePricePercentage),
  184. MACROSTR(RenewableGenerationPercentage)
  185. };
  186. #endif
  187. static char *CustomerInformationStatusEnumTypeStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(Invalid)
  191. };
  192. static char *DataEnumTypeStr[] = {
  193. MACROSTR(string),
  194. MACROSTR(decimal),
  195. MACROSTR(integer),
  196. MACROSTR(dateTime),
  197. MACROSTR(boolean),
  198. MACROSTR(OptionList),
  199. MACROSTR(SequenceList),
  200. MACROSTR(MemberList)
  201. };
  202. static char *DataTransferStatusEnumTypeStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected),
  205. MACROSTR(UnknownMessageId),
  206. MACROSTR(UnknownVendorId)
  207. };
  208. static char *DeleteCertificateStatusEnumTypeStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Failed),
  211. MACROSTR(NotFound)
  212. };
  213. static char *DisplayMessageStatusEnumTypeStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(NotSupportedMessageFormat),
  216. MACROSTR(Rejected),
  217. MACROSTR(NotSupportedPriority),
  218. MACROSTR(NotSupportedState),
  219. MACROSTR(UnknownTransaction)
  220. };
  221. #if 0
  222. static char *EnergyTransferModeEnumTypeStr[] = {
  223. MACROSTR(DC),
  224. MACROSTR(AC_single_phase),
  225. MACROSTR(AC_two_phase),
  226. MACROSTR(AC_three_phase)
  227. };
  228. #endif
  229. static char *EventNotificationEnumTypeStr[] = {
  230. MACROSTR(HardWiredNotification),
  231. MACROSTR(HardWiredMonitor),
  232. MACROSTR(PreconfiguredMonitor),
  233. MACROSTR(CustomMonitor)
  234. };
  235. static char *EventTriggerEnumTypeStr[] = {
  236. MACROSTR(Alerting),
  237. MACROSTR(Delta),
  238. MACROSTR(Periodic)
  239. };
  240. static char *FirmwareStatusEnumTypeStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(DownloadScheduled),
  245. MACROSTR(DownloadPaused),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed),
  250. MACROSTR(InstallRebooting),
  251. MACROSTR(InstallScheduled),
  252. MACROSTR(InstallVerificationFailed),
  253. MACROSTR(InvalidSignature),
  254. MACROSTR(SignatureVerified)
  255. };
  256. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected),
  259. MACROSTR(NotSupported),
  260. MACROSTR(EmptyResultSet)
  261. };
  262. static char *GenericStatusEnumTypeStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected)
  265. };
  266. static char *GetCertificateIdUseEnumTypeStr[] = {
  267. MACROSTR(V2GRootCertificate),
  268. MACROSTR(MORootCertificate),
  269. MACROSTR(CSMSRootCertificate),
  270. MACROSTR(V2GCertificateChain),
  271. MACROSTR(ManufacturerRootCertificate)
  272. };
  273. static char *GetCertificateStatusEnumTypeStr[] = {
  274. MACROSTR(Accepted),
  275. MACROSTR(Failed)
  276. };
  277. static char *GetChargingProfileStatusEnumTypeStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(NoProfiles)
  280. };
  281. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Unknown)
  284. };
  285. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(NotFound)
  288. };
  289. static char *GetVariableStatusEnumTypeStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected),
  292. MACROSTR(UnknownComponent),
  293. MACROSTR(UnknownVariable),
  294. MACROSTR(NotSupportedAttributeType)
  295. };
  296. static char *HashAlgorithmEnumTypeStr[] = {
  297. MACROSTR(SHA256),
  298. MACROSTR(SHA384),
  299. MACROSTR(SHA512)
  300. };
  301. static char *IdTokenEnumTypeStr[] = {
  302. MACROSTR(Central),
  303. MACROSTR(eMAID),
  304. MACROSTR(ISO14443),
  305. MACROSTR(KeyCode),
  306. MACROSTR(Local),
  307. MACROSTR(NoAuthorization),
  308. MACROSTR(ISO15693)
  309. };
  310. static char *InstallCertificateUseEnumTypeStr[] = {
  311. MACROSTR(V2GRootCertificate),
  312. MACROSTR(MORootCertificate),
  313. MACROSTR(CSMSRootCertificate),
  314. MACROSTR(ManufacturerRootCertificate)
  315. };
  316. static char *InstallCertificateStatusEnumTypeStr[]={
  317. MACROSTR(Accepted),
  318. MACROSTR(Failed),
  319. MACROSTR(Rejected)
  320. };
  321. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  322. MACROSTR(Accepted),
  323. MACROSTR(Failed)
  324. };
  325. static char *LocationEnumTypeStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char *LogEnumTypeStr[] = {
  333. MACROSTR(DiagnosticsLog),
  334. MACROSTR(SecurityLog)
  335. };
  336. static char *LogStatusEnumTypeStr[] = {
  337. MACROSTR(Accepted),
  338. MACROSTR(Rejected),
  339. MACROSTR(AcceptedCanceled)
  340. };
  341. static char *MeasurandEnumTypeStr[] = {
  342. MACROSTR(Current.Export),
  343. MACROSTR(Current.Import),
  344. MACROSTR(Current.Offered),
  345. MACROSTR(Energy.Active.Export.Register),
  346. MACROSTR(Energy.Active.Import.Register),
  347. MACROSTR(Energy.Reactive.Export.Register),
  348. MACROSTR(Energy.Reactive.Import.Register),
  349. MACROSTR(Energy.Active.Export.Interval),
  350. MACROSTR(Energy.Active.Import.Interval),
  351. MACROSTR(Energy.Active.Net),
  352. MACROSTR(Energy.Reactive.Export.Interval),
  353. MACROSTR(Energy.Reactive.Import.Interval),
  354. MACROSTR(Energy.Reactive.Net),
  355. MACROSTR(Energy.Apparent.Net),
  356. MACROSTR(Energy.Apparent.Import),
  357. MACROSTR(Energy.Apparent.Export),
  358. MACROSTR(Frequency),
  359. MACROSTR(Power.Active.Export),
  360. MACROSTR(Power.Active.Import),
  361. MACROSTR(Power.Factor),
  362. MACROSTR(Power.Offered),
  363. MACROSTR(Power.Reactive.Export),
  364. MACROSTR(Power.Reactive.Import),
  365. MACROSTR(SoC),
  366. MACROSTR(Voltage)
  367. };
  368. static char *MessageFormatEnumTypeStr[] = {
  369. MACROSTR(ASCII),
  370. MACROSTR(HTML),
  371. MACROSTR(URI),
  372. MACROSTR(UTF8)
  373. };
  374. static char *MessagePriorityEnumTypeStr[] = {
  375. MACROSTR(AlwaysFront),
  376. MACROSTR(InFront),
  377. MACROSTR(NormalCycle)
  378. };
  379. static char *MessageStateEnumTypeStr[] = {
  380. MACROSTR(Charging),
  381. MACROSTR(Faulted),
  382. MACROSTR(Idle),
  383. MACROSTR(Unavailable)
  384. };
  385. static char *MessageTriggerEnumTypeStr[] = {
  386. MACROSTR(BootNotification),
  387. MACROSTR(LogStatusNotification),
  388. MACROSTR(FirmwareStatusNotification),
  389. MACROSTR(Heartbeat),
  390. MACROSTR(MeterValues),
  391. MACROSTR(SignChargingStationCertificate),
  392. MACROSTR(SignV2GCertificate),
  393. MACROSTR(StatusNotification),
  394. MACROSTR(TransactionEvent),
  395. MACROSTR(SignCombinedCertificate),
  396. MACROSTR(PublishFirmwareStatusNotification)
  397. };
  398. static char *MonitorEnumTypeStr[] = {
  399. MACROSTR(UpperThreshold),
  400. MACROSTR(LowerThreshold),
  401. MACROSTR(Delta),
  402. MACROSTR(Periodic),
  403. MACROSTR(PeriodicClockAligned)
  404. };
  405. static char *MonitoringBaseEnumTypeStr[] = {
  406. MACROSTR(All),
  407. MACROSTR(FactoryDefault),
  408. MACROSTR(HardWiredOnly)
  409. };
  410. static char *MonitoringCriterionEnumTypeStr[] = {
  411. MACROSTR(ThresholdMonitoring),
  412. MACROSTR(DeltaMonitoring),
  413. MACROSTR(PeriodicMonitoring)
  414. };
  415. static char *MutabilityEnumTypeStr[] = {
  416. MACROSTR(ReadOnly),
  417. MACROSTR(WriteOnly),
  418. MACROSTR(ReadWrite)
  419. };
  420. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  421. MACROSTR(Accepted),
  422. MACROSTR(Rejected),
  423. MACROSTR(Processing)
  424. };
  425. static char *OCPPInterfaceEnumTypeStr[] = {
  426. MACROSTR(Wired0),
  427. MACROSTR(Wired1),
  428. MACROSTR(Wired2),
  429. MACROSTR(Wired3),
  430. MACROSTR(Wireless0),
  431. MACROSTR(Wireless1),
  432. MACROSTR(Wireless2),
  433. MACROSTR(Wireless3)
  434. };
  435. static char *OCPPTransportEnumTypeStr[] = {
  436. MACROSTR(JSON),
  437. MACROSTR(SOAP)
  438. };
  439. static char *OCPPVersionEnumTypeStr[] = {
  440. MACROSTR(OCPP12),
  441. MACROSTR(OCPP15),
  442. MACROSTR(OCPP16),
  443. MACROSTR(OCPP20)
  444. };
  445. static char *OperationalStatusEnumTypeStr[] = {
  446. MACROSTR(Inoperative),
  447. MACROSTR(Operative)
  448. };
  449. static char *PhaseEnumTypeStr[] = {
  450. MACROSTR(L1),
  451. MACROSTR(L2),
  452. MACROSTR(L3),
  453. MACROSTR(N),
  454. MACROSTR(L1-N),
  455. MACROSTR(L2-N),
  456. MACROSTR(L3-N),
  457. MACROSTR(L1-L2),
  458. MACROSTR(L2-L3),
  459. MACROSTR(L3-L1)
  460. };
  461. static char *PublishFirmwareStatusEnumTypeStr[] = {
  462. MACROSTR(Downloaded),
  463. MACROSTR(DownloadFailed),
  464. MACROSTR(Downloading),
  465. MACROSTR(DownloadScheduled),
  466. MACROSTR(DownloadPaused),
  467. MACROSTR(PublishFailed),
  468. MACROSTR(Published),
  469. MACROSTR(InvalidChecksum),
  470. MACROSTR(ChecksumVerified)
  471. };
  472. static char *ReadingContextEnumTypeStr[] = {
  473. MACROSTR(Interruption.Begin),
  474. MACROSTR(Interruption.End),
  475. MACROSTR(Other),
  476. MACROSTR(Sample.Clock),
  477. MACROSTR(Sample.Periodic),
  478. MACROSTR(Transaction.Begin),
  479. MACROSTR(Transaction.End),
  480. MACROSTR(Trigger)
  481. };
  482. #if 0
  483. static char *ReasonEnumTypeStr[] = {
  484. MACROSTR(DeAuthorized),
  485. MACROSTR(EmergencyStop),
  486. MACROSTR(EnergyLimitReached),
  487. MACROSTR(EVDisconnected),
  488. MACROSTR(GroundFault),
  489. MACROSTR(ImmediateReset),
  490. MACROSTR(Local),
  491. MACROSTR(LocalOutOfCredit),
  492. MACROSTR(MasterPass),
  493. MACROSTR(Other),
  494. MACROSTR(OvercurrentFault),
  495. MACROSTR(PowerLoss),
  496. MACROSTR(PowerQuality),
  497. MACROSTR(Reboot),
  498. MACROSTR(Remote),
  499. MACROSTR(SOCLimitReached),
  500. MACROSTR(StoppedByEV),
  501. MACROSTR(TimeLimitReached),
  502. MACROSTR(TimeLimitReached)
  503. };
  504. #endif
  505. static char *RecurrencyKindEnumTypeStr[] = {
  506. MACROSTR(Daily),
  507. MACROSTR(Weekly)
  508. };
  509. static char *RegistrationStatusEnumTypeStr[] = {
  510. MACROSTR(Accepted),
  511. MACROSTR(Pending),
  512. MACROSTR(Rejected)
  513. };
  514. static char *ReportBaseEnumTypeStr[] = {
  515. MACROSTR(ConfigurationInventory),
  516. MACROSTR(FullInventory),
  517. MACROSTR(SummaryInventory)
  518. };
  519. static char *RequestStartStopStatusEnumTypeStr[] = {
  520. MACROSTR(Accepted),
  521. MACROSTR(Rejected)
  522. };
  523. static char *ReservationUpdateStatusEnumTypeStr[] = {
  524. MACROSTR(Expired),
  525. MACROSTR(Removed)
  526. };
  527. static char *ReserveNowStatusEnumTypeStr[] = {
  528. MACROSTR(Accepted),
  529. MACROSTR(Faulted),
  530. MACROSTR(Occupied),
  531. MACROSTR(Rejected),
  532. MACROSTR(Unavailable)
  533. };
  534. static char *ResetEnumTypeStr[] = {
  535. MACROSTR(Immediate),
  536. MACROSTR(OnIdle)
  537. };
  538. static char *ResetStatusEnumTypeStr[] = {
  539. MACROSTR(Accepted),
  540. MACROSTR(Rejected),
  541. MACROSTR(Scheduled)
  542. };
  543. static char *SetMonitoringStatusEnumTypeStr[] = {
  544. MACROSTR(Accepted),
  545. MACROSTR(UnknownComponent),
  546. MACROSTR(UnknownVariable),
  547. MACROSTR(UnsupportedMonitorType),
  548. MACROSTR(Rejected),
  549. MACROSTR(OutOfRange),
  550. MACROSTR(Duplicate)
  551. };
  552. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  553. MACROSTR(Accepted),
  554. MACROSTR(Rejected),
  555. MACROSTR(Failed)
  556. };
  557. static char *SetVariableStatusEnumTypeStr[] = {
  558. MACROSTR(Accepted),
  559. MACROSTR(Rejected),
  560. MACROSTR(InvalidValue),
  561. MACROSTR(UnknownComponent),
  562. MACROSTR(UnknownVariable),
  563. MACROSTR(NotSupportedAttributeType),
  564. MACROSTR(OutOfRange),
  565. MACROSTR(RebootRequired)
  566. };
  567. static char *TransactionEventEnumTypeStr[] = {
  568. MACROSTR(Ended),
  569. MACROSTR(Started),
  570. MACROSTR(Updated)
  571. };
  572. static char *TriggerMessageStatusEnumTypeStr[] = {
  573. MACROSTR(Accepted),
  574. MACROSTR(Rejected),
  575. MACROSTR(NotImplemented)
  576. };
  577. static char *TriggerReasonEnumTypeStr[] = {
  578. MACROSTR(Authorized),
  579. MACROSTR(CablePluggedIn),
  580. MACROSTR(ChargingRateChanged),
  581. MACROSTR(ChargingStateChanged),
  582. MACROSTR(Deauthorized),
  583. MACROSTR(EnergyLimitReached),
  584. MACROSTR(EVCommunicationLost),
  585. MACROSTR(EVConnectTimeout),
  586. MACROSTR(MeterValueClock),
  587. MACROSTR(MeterValuePeriodic),
  588. MACROSTR(TimeLimitReached),
  589. MACROSTR(Trigger),
  590. MACROSTR(UnlockCommand),
  591. MACROSTR(StopAuthorized),
  592. MACROSTR(EVDeparted),
  593. MACROSTR(EVDetected),
  594. MACROSTR(RemoteStop),
  595. MACROSTR(RemoteStart),
  596. MACROSTR(AbnormalCondition),
  597. MACROSTR(SignedDataReceived),
  598. MACROSTR(ResetCommand)
  599. };
  600. static char *UnlockStatusEnumTypeStr[] = {
  601. MACROSTR(Unlocked),
  602. MACROSTR(UnlockFailed),
  603. MACROSTR(OngoingAuthorizedTransaction),
  604. MACROSTR(UnknownConnector)
  605. };
  606. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  607. MACROSTR(DownloadOngoing),
  608. MACROSTR(NoFirmware),
  609. MACROSTR(Unpublished)
  610. };
  611. static char *UpdateEnumTypeStr[] = {
  612. MACROSTR(Differential),
  613. MACROSTR(Full)
  614. };
  615. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  616. MACROSTR(Accepted),
  617. MACROSTR(Rejected),
  618. MACROSTR(AcceptedCanceled),
  619. MACROSTR(InvalidCertificate),
  620. MACROSTR(RevokedCertificate)
  621. };
  622. static char *UpdateStatusEnumTypeStr[] = {
  623. MACROSTR(Accepted),
  624. MACROSTR(Failed),
  625. MACROSTR(VersionMismatch)
  626. };
  627. static char *UploadLogStatusEnumTypeStr[] = {
  628. MACROSTR(BadMessage),
  629. MACROSTR(Idle),
  630. MACROSTR(NotSupportedOperation),
  631. MACROSTR(PermissionDenied),
  632. MACROSTR(Uploaded),
  633. MACROSTR(UploadFailure),
  634. MACROSTR(Uploading),
  635. MACROSTR(AcceptedCanceled)
  636. };
  637. static char *VPNEnumTypeStr[] = {
  638. MACROSTR(IKEv2),
  639. MACROSTR(IPSec),
  640. MACROSTR(L2TP),
  641. MACROSTR(PPTP)
  642. };
  643. #if 0
  644. static char *ChargePointErrorCodeEnumTypeStr[] = {
  645. MACROSTR(ConnectorLockFailure),
  646. MACROSTR(EVCommunicationError),
  647. MACROSTR(GroundFailure),
  648. MACROSTR(HighTemperature),
  649. MACROSTR(InternalError),
  650. MACROSTR(LocalListConflict),
  651. MACROSTR(NoError),
  652. MACROSTR(OtherError),
  653. MACROSTR(OverCurrentFailure),
  654. MACROSTR(OverVoltage),
  655. MACROSTR(PowerMeterFailure),
  656. MACROSTR(PowerSwitchFailure),
  657. MACROSTR(ReaderFailure),
  658. MACROSTR(ResetFailure),
  659. MACROSTR(UnderVoltage),
  660. MACROSTR(WeakSignal)
  661. };
  662. #endif
  663. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  664. MACROSTR(Accepted),
  665. MACROSTR(Rejected)
  666. };
  667. static char *RemoteStartStopStatusEnumTypeStr[] = {
  668. MACROSTR(Accepted),
  669. MACROSTR(Rejected)
  670. };
  671. #if 0
  672. static char * StopTransactionReasonEnumTypeStr[] = {
  673. MACROSTR(EmergencyStop),
  674. MACROSTR(EVDisconnected),
  675. MACROSTR(HardReset),
  676. MACROSTR(Local),
  677. MACROSTR(Other),
  678. MACROSTR(PowerLoss),
  679. MACROSTR(Reboot),
  680. MACROSTR(Remote),
  681. MACROSTR(SoftReset),
  682. MACROSTR(UnlockCommand),
  683. MACROSTR(DeAuthorized)
  684. };
  685. #endif
  686. //ChargePointMaxProfile
  687. #define ChargingStationMaxProfile_JSON "/Storage/OCPP/ChargingStationMaxProfile_OCPP20.json"
  688. //TxDefaultProfile
  689. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  690. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  691. struct StatusCodeData *ShmStatusCodeData;
  692. struct PsuData *ShmPsuData ;
  693. struct OCPP20Data *ShmOCPP20Data;
  694. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  695. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  696. //===============================
  697. // Gun Total Numbers
  698. //===============================
  699. static ParsingRatedCur modelnameInfo = {0};
  700. static int gunTotalNumber = 0;
  701. static uint8_t gunType[4] = {0};
  702. //===============================
  703. // Local List Version
  704. //===============================
  705. static int localversion=0;
  706. //===============================
  707. // Variable Version
  708. //===============================
  709. static int variableVersion=7;
  710. //===============================
  711. // OCPP sign variable
  712. //===============================
  713. static int server_sign = FALSE;
  714. int server_pending = FALSE;
  715. static int BootNotificationInterval = 10;
  716. //===============================
  717. // OCPP auth variable
  718. //===============================
  719. static int authorizeRetryTimes = 0; //number of Retry times
  720. //===============================
  721. // OCPP other variables
  722. //===============================
  723. static int HeartBeatWaitTime = 10;
  724. static int FirstHeartBeat = 0;
  725. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  726. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  727. static char CurrentChargingProfileScheduleStr[30] = {0};
  728. static int isCancelUploadLog = FALSE;
  729. pthread_t th_GetLog;
  730. //========================================
  731. // OCPP status/previous related variables
  732. //========================================
  733. static int GunStatusInterval = 10;
  734. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  735. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  736. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  737. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  738. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  739. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  740. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  741. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  742. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  743. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  744. static int TransactionMessageAttemptsValue = 0;
  745. static int TransactionMessageRetryIntervalValue = 0;
  746. static struct AuthorizationData idTagQuery;
  747. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  748. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  749. //=============================================
  750. // OCPP HeartBeat Response Not Receive Counts
  751. //============================================
  752. static int HeartBeatWithNOResponse = 0;
  753. static int HeartBeatCountPerHour = 0;
  754. sqlite3 *db;
  755. int TransactionMessageAttemptsGet(void);
  756. int TransactionMessageRetryIntervalGet(void);
  757. int GetOcppConnStatus(void);
  758. void SetOcppConnStatus(uint8_t status);
  759. int setKeyValue(char *key, char *value);
  760. void OCPP_get_TableAuthlocalAllData(void);
  761. void processUnkownKey(void);
  762. struct InterLock
  763. {
  764. unsigned char isGetLogGoing:1;
  765. unsigned char isUpdateFirmwareGoing:1;
  766. }interLock;
  767. struct ClientTime
  768. {
  769. struct timespec Heartbeat;
  770. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  771. struct timespec StartTransaction;
  772. struct timespec StopTransaction;
  773. struct timespec MeterValues[CONNECTOR_QUANTITY];
  774. struct timespec RemoteStartWait;
  775. }clientTime;
  776. typedef union
  777. {
  778. //Operations Initiated by Central System
  779. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  780. struct
  781. {
  782. //CsMsgValue[0]
  783. unsigned char StatusNotificationReq:1; //bit 0,
  784. unsigned char StatusNotificationConf:1; //bit 1,
  785. unsigned char TriggerMeterValueReq:1; //bit 2,
  786. unsigned char SampleMeterReq:1; //bit 3,
  787. unsigned char ClockAlignMeterReq:1; //bit 4,
  788. unsigned char TriggerStatusNotificationReq:1; //bit 5,
  789. unsigned char isOnCharging:1; //bit 6,
  790. unsigned char TriggerTransactionEventReq:1; //bit 7
  791. }bits[CONNECTOR_QUANTITY];
  792. }CpinitiateMsg;
  793. CpinitiateMsg cpinitateMsg;
  794. //=========================================
  795. // Save configuration
  796. //=========================================
  797. int runShellCmd(const char*cmd)
  798. {
  799. int result = FAIL;
  800. char buf[256];
  801. FILE *fp;
  802. fp = popen(cmd, "r");
  803. if(fp != NULL)
  804. {
  805. while(fgets(buf, sizeof(buf), fp) != NULL)
  806. {
  807. DEBUG_INFO("%s\n", buf);
  808. }
  809. result = PASS;
  810. }
  811. pclose(fp);
  812. return result;
  813. }
  814. int StoreUsrConfigData(struct SysConfigData *UsrData)
  815. {
  816. int result = PASS;
  817. int fd,wrd;
  818. unsigned int i,Chk;
  819. unsigned char *ptr, *BufTmp;
  820. int MtdBlockSize = 0x300000;
  821. Chk=0;
  822. ptr=(unsigned char *)UsrData;
  823. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  824. {
  825. memset(BufTmp,0,MtdBlockSize);
  826. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  827. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  828. Chk+=*(BufTmp+i);
  829. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  830. // Output configuration to file.
  831. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  832. if (fd < 0)
  833. {
  834. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  835. free(BufTmp);
  836. return 0;
  837. }
  838. wrd=write(fd, BufTmp, MtdBlockSize);
  839. close(fd);
  840. if(wrd<MtdBlockSize)
  841. {
  842. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  843. free(BufTmp);
  844. return 0;
  845. }
  846. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  847. DEBUG_INFO("Erase /dev/mtd10.\n");
  848. runShellCmd("flash_erase /dev/mtd10 0 0");
  849. DEBUG_INFO("Write /dev/mtd10.\n");
  850. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  851. DEBUG_INFO("Erase /dev/mtd11.\n");
  852. runShellCmd("flash_erase /dev/mtd11 0 0");
  853. DEBUG_INFO("Write /dev/mtd11.\n");
  854. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  855. system("rm -f /mnt/EvseConfig.bin");
  856. DEBUG_INFO("EvseConfig write to flash OK\n");
  857. }
  858. else
  859. {
  860. DEBUG_ERROR("alloc BlockSize NG\r\n");
  861. result = FAIL;
  862. }
  863. if(BufTmp!=NULL)
  864. free(BufTmp);
  865. return result;
  866. }
  867. //=========================================
  868. // Date time related function
  869. //=========================================
  870. void getNowDatetime(uint8_t *data)
  871. {
  872. time_t t = time(NULL);
  873. struct tm tm = *localtime(&t);
  874. 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);
  875. }
  876. //=========================================
  877. // Sqlite3 related function
  878. //=========================================
  879. int DB_Initial()
  880. {
  881. int result = PASS;
  882. char* errMsg = NULL;
  883. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  884. "idToken text UNIQUE,"
  885. "type text,"
  886. "status text,"
  887. "cacheExpiryDateTime text,"
  888. "chargingPriority integer,"
  889. "language1 text,"
  890. "evseId text,"
  891. "language2 text,"
  892. "groupIdToken_idToken text,"
  893. "groupIdToken_type text,"
  894. "personalMessage text);";
  895. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  896. "idToken text UNIQUE,"
  897. "type text,"
  898. "status text,"
  899. "cacheExpiryDateTime text,"
  900. "chargingPriority integer,"
  901. "language1 text,"
  902. "evseId text,"
  903. "language2 text,"
  904. "groupIdToken_idToken text,"
  905. "groupIdToken_type text,"
  906. "personalMessage text,"
  907. "version text);";
  908. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  909. "componentName text NOT NULL ,"
  910. "componentInstance text, "
  911. "variableName text NOT NULL, "
  912. "variableInstance text, "
  913. "variableCharacteristicsDataType integer, "
  914. "variableCharacteristicsUnit text, "
  915. "variableCharacteristicsMaxLimit real,"
  916. "variableAttributesType text, "
  917. "variableAttributesTypeMutability text, "
  918. "variableAttributesTypeValue text, "
  919. "variableCharacteristicsMinLimit real,"
  920. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  921. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  922. "type text);";
  923. char *sqlSecurityEventType = "create table if not exists ocpp20_securityevent_type (idx integer primary key,"
  924. "type text);";
  925. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  926. "slot integer UNIQUE, connectionData text);";
  927. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  928. "occurDatetime text,"
  929. "message_type text,"
  930. "message_content text)";
  931. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  932. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  933. {
  934. result = FAIL;
  935. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  936. sqlite3_close(db);
  937. }
  938. else
  939. {
  940. DEBUG_INFO( "OCPP local database open successfully.\n");
  941. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  942. {
  943. result = FAIL;
  944. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  945. }
  946. else
  947. {
  948. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  949. }
  950. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  951. {
  952. result = FAIL;
  953. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  954. }
  955. else
  956. {
  957. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  958. }
  959. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  960. {
  961. result = FAIL;
  962. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  963. }
  964. else
  965. {
  966. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  967. }
  968. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  969. {
  970. result = FAIL;
  971. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  972. }
  973. else
  974. {
  975. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  976. }
  977. if (sqlite3_exec(db, sqlSecurityEventType, 0, 0, &errMsg) != SQLITE_OK)
  978. {
  979. result = FAIL;
  980. DEBUG_ERROR( "Create OCPP 2.0 securityevent_type table error message: %s\n", errMsg);
  981. }
  982. else
  983. {
  984. DEBUG_INFO( "Create OCPP 2.0 securityevent_type table successfully\n");
  985. }
  986. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  987. {
  988. result = FAIL;
  989. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  990. }
  991. else
  992. {
  993. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  994. }
  995. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  996. {
  997. result = FAIL;
  998. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  999. }
  1000. else
  1001. {
  1002. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  1003. }
  1004. //sqlite3_close(db);
  1005. }
  1006. return result;
  1007. }
  1008. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  1009. {
  1010. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  1011. return 0;
  1012. }
  1013. void DB_getListVerion()
  1014. {
  1015. char sql[256];
  1016. char* errMsg = NULL;
  1017. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  1018. /* Execute SQL statement */
  1019. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  1020. {
  1021. DEBUG_INFO("SQL error: %s", errMsg);
  1022. }
  1023. }
  1024. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  1025. {
  1026. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  1027. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  1028. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  1029. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  1030. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  1031. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  1032. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  1033. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  1034. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  1035. return 0;
  1036. }
  1037. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1038. {
  1039. char sql[256];
  1040. char* errMsg = NULL;
  1041. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1042. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1043. if(isQueryFromCache)
  1044. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1045. else
  1046. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1047. /* Execute SQL statement */
  1048. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1049. {
  1050. DEBUG_INFO("SQL error: %s", errMsg);
  1051. }
  1052. }
  1053. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1054. {
  1055. for (int i = 0; i < columnCount; i++)
  1056. {
  1057. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1058. }
  1059. return 0;
  1060. }
  1061. void DB_get_TableAuthlocalAllData(void)
  1062. {
  1063. char sql[256];
  1064. char* errMsg = NULL;
  1065. sprintf(sql,"select * from ocpp20_auth_local;");
  1066. /* Execute SQL statement */
  1067. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1068. {
  1069. DEBUG_INFO("SQL error: %s", errMsg);
  1070. }
  1071. }
  1072. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1073. {
  1074. for(int i = 0; i<columnCount; i++)
  1075. {
  1076. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1077. }
  1078. return 0;
  1079. }
  1080. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1081. {
  1082. int result = PASS;
  1083. char sql[512];
  1084. char* errMsg = NULL;
  1085. 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;",
  1086. data->idToken.idToken,
  1087. data->idToken.type,
  1088. data->idTokenInfo.status,
  1089. data->idTokenInfo.cacheExpiryDateTime,
  1090. data->idTokenInfo.chargingPriority,
  1091. data->idTokenInfo.language1,
  1092. data->idTokenInfo.language2,
  1093. data->idTokenInfo.groupIdToken.idToken,
  1094. data->idTokenInfo.groupIdToken.type,
  1095. listVersion);
  1096. //* Execute SQL statement */
  1097. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1098. {
  1099. DEBUG_INFO("SQL error: %s\n", errMsg);
  1100. result = FAIL;
  1101. }
  1102. else
  1103. {
  1104. memset(sql, 0, ARRAY_SIZE(sql));
  1105. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1106. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1107. {
  1108. DEBUG_INFO("SQL error: %s\n", errMsg);
  1109. result = FAIL;
  1110. }
  1111. }
  1112. return result;
  1113. }
  1114. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1115. {
  1116. int result = PASS;
  1117. char sql[512];
  1118. char* errMsg = NULL;
  1119. 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;",
  1120. idToken->idToken,
  1121. idToken->type,
  1122. idTokenInfo->status,
  1123. idTokenInfo->cacheExpiryDateTime,
  1124. idTokenInfo->chargingPriority,
  1125. idTokenInfo->language1,
  1126. idTokenInfo->language2,
  1127. idTokenInfo->groupIdToken.idToken,
  1128. idTokenInfo->groupIdToken.type);
  1129. //* Execute SQL statement */
  1130. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1131. {
  1132. DEBUG_INFO("SQL error: %s\n", errMsg);
  1133. result = FAIL;
  1134. }
  1135. return result;
  1136. }
  1137. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1138. {
  1139. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1140. // printf("localversion=%d\n", localversion);
  1141. return 0;
  1142. }
  1143. void DB_deleteIdTag(char idTag[])
  1144. {
  1145. char sql[512];
  1146. char* errMsg = NULL;
  1147. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1148. //* Execute SQL statement */
  1149. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1150. {
  1151. DEBUG_INFO("SQL error: %s", errMsg);
  1152. }
  1153. }
  1154. int DB_cleanLocalList()
  1155. {
  1156. int result = PASS;
  1157. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1158. char *errMsg = 0;
  1159. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1160. {
  1161. DEBUG_INFO("%s\n", errMsg);
  1162. result = FAIL;
  1163. }
  1164. return result;
  1165. }
  1166. int DB_cleanLocalCache()
  1167. {
  1168. int result = PASS;
  1169. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1170. char *errMsg = 0;
  1171. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1172. {
  1173. DEBUG_INFO("%s\n", errMsg);
  1174. result = FAIL;
  1175. }
  1176. return result;
  1177. }
  1178. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1179. {
  1180. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1181. return 0;
  1182. }
  1183. void DB_getBooType()
  1184. {
  1185. char sql[256];
  1186. char* errMsg = NULL;
  1187. sprintf(sql,"select * from ocpp20_boot_type;");
  1188. /* Execute SQL statement */
  1189. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1190. {
  1191. DEBUG_INFO("SQL error: %s\n", errMsg);
  1192. }
  1193. }
  1194. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1195. {
  1196. for(int i = 0; i<columnCount; i++)
  1197. {
  1198. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1199. }
  1200. return 0;
  1201. }
  1202. int DB_updateBootType(BootReasonEnumType reason)
  1203. {
  1204. int result = PASS;
  1205. char sql[512];
  1206. char* errMsg = NULL;
  1207. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1208. //* Execute SQL statement */
  1209. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1210. {
  1211. DEBUG_INFO("SQL error: %s\n", errMsg);
  1212. result = FAIL;
  1213. }
  1214. return result;
  1215. }
  1216. int SecurityEventTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1217. {
  1218. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", columnValue[1] ? columnValue[1] : SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  1219. return 0;
  1220. }
  1221. void DB_getSecurityEventType()
  1222. {
  1223. char sql[256];
  1224. char* errMsg = NULL;
  1225. sprintf(sql,"select * from ocpp20_securityevent_type;");
  1226. /* Execute SQL statement */
  1227. if(sqlite3_exec(db, sql, SecurityEventTypecallback, 0, &errMsg) != SQLITE_OK )
  1228. {
  1229. DEBUG_INFO("SQL error: %s\n", errMsg);
  1230. }
  1231. }
  1232. int DB_cbUpdateSecurityEventType(void *para, int columnCount, char **columnValue, char **columnName)
  1233. {
  1234. for(int i = 0; i<columnCount; i++)
  1235. {
  1236. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1237. }
  1238. return 0;
  1239. }
  1240. int DB_updateSecurityEventType(SecurityEventEnumType reason)
  1241. {
  1242. int result = PASS;
  1243. char sql[512];
  1244. char* errMsg = NULL;
  1245. sprintf(sql,"insert or replace into ocpp20_securityevent_type (idx, type) VALUES(1, '%s');", SecurityEventEnumTypeStr[reason]);
  1246. //* Execute SQL statement */
  1247. if(sqlite3_exec(db, sql, DB_cbUpdateSecurityEventType, 0, &errMsg) != SQLITE_OK)
  1248. {
  1249. DEBUG_INFO("SQL error: %s\n", errMsg);
  1250. result = FAIL;
  1251. }
  1252. return result;
  1253. }
  1254. int DB_variableClear()
  1255. {
  1256. int result = PASS;
  1257. char * sqlcleanLocalList = "delete from ocpp20_variable";
  1258. char *errMsg = 0;
  1259. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1260. {
  1261. DEBUG_INFO("%s\n", errMsg);
  1262. result = FAIL;
  1263. }
  1264. return result;
  1265. }
  1266. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1267. {
  1268. for(int i = 0; i<columnCount; i++)
  1269. {
  1270. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1271. }
  1272. return 0;
  1273. }
  1274. int DB_variableSaveToDb(struct ReportDataType *variable)
  1275. {
  1276. int result = FAIL;
  1277. char sql[4096];
  1278. char* errMsg = NULL;
  1279. sprintf(sql,"insert or replace into ocpp20_variable (componentName, componentInstance, variableName, variableInstance, variableCharacteristicsDataType, variableCharacteristicsUnit, variableCharacteristicsMaxLimit, variableAttributesType, variableAttributesTypeMutability, variableAttributesTypeValue, variableCharacteristicsMinLimit) VALUES('%s', '%s', '%s', '%s', '%s', '%s', %f, '%s', '%s', '%s', '%f'); SELECT * from ocpp20_variable;",
  1280. variable->component.name,
  1281. variable->component.instance,
  1282. variable->variable.name,
  1283. variable->variable.instance,
  1284. variable->variableCharacteristics.dataType,
  1285. variable->variableCharacteristics.unit,
  1286. variable->variableCharacteristics.maxLimit,
  1287. variable->variableAttribute[0].type,
  1288. variable->variableAttribute[0].mutability,
  1289. variable->variableAttribute[0].value,
  1290. variable->variableCharacteristics.minLimit);
  1291. //* Execute SQL statement */
  1292. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1293. {
  1294. DEBUG_INFO("SQL error: %s\n", errMsg);
  1295. result = FAIL;
  1296. }
  1297. return result;
  1298. }
  1299. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1300. {
  1301. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1302. if(atoi(columnValue[0]) == 0)
  1303. {
  1304. DB_updateBootType(BootReasonEnumType_PowerUp);
  1305. // Create variable table content
  1306. /* AlignedDataCtrlr Required item */
  1307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "false");
  1313. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "true");
  1320. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1324. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1329. "Energy.Active.Import.Register,"
  1330. "Energy.Active.Import.Interval,"
  1331. "Power.Active.Import,"
  1332. "Voltage,"
  1333. "SoC,"
  1334. "Current.Offered,"
  1335. "Power.Offered");
  1336. else
  1337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1338. "Energy.Active.Import.Register,"
  1339. "Energy.Active.Import.Interval,"
  1340. "Power.Active.Import,"
  1341. "Voltage,"
  1342. "Current.Offered");
  1343. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1348. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 5;
  1349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1352. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "true");
  1359. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  1366. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1370. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1375. "Energy.Active.Import.Register,"
  1376. "Energy.Active.Import.Interval,"
  1377. "Power.Active.Import,"
  1378. "Voltage,"
  1379. "SoC");
  1380. else
  1381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1382. "Energy.Active.Import.Register,"
  1383. "Energy.Active.Import.Interval,"
  1384. "Power.Active.Import,"
  1385. "Voltage");
  1386. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1394. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1395. /* AuthCtrlrVariable Required item */
  1396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE?"true":"false");
  1402. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AuthCtrlr");
  1404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1409. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "false");
  1416. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "false");
  1423. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true");
  1430. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true");
  1437. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1441. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1445. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1446. /* AuthCacheCtrlr Variable Required item*/
  1447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "false");
  1453. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "true");
  1460. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "true");
  1468. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1472. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "true");
  1476. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1483. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1484. /* ClockCtrlr Variable Required item */
  1485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1490. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1491. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1498. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1506. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1513. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1520. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1528. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1535. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1542. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1543. /* ChargingStation Required item */
  1544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "false");
  1550. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1557. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1564. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  1566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  1567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].value, "0");
  1571. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec]);
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  1573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  1578. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend]);
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  1580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  1581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value, "FreeVendIdtag");
  1585. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag]);
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].value, "0");
  1592. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower]);
  1593. /* Connector Required item */
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "false");
  1600. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1607. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1614. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1615. /* CustomizationCtrlr Required item */
  1616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "false");
  1622. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1623. /* DeviceDataCtrlr Required item */
  1624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1631. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1639. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1647. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1655. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1658. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1663. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1666. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1671. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1679. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1687. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1688. /* DisplayMessageCtrlr Required item */
  1689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "false");
  1695. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "false");
  1702. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1706. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1708. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1710. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1717. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1724. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1725. /* EVSE Required item */
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "false");
  1732. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1739. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1746. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1753. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1754. /* LocalAuthListCtrlr Required item */
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true");
  1761. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1765. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1769. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "true");
  1776. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1783. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  1784. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  1792. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1796. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  1800. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1801. /* MonitoringCtrlr Required item */
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "false");
  1808. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "false");
  1815. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1823. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1831. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1839. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1847. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1854. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1855. /* OCPPCommCtrlr Required item */
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1862. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1871. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1878. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1882. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1887. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1894. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1901. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1909. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "false");
  1916. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1925. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  1934. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "true");
  1941. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1945. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1950. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1957. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1964. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  1971. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "false");
  1978. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  1982. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  1987. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  1988. /* ReservationCtrlr Required item */
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "true");
  1995. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "true");
  2002. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "false");
  2009. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  2010. /* SampledDataCtrlr Required item */
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "true");
  2017. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "true");
  2024. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  2031. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2035. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2040. "Energy.Active.Import.Register,"
  2041. "Energy.Active.Import.Interval,"
  2042. "Power.Active.Import,"
  2043. "Voltage,"
  2044. "SoC");
  2045. else
  2046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2047. "Energy.Active.Import.Register,"
  2048. "Energy.Active.Import.Interval,"
  2049. "Power.Active.Import,"
  2050. "Voltage");
  2051. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  2059. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2063. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  2067. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2071. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2076. "Energy.Active.Import.Register,"
  2077. "Energy.Active.Import.Interval,"
  2078. "Power.Active.Import,"
  2079. "Voltage,"
  2080. "SoC,"
  2081. "Current.Offered,"
  2082. "Power.Offered");
  2083. else
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2085. "Energy.Active.Import.Register,"
  2086. "Energy.Active.Import.Interval,"
  2087. "Power.Active.Import,"
  2088. "Voltage,"
  2089. "Current.Offered");
  2090. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2095. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2099. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2100. /* SecurityCtrlr Required item */
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2104. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", (strlen((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword)>0?(char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword:"00000000"));
  2108. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2112. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2116. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2123. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2127. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2131. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2138. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "false");
  2145. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2149. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2153. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2154. /* SmartChargingCtrlr Required item */
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "true");
  2161. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "true");
  2168. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "false");
  2175. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "3");
  2182. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2189. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2196. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "false");
  2203. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "false");
  2210. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "false");
  2217. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2221. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2225. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2232. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2233. /* TariffCostCtrlr Required item */
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "false");
  2241. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "false");
  2249. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2253. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2257. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "false");
  2265. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "false");
  2273. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2277. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2281. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2285. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2289. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2290. /* TxCtrlr Required item */
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2297. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2305. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "true");
  2312. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2319. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2326. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2333. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2341. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "false");
  2348. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2349. }
  2350. else
  2351. {
  2352. // Variable name init
  2353. /* AlignedDataCtrlr Required item */
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2370. /* AuthCtrlrVariable Required item */
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2385. /* AuthCacheCtrlr Variable Required item */
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2396. /* ClockCtrlr Variable Required item */
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2415. /* ChargingStation Required item */
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2430. /* Connector Required item */
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2437. /* CustomizationCtrlr Required item */
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2440. /* DeviceDataCtrlr Required item */
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2463. /* DisplayMessageCtrlr Required item */
  2464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2474. /* EVSE Required item */
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2483. /* LocalAuthListCtrlr Required item */
  2484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2498. /* MonitoringCtrlr Required item */
  2499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2517. /* OCPPCommCtrlr Required item */
  2518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2555. /* ReservationCtrlr Required item */
  2556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2562. /* SampledDataCtrlr Required item */
  2563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2579. /* SecurityCtrlr Required item */
  2580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2594. /* SmartChargingCtrlr Required item */
  2595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2617. /* TariffCostCtrlr Required item */
  2618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2636. /* TxCtrlr Required item */
  2637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2653. }
  2654. return 0;
  2655. }
  2656. void DB_variableIsCreate()
  2657. {
  2658. char sql[512];
  2659. char* errMsg = NULL;
  2660. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2661. /* Execute SQL statement */
  2662. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2663. {
  2664. DEBUG_INFO("SQL error: %s\n", errMsg);
  2665. }
  2666. }
  2667. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2668. {
  2669. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2670. {
  2671. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2672. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2673. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2674. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2675. {
  2676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2678. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2682. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  2683. }
  2684. }
  2685. return 0;
  2686. }
  2687. void DB_variableLoadFromDb()
  2688. {
  2689. char sql[512];
  2690. char* errMsg = NULL;
  2691. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2692. /* Execute SQL statement */
  2693. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2694. {
  2695. DEBUG_INFO("SQL error: %s\n", errMsg);
  2696. }
  2697. }
  2698. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2699. {
  2700. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2701. if(columnCount > 0)
  2702. {
  2703. for(int idx=0;idx<columnCount;idx++)
  2704. {
  2705. json_object *SetNetworkProfile;
  2706. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2707. if(!is_error(SetNetworkProfile))
  2708. {
  2709. // Required data
  2710. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2711. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2712. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2713. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2714. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2715. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2716. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2717. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2718. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2719. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2720. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2721. {
  2722. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2723. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2724. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2725. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2726. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2727. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2728. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2729. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2730. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2731. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2732. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2733. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2734. }
  2735. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2736. {
  2737. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2738. {
  2739. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2740. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2741. }
  2742. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2743. {
  2744. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2745. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2746. }
  2747. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2748. {
  2749. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2750. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2751. }
  2752. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2753. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2754. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2755. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2756. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2757. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2758. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2759. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2760. }
  2761. }
  2762. json_object_put(SetNetworkProfile);
  2763. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2764. }
  2765. }
  2766. return 0;
  2767. }
  2768. void DB_getNetworkProfileFromDb()
  2769. {
  2770. char sql[512];
  2771. char* errMsg = NULL;
  2772. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2773. /* Execute SQL statement */
  2774. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2775. {
  2776. DEBUG_INFO("SQL error: %s\n", errMsg);
  2777. }
  2778. }
  2779. int DB_addNetworkProfile(int slot, char *data)
  2780. {
  2781. int result = PASS;
  2782. char sql[512];
  2783. char* errMsg = NULL;
  2784. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2785. slot,
  2786. data);
  2787. //* Execute SQL statement */
  2788. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2789. {
  2790. DEBUG_INFO("SQL error: %s\n", errMsg);
  2791. result = FAIL;
  2792. }
  2793. return result;
  2794. }
  2795. int DB_deleteNetworkProfile(int slot)
  2796. {
  2797. int result = PASS;
  2798. char sql[512];
  2799. char* errMsg = NULL;
  2800. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2801. //* Execute SQL statement */
  2802. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2803. {
  2804. DEBUG_INFO("SQL error: %s", errMsg);
  2805. result = FAIL;
  2806. }
  2807. return result;
  2808. }
  2809. int isNumber(uint8_t *string, uint8_t isFloat)
  2810. {
  2811. int result = NO;
  2812. int cntDecimal = 0;
  2813. float i;
  2814. for(int idx=0; idx<strlen((char*)string); idx++)
  2815. {
  2816. if((isdigit(string[idx])==0) && (string[idx] != '.'))
  2817. {
  2818. return result;
  2819. }
  2820. else if(string[idx] == '.')
  2821. cntDecimal++;
  2822. if(cntDecimal>1)
  2823. return result;
  2824. }
  2825. if((isFloat==FALSE) && (strstr((char*)string, ".") != NULL))
  2826. {
  2827. //DEBUG_INFO("%s is not pure integer!!\n", string);
  2828. }
  2829. else if((isFloat==TRUE) && (strstr((char*)string, ".") == NULL))
  2830. {
  2831. //DEBUG_INFO("%s is not float format!!\n", string);
  2832. }
  2833. else if(sscanf((char*)string, "%f", &i) != 0)
  2834. {
  2835. result = YES;
  2836. }
  2837. return result;
  2838. }
  2839. int isMatchTimeFormat(uint8_t *time)
  2840. {
  2841. int result = NO;
  2842. struct ParsingResult
  2843. {
  2844. int result;
  2845. int scanedElement;
  2846. int year;
  2847. int month;
  2848. int mday;
  2849. int hour;
  2850. int min;
  2851. int sec;
  2852. int tz_hour;
  2853. int tz_min;
  2854. float minSec;
  2855. }parsingResult;
  2856. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  2857. if(strstr((char*)time, ".") != NULL)
  2858. {
  2859. // Original data with mini second
  2860. if(strstr((char*)time, "Z") != NULL)
  2861. {
  2862. // Original data with Z
  2863. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%fZ",
  2864. &parsingResult.year,
  2865. &parsingResult.month,
  2866. &parsingResult.mday,
  2867. &parsingResult.hour,
  2868. &parsingResult.min,
  2869. &parsingResult.sec,
  2870. &parsingResult.minSec);
  2871. }
  2872. else
  2873. {
  2874. // Original data without Z
  2875. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2876. &parsingResult.year,
  2877. &parsingResult.month,
  2878. &parsingResult.mday,
  2879. &parsingResult.hour,
  2880. &parsingResult.min,
  2881. &parsingResult.sec,
  2882. &parsingResult.minSec,
  2883. &parsingResult.tz_hour,
  2884. &parsingResult.tz_min);
  2885. }
  2886. }
  2887. else
  2888. {
  2889. // Original data without mini second
  2890. if(strstr((char*)time, "Z") != NULL)
  2891. {
  2892. // Original data with Z
  2893. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%dZ",
  2894. &parsingResult.year,
  2895. &parsingResult.month,
  2896. &parsingResult.mday,
  2897. &parsingResult.hour,
  2898. &parsingResult.min,
  2899. &parsingResult.sec);
  2900. }
  2901. else
  2902. {
  2903. // Original data without Z
  2904. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d%d:%d",
  2905. &parsingResult.year,
  2906. &parsingResult.month,
  2907. &parsingResult.mday,
  2908. &parsingResult.hour,
  2909. &parsingResult.min,
  2910. &parsingResult.sec,
  2911. &parsingResult.tz_hour,
  2912. &parsingResult.tz_min);
  2913. }
  2914. }
  2915. if(parsingResult.scanedElement >= 6)
  2916. {
  2917. result = YES;
  2918. }
  2919. return result;
  2920. }
  2921. int getCurrentYear()
  2922. {
  2923. int result = 0;
  2924. time_t CurrentTime;
  2925. struct tm *tm;
  2926. CurrentTime = time(NULL);
  2927. tm=localtime(&CurrentTime);
  2928. result = (tm->tm_year + 1900);
  2929. return result;
  2930. }
  2931. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2932. {
  2933. int result = PASS;
  2934. char* errMsg = NULL;
  2935. char sqlStr[8192];
  2936. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2937. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2938. {
  2939. result = FAIL;
  2940. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  2941. }
  2942. 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));
  2943. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2944. {
  2945. result = FAIL;
  2946. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  2947. }
  2948. return result;
  2949. }
  2950. //==========================================
  2951. // Check time passed since today
  2952. //==========================================
  2953. long long DiffTimebWithNow(struct timeb ST)
  2954. {
  2955. //return milli-second
  2956. struct timeb ET;
  2957. long long StartTime,StopTime;
  2958. ftime(&ET);
  2959. StartTime=(long long)ST.time;
  2960. StopTime=(long long)ET.time;
  2961. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2962. }
  2963. int getTimePassSinceToday(uint8_t gun_index)
  2964. {
  2965. int result = -1;
  2966. static time_t lastTime[4];
  2967. time_t t;
  2968. struct tm *tmStartToday;
  2969. struct timeb tbStartToday;
  2970. t=time(NULL);
  2971. if(difftime(t, lastTime[gun_index])>0)
  2972. {
  2973. tmStartToday=localtime(&t);
  2974. tmStartToday->tm_hour = 0;
  2975. tmStartToday->tm_min = 0;
  2976. tmStartToday->tm_sec = 0;
  2977. tbStartToday.time = mktime(tmStartToday);
  2978. tbStartToday.millitm = 0;
  2979. result = DiffTimebWithNow(tbStartToday)/1000;
  2980. lastTime[gun_index] = t;
  2981. }
  2982. return result;
  2983. }
  2984. int syncDateTimeRTC(uint8_t *data)
  2985. {
  2986. struct ParsingResult
  2987. {
  2988. int result;
  2989. int scanedElement;
  2990. int year;
  2991. int month;
  2992. int mday;
  2993. int hour;
  2994. int min;
  2995. int sec;
  2996. int tz_hour;
  2997. int tz_min;
  2998. float minSec;
  2999. }result;
  3000. struct tm tmOrg;
  3001. struct tm *tmTarget;
  3002. struct timeb tbTarget;
  3003. char buf[128];
  3004. memset(&result, 0x00, sizeof(struct ParsingResult));
  3005. result.result = PASS;
  3006. if(strstr((char*)data, ".") != NULL)
  3007. {
  3008. // Original data with mini second
  3009. if(strstr((char*)data, "Z") != NULL)
  3010. {
  3011. // Original data with Z
  3012. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  3013. &result.year,
  3014. &result.month,
  3015. &result.mday,
  3016. &result.hour,
  3017. &result.min,
  3018. &result.sec,
  3019. &result.minSec);
  3020. }
  3021. else
  3022. {
  3023. // Original data without Z
  3024. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3025. &result.year,
  3026. &result.month,
  3027. &result.mday,
  3028. &result.hour,
  3029. &result.min,
  3030. &result.sec,
  3031. &result.minSec,
  3032. &result.tz_hour,
  3033. &result.tz_min);
  3034. }
  3035. }
  3036. else
  3037. {
  3038. // Original data without mini second
  3039. if(strstr((char*)data, "Z") != NULL)
  3040. {
  3041. // Original data with Z
  3042. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  3043. &result.year,
  3044. &result.month,
  3045. &result.mday,
  3046. &result.hour,
  3047. &result.min,
  3048. &result.sec);
  3049. }
  3050. else
  3051. {
  3052. // Original data without Z
  3053. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  3054. &result.year,
  3055. &result.month,
  3056. &result.mday,
  3057. &result.hour,
  3058. &result.min,
  3059. &result.sec,
  3060. &result.tz_hour,
  3061. &result.tz_min);
  3062. }
  3063. }
  3064. tmOrg.tm_year = result.year - 1900;
  3065. tmOrg.tm_mon = result.month - 1;
  3066. tmOrg.tm_mday = result.mday;
  3067. tmOrg.tm_hour = result.hour;
  3068. tmOrg.tm_min = result.min;
  3069. tmOrg.tm_sec = result.sec;
  3070. tmOrg.tm_gmtoff = 0;
  3071. tbTarget.time = mktime(&tmOrg);
  3072. tbTarget.timezone = 0;
  3073. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  3074. tmTarget = gmtime(&tbTarget.time);
  3075. 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);
  3076. //DEBUG_INFO(" org date time: %s\n", data);
  3077. //DEBUG_INFO("parse date time: %s\n", buf);
  3078. system(buf);
  3079. system("/sbin/hwclock -w --systohc");
  3080. if(result.scanedElement < 6)
  3081. result.result = FAIL;
  3082. return result.result;
  3083. }
  3084. //==========================================
  3085. // GetCompositeSchedule logic related function
  3086. //==========================================
  3087. int DiffTimebSec(struct timeb ST, struct timeb ET)
  3088. {
  3089. //return milli-second
  3090. unsigned int StartTime,StopTime;
  3091. StartTime=(unsigned int)ST.time;
  3092. StopTime=(unsigned int)ET.time;
  3093. return (StopTime-StartTime);
  3094. }
  3095. int DiffTimebWithNowSec(struct timeb ST)
  3096. {
  3097. //return milli-second
  3098. struct timeb ET;
  3099. unsigned int StartTime,StopTime;
  3100. ftime(&ET);
  3101. StartTime=(unsigned int)ST.time;
  3102. StopTime=(unsigned int)ET.time;
  3103. return (StopTime-StartTime);
  3104. }
  3105. int getStartStop(uint8_t *start, uint8_t *stop)
  3106. {
  3107. struct ParsingResult
  3108. {
  3109. int result;
  3110. int scanedElement;
  3111. int year;
  3112. int month;
  3113. int mday;
  3114. int hour;
  3115. int min;
  3116. int sec;
  3117. int tz_hour;
  3118. int tz_min;
  3119. float minSec;
  3120. };
  3121. struct ParsingResult parseStart;
  3122. struct ParsingResult parseStop;
  3123. int result = -1;
  3124. struct tm tmStart;
  3125. struct timeb tbStart;
  3126. struct tm tmStop;
  3127. struct timeb tbStop;
  3128. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3129. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3130. // Scan start & stop date time
  3131. if(strstr((char*)start, ".") != NULL)
  3132. {
  3133. // Original data with mini second
  3134. if(strstr((char*)start, "Z") != NULL)
  3135. {
  3136. // Original data with Z
  3137. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3138. &parseStart.year,
  3139. &parseStart.month,
  3140. &parseStart.mday,
  3141. &parseStart.hour,
  3142. &parseStart.min,
  3143. &parseStart.sec,
  3144. &parseStart.minSec);
  3145. }
  3146. else
  3147. {
  3148. // Original data without Z
  3149. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3150. &parseStart.year,
  3151. &parseStart.month,
  3152. &parseStart.mday,
  3153. &parseStart.hour,
  3154. &parseStart.min,
  3155. &parseStart.sec,
  3156. &parseStart.minSec,
  3157. &parseStart.tz_hour,
  3158. &parseStart.tz_min);
  3159. }
  3160. }
  3161. else
  3162. {
  3163. // Original data without mini second
  3164. if(strstr((char*)start, "Z") != NULL)
  3165. {
  3166. // Original data with Z
  3167. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3168. &parseStart.year,
  3169. &parseStart.month,
  3170. &parseStart.mday,
  3171. &parseStart.hour,
  3172. &parseStart.min,
  3173. &parseStart.sec);
  3174. }
  3175. else
  3176. {
  3177. // Original data without Z
  3178. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3179. &parseStart.year,
  3180. &parseStart.month,
  3181. &parseStart.mday,
  3182. &parseStart.hour,
  3183. &parseStart.min,
  3184. &parseStart.sec,
  3185. &parseStart.tz_hour,
  3186. &parseStart.tz_min);
  3187. }
  3188. }
  3189. if(strstr((char*)stop, ".") != NULL)
  3190. {
  3191. // Original data with mini second
  3192. if(strstr((char*)stop, "Z") != NULL)
  3193. {
  3194. // Original data with Z
  3195. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3196. &parseStop.year,
  3197. &parseStop.month,
  3198. &parseStop.mday,
  3199. &parseStop.hour,
  3200. &parseStop.min,
  3201. &parseStop.sec,
  3202. &parseStop.minSec);
  3203. }
  3204. else
  3205. {
  3206. // Original data without Z
  3207. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3208. &parseStop.year,
  3209. &parseStop.month,
  3210. &parseStop.mday,
  3211. &parseStop.hour,
  3212. &parseStop.min,
  3213. &parseStop.sec,
  3214. &parseStop.minSec,
  3215. &parseStop.tz_hour,
  3216. &parseStop.tz_min);
  3217. }
  3218. }
  3219. else
  3220. {
  3221. // Original data without mini second
  3222. if(strstr((char*)stop, "Z") != NULL)
  3223. {
  3224. // Original data with Z
  3225. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3226. &parseStop.year,
  3227. &parseStop.month,
  3228. &parseStop.mday,
  3229. &parseStop.hour,
  3230. &parseStop.min,
  3231. &parseStop.sec);
  3232. }
  3233. else
  3234. {
  3235. // Original data without Z
  3236. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3237. &parseStop.year,
  3238. &parseStop.month,
  3239. &parseStop.mday,
  3240. &parseStop.hour,
  3241. &parseStop.min,
  3242. &parseStop.sec,
  3243. &parseStop.tz_hour,
  3244. &parseStop.tz_min);
  3245. }
  3246. }
  3247. // Calculate date time difference
  3248. if((parseStart.scanedElement >=6) &&
  3249. (parseStop.scanedElement >=6))
  3250. {
  3251. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  3252. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  3253. tmStart.tm_year = parseStart.year - 1900;
  3254. tmStart.tm_mon = parseStart.month - 1;
  3255. tmStart.tm_mday = parseStart.mday;
  3256. tmStart.tm_hour = parseStart.hour;
  3257. tmStart.tm_min = parseStart.min;
  3258. tmStart.tm_sec = parseStart.sec;
  3259. tmStart.tm_gmtoff = 0;
  3260. tbStart.time = mktime(&tmStart);
  3261. tbStart.timezone = 0;
  3262. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3263. tmStop.tm_year = parseStop.year - 1900;
  3264. tmStop.tm_mon = parseStop.month - 1;
  3265. tmStop.tm_mday = parseStop.mday;
  3266. tmStop.tm_hour = parseStop.hour;
  3267. tmStop.tm_min = parseStop.min;
  3268. tmStop.tm_sec = parseStop.sec;
  3269. tmStop.tm_gmtoff = 0;
  3270. tbStop.time = mktime(&tmStop);
  3271. tbStop.timezone = 0;
  3272. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3273. result = DiffTimebSec(tbStart, tbStop);
  3274. //DEBUG_INFO("getStartStop(): %d\n", result);
  3275. }
  3276. else
  3277. {
  3278. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3279. }
  3280. return result;
  3281. }
  3282. int isOvertNow(uint8_t *start)
  3283. {
  3284. int result = NO;
  3285. struct ParsingResult
  3286. {
  3287. int result;
  3288. int scanedElement;
  3289. int year;
  3290. int month;
  3291. int mday;
  3292. int hour;
  3293. int min;
  3294. int sec;
  3295. int tz_hour;
  3296. int tz_min;
  3297. float minSec;
  3298. }parsingResult;
  3299. struct tm tmStart;
  3300. struct timeb tbStart;
  3301. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3302. if(strstr((char*)start, ".") != NULL)
  3303. {
  3304. // Original data with mini second
  3305. if(strstr((char*)start, "Z") != NULL)
  3306. {
  3307. // Original data with Z
  3308. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3309. &parsingResult.year,
  3310. &parsingResult.month,
  3311. &parsingResult.mday,
  3312. &parsingResult.hour,
  3313. &parsingResult.min,
  3314. &parsingResult.sec,
  3315. &parsingResult.minSec);
  3316. }
  3317. else
  3318. {
  3319. // Original data without Z
  3320. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3321. &parsingResult.year,
  3322. &parsingResult.month,
  3323. &parsingResult.mday,
  3324. &parsingResult.hour,
  3325. &parsingResult.min,
  3326. &parsingResult.sec,
  3327. &parsingResult.minSec,
  3328. &parsingResult.tz_hour,
  3329. &parsingResult.tz_min);
  3330. }
  3331. }
  3332. else
  3333. {
  3334. // Original data without mini second
  3335. if(strstr((char*)start, "Z") != NULL)
  3336. {
  3337. // Original data with Z
  3338. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3339. &parsingResult.year,
  3340. &parsingResult.month,
  3341. &parsingResult.mday,
  3342. &parsingResult.hour,
  3343. &parsingResult.min,
  3344. &parsingResult.sec);
  3345. }
  3346. else
  3347. {
  3348. // Original data without Z
  3349. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3350. &parsingResult.year,
  3351. &parsingResult.month,
  3352. &parsingResult.mday,
  3353. &parsingResult.hour,
  3354. &parsingResult.min,
  3355. &parsingResult.sec,
  3356. &parsingResult.tz_hour,
  3357. &parsingResult.tz_min);
  3358. }
  3359. }
  3360. if(parsingResult.scanedElement >= 6)
  3361. {
  3362. tmStart.tm_year = parsingResult.year - 1900;
  3363. tmStart.tm_mon = parsingResult.month - 1;
  3364. tmStart.tm_mday = parsingResult.mday;
  3365. tmStart.tm_hour = parsingResult.hour;
  3366. tmStart.tm_min = parsingResult.min;
  3367. tmStart.tm_sec = parsingResult.sec;
  3368. tmStart.tm_gmtoff = 0;
  3369. tbStart.time = mktime(&tmStart);
  3370. tbStart.timezone = 0;
  3371. tbStart.millitm = 0;
  3372. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3373. if(DiffTimebWithNowSec(tbStart) <= 0)
  3374. result = NO;
  3375. else
  3376. result = YES;
  3377. }
  3378. else
  3379. {
  3380. DEBUG_WARN("Start date parsing error.\n");
  3381. }
  3382. return result;
  3383. }
  3384. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3385. {
  3386. struct ParsingResult
  3387. {
  3388. int result;
  3389. int scanedElement;
  3390. int year;
  3391. int month;
  3392. int mday;
  3393. int hour;
  3394. int min;
  3395. int sec;
  3396. int tz_hour;
  3397. int tz_min;
  3398. float minSec;
  3399. };
  3400. struct ParsingResult parseStart;
  3401. struct ParsingResult parseStop;
  3402. int result = -1;
  3403. struct tm tmStart;
  3404. struct timeb tbStart;
  3405. struct tm tmStop;
  3406. struct timeb tbStop;
  3407. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3408. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3409. // Scan start & stop date time
  3410. if(strstr((char*)start, ".") != NULL)
  3411. {
  3412. // Original data with mini second
  3413. if(strstr((char*)start, "Z") != NULL)
  3414. {
  3415. // Original data with Z
  3416. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3417. &parseStart.year,
  3418. &parseStart.month,
  3419. &parseStart.mday,
  3420. &parseStart.hour,
  3421. &parseStart.min,
  3422. &parseStart.sec,
  3423. &parseStart.minSec);
  3424. }
  3425. else
  3426. {
  3427. // Original data without Z
  3428. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3429. &parseStart.year,
  3430. &parseStart.month,
  3431. &parseStart.mday,
  3432. &parseStart.hour,
  3433. &parseStart.min,
  3434. &parseStart.sec,
  3435. &parseStart.minSec,
  3436. &parseStart.tz_hour,
  3437. &parseStart.tz_min);
  3438. }
  3439. }
  3440. else
  3441. {
  3442. // Original data without mini second
  3443. if(strstr((char*)start, "Z") != NULL)
  3444. {
  3445. // Original data with Z
  3446. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3447. &parseStart.year,
  3448. &parseStart.month,
  3449. &parseStart.mday,
  3450. &parseStart.hour,
  3451. &parseStart.min,
  3452. &parseStart.sec);
  3453. }
  3454. else
  3455. {
  3456. // Original data without Z
  3457. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3458. &parseStart.year,
  3459. &parseStart.month,
  3460. &parseStart.mday,
  3461. &parseStart.hour,
  3462. &parseStart.min,
  3463. &parseStart.sec,
  3464. &parseStart.tz_hour,
  3465. &parseStart.tz_min);
  3466. }
  3467. }
  3468. if(strstr((char*)stop, ".") != NULL)
  3469. {
  3470. // Original data with mini second
  3471. if(strstr((char*)stop, "Z") != NULL)
  3472. {
  3473. // Original data with Z
  3474. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3475. &parseStop.year,
  3476. &parseStop.month,
  3477. &parseStop.mday,
  3478. &parseStop.hour,
  3479. &parseStop.min,
  3480. &parseStop.sec,
  3481. &parseStop.minSec);
  3482. }
  3483. else
  3484. {
  3485. // Original data without Z
  3486. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3487. &parseStop.year,
  3488. &parseStop.month,
  3489. &parseStop.mday,
  3490. &parseStop.hour,
  3491. &parseStop.min,
  3492. &parseStop.sec,
  3493. &parseStop.minSec,
  3494. &parseStop.tz_hour,
  3495. &parseStop.tz_min);
  3496. }
  3497. }
  3498. else
  3499. {
  3500. // Original data without mini second
  3501. if(strstr((char*)stop, "Z") != NULL)
  3502. {
  3503. // Original data with Z
  3504. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3505. &parseStop.year,
  3506. &parseStop.month,
  3507. &parseStop.mday,
  3508. &parseStop.hour,
  3509. &parseStop.min,
  3510. &parseStop.sec);
  3511. }
  3512. else
  3513. {
  3514. // Original data without Z
  3515. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3516. &parseStop.year,
  3517. &parseStop.month,
  3518. &parseStop.mday,
  3519. &parseStop.hour,
  3520. &parseStop.min,
  3521. &parseStop.sec,
  3522. &parseStop.tz_hour,
  3523. &parseStop.tz_min);
  3524. }
  3525. }
  3526. // Calculate date time difference
  3527. if((parseStart.scanedElement >=6) &&
  3528. (parseStop.scanedElement >=6))
  3529. {
  3530. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  3531. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  3532. tmStart.tm_year = parseStart.year - 1900;
  3533. tmStart.tm_mon = parseStart.month - 1;
  3534. tmStart.tm_mday = parseStart.mday;
  3535. tmStart.tm_hour = parseStart.hour;
  3536. tmStart.tm_min = parseStart.min;
  3537. tmStart.tm_sec = parseStart.sec;
  3538. tmStart.tm_gmtoff = 0;
  3539. tbStart.time = mktime(&tmStart);
  3540. tbStart.timezone = 0;
  3541. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3542. tmStop.tm_year = parseStop.year - 1900;
  3543. tmStop.tm_mon = parseStop.month - 1;
  3544. tmStop.tm_mday = parseStop.mday;
  3545. tmStop.tm_hour = parseStop.hour;
  3546. tmStop.tm_min = parseStop.min;
  3547. tmStop.tm_sec = parseStop.sec;
  3548. tmStop.tm_gmtoff = 0;
  3549. tbStop.time = mktime(&tmStop);
  3550. tbStop.timezone = 0;
  3551. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3552. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  3553. //DEBUG_INFO("getStartStop(): %d\n", result);
  3554. }
  3555. else
  3556. {
  3557. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3558. }
  3559. return result;
  3560. }
  3561. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3562. {
  3563. FILE *fp;
  3564. char profileFileName[128];
  3565. char *line = NULL;
  3566. size_t len = 0;
  3567. time_t CurrentTime;
  3568. struct tm *tmComposite;
  3569. struct ChargingProfileType maxProfile;
  3570. struct ChargingProfileType compositeProfile;
  3571. uint8_t limitMax=0;
  3572. int compositePeriodIdx = 0;
  3573. CurrentTime = time(NULL);
  3574. tmComposite=localtime(&CurrentTime);
  3575. 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);
  3576. if(isUnitA)
  3577. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3578. else
  3579. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3580. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  3581. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3582. {
  3583. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3584. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3585. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3586. }
  3587. compositeProfile.id = 0;
  3588. compositeProfile.stackLevel = 99 ;
  3589. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  3590. maxProfile.id = -1;
  3591. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3592. system("rm -f /tmp/*.json");
  3593. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3594. // Search max profile
  3595. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  3596. if((access(profileFileName, F_OK))!=-1)
  3597. {
  3598. fp = fopen(profileFileName, "r");
  3599. while(getline(&line, &len, fp) != -1)
  3600. {
  3601. json_object *obj = NULL;
  3602. obj = json_tokener_parse(line);
  3603. if(is_error(obj))
  3604. {
  3605. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3606. }
  3607. else
  3608. {
  3609. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  3610. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  3611. )
  3612. {
  3613. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3614. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3615. )
  3616. {
  3617. struct tm tmFrom, tmTo;
  3618. struct timeb tbFrom, tbTo;
  3619. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  3620. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  3621. {
  3622. tmFrom.tm_year -= 1900;
  3623. tmFrom.tm_mon -= 1;
  3624. tbFrom.time = mktime(&tmFrom);
  3625. tmTo.tm_year -= 1900;
  3626. tmTo.tm_mon -= 1;
  3627. tbTo.time = mktime(&tmTo);
  3628. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3629. {
  3630. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3631. {
  3632. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3633. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3634. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3635. }
  3636. if(maxProfile.id == -1)
  3637. DEBUG_INFO("MaxProfile found.\n");
  3638. else
  3639. DEBUG_INFO("MaxProfile updated.\n");
  3640. // Required item
  3641. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3642. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3643. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3644. if(isUnitA)
  3645. {
  3646. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3647. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  3648. {
  3649. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3650. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0 ), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3651. 3:
  3652. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3653. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3654. }
  3655. }
  3656. else
  3657. {
  3658. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3659. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  3660. {
  3661. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3662. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3663. 3:
  3664. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3665. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3666. }
  3667. }
  3668. // Optional item
  3669. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3670. {
  3671. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3672. }
  3673. else
  3674. {
  3675. sprintf((char*)maxProfile.validFrom, " ");
  3676. }
  3677. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3678. {
  3679. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3680. }
  3681. else
  3682. {
  3683. sprintf((char*)maxProfile.validTo, " ");
  3684. }
  3685. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3686. {
  3687. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3688. }
  3689. else
  3690. {
  3691. sprintf((char*)maxProfile.recurrencyKind, " ");
  3692. }
  3693. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3694. {
  3695. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3696. }
  3697. else
  3698. {
  3699. sprintf((char*)maxProfile.transactionId, " ");
  3700. }
  3701. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  3702. {
  3703. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  3704. }
  3705. else
  3706. {
  3707. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3708. }
  3709. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  3710. {
  3711. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  3712. }
  3713. else
  3714. {
  3715. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3716. }
  3717. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  3718. {
  3719. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  3720. }
  3721. else
  3722. {
  3723. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3724. }
  3725. }
  3726. }
  3727. }
  3728. else
  3729. {
  3730. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3731. {
  3732. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3733. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3734. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3735. }
  3736. if(maxProfile.id == -1)
  3737. DEBUG_INFO("MaxProfile found.\n");
  3738. else
  3739. DEBUG_INFO("MaxProfile updated.\n");
  3740. // Required item
  3741. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3742. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3743. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3744. if(isUnitA)
  3745. {
  3746. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3747. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  3748. {
  3749. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3750. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3751. 3:
  3752. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3753. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3754. }
  3755. }
  3756. else
  3757. {
  3758. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3759. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  3760. {
  3761. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3762. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3763. 3:
  3764. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3765. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3766. }
  3767. }
  3768. // Optional item
  3769. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3770. {
  3771. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3772. }
  3773. else
  3774. {
  3775. sprintf((char*)maxProfile.validFrom, " ");
  3776. }
  3777. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3778. {
  3779. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3780. }
  3781. else
  3782. {
  3783. sprintf((char*)maxProfile.validTo, " ");
  3784. }
  3785. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3786. {
  3787. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3788. }
  3789. else
  3790. {
  3791. sprintf((char*)maxProfile.recurrencyKind, " ");
  3792. }
  3793. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3794. {
  3795. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3796. }
  3797. else
  3798. {
  3799. sprintf((char*)maxProfile.transactionId, " ");
  3800. }
  3801. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  3802. {
  3803. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  3804. }
  3805. else
  3806. {
  3807. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3808. }
  3809. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  3810. {
  3811. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  3812. }
  3813. else
  3814. {
  3815. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3816. }
  3817. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  3818. {
  3819. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  3820. }
  3821. else
  3822. {
  3823. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3824. }
  3825. }
  3826. }
  3827. }
  3828. json_object_put(obj);
  3829. }
  3830. fclose(fp);
  3831. /*
  3832. if(maxProfile.id !=-1)
  3833. {
  3834. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3835. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3836. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3837. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3838. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3839. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3840. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3841. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3842. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3843. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3844. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3845. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3846. {
  3847. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3848. {
  3849. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3850. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3851. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3852. }
  3853. }
  3854. }
  3855. else
  3856. DEBUG_INFO("MaxProfile not found.\n");
  3857. DEBUG_INFO("------------------------------------\n");*/
  3858. }
  3859. if(maxProfile.id != -1)
  3860. {
  3861. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3862. {
  3863. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3864. {
  3865. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  3866. 0:
  3867. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  3868. }
  3869. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3870. {
  3871. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3872. {
  3873. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  3874. 0:
  3875. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  3876. if(idxPeriod > 0)
  3877. {
  3878. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3879. {
  3880. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3881. }
  3882. }
  3883. }
  3884. }
  3885. }
  3886. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3887. {
  3888. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3889. {
  3890. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  3891. }
  3892. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3893. {
  3894. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3895. {
  3896. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  3897. if(idxPeriod > 0)
  3898. {
  3899. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3900. {
  3901. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3902. }
  3903. }
  3904. }
  3905. }
  3906. }
  3907. else
  3908. {
  3909. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3910. {
  3911. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3912. {
  3913. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3914. 0:
  3915. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3916. }
  3917. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3918. {
  3919. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3920. {
  3921. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3922. 0:
  3923. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3924. if(idxPeriod > 0)
  3925. {
  3926. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3927. {
  3928. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3929. }
  3930. }
  3931. }
  3932. }
  3933. }
  3934. else
  3935. {
  3936. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3937. {
  3938. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3939. 0:
  3940. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3941. }
  3942. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3943. {
  3944. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3945. {
  3946. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3947. 0:
  3948. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3949. if(idxPeriod > 0)
  3950. {
  3951. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3952. {
  3953. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3954. }
  3955. }
  3956. }
  3957. }
  3958. }
  3959. }
  3960. /*
  3961. DEBUG_INFO("MaxProfile after align.\n");
  3962. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3963. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3964. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3965. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3966. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3967. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3968. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3969. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3970. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3971. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3972. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3973. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3974. {
  3975. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3976. {
  3977. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3978. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3979. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3980. }
  3981. }
  3982. DEBUG_INFO("------------------------------------\n");*/
  3983. }
  3984. // Find each profile period quantity
  3985. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  3986. {
  3987. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  3988. limitMax = idx+1;
  3989. }
  3990. if(maxProfile.id != -1)
  3991. {
  3992. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3993. {
  3994. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  3995. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  3996. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  3997. {
  3998. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3999. {
  4000. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4001. compositePeriodIdx++;
  4002. }
  4003. else
  4004. {
  4005. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4006. }
  4007. }
  4008. }
  4009. }
  4010. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  4011. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4012. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  4013. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  4014. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4015. {
  4016. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4017. {
  4018. compositeProfile.id = 1;
  4019. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4020. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4021. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4022. }
  4023. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4024. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4025. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4026. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4027. }
  4028. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4029. if(line)
  4030. free(line);
  4031. }
  4032. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4033. {
  4034. FILE *fp;
  4035. char profileFileName[128];
  4036. char *line = NULL;
  4037. size_t len = 0;
  4038. time_t CurrentTime;
  4039. struct tm *tmComposite;
  4040. struct ChargingProfileType maxProfile;
  4041. struct ChargingProfileType defaultTxProfile;
  4042. struct ChargingProfileType txProfile;
  4043. struct ChargingProfileType compositeProfile;
  4044. struct ChargingSchedulePeriodType tmpPeriod;
  4045. uint8_t limitMax=0;
  4046. uint8_t limitDef=0;
  4047. uint8_t limitTx=0;
  4048. int compositePeriodIdx = 0;
  4049. CurrentTime = time(NULL);
  4050. tmComposite=localtime(&CurrentTime);
  4051. 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);
  4052. if(isUnitA)
  4053. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4054. else
  4055. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4056. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4058. {
  4059. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4060. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4061. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4062. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  4063. }
  4064. compositeProfile.id = 0;
  4065. compositeProfile.stackLevel = 99 ;
  4066. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  4067. maxProfile.id = -1;
  4068. defaultTxProfile.id = -1;
  4069. txProfile.id = -1;
  4070. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4071. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  4072. txProfile.chargingSchedule[idxSchedule].duration = -1;
  4073. system("rm -f /tmp/*.json");
  4074. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4075. /*
  4076. * Search valid charging profile
  4077. */
  4078. //DEBUG_INFO("====================================\n");
  4079. // Search tx profile
  4080. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", connectorId);
  4081. if((access(profileFileName, F_OK))!=-1)
  4082. {
  4083. fp = fopen(profileFileName, "r");
  4084. while(getline(&line, &len, fp) != -1)
  4085. {
  4086. json_object *obj = NULL;
  4087. obj = json_tokener_parse(line);
  4088. if(is_error(obj))
  4089. {
  4090. DEBUG_ERROR("Parse txProfile from file error.\n");
  4091. }
  4092. else
  4093. {
  4094. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  4095. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  4096. )
  4097. {
  4098. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4099. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4100. )
  4101. {
  4102. struct tm tmFrom, tmTo;
  4103. struct timeb tbFrom, tbTo;
  4104. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  4105. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  4106. {
  4107. tmFrom.tm_year -= 1900;
  4108. tmFrom.tm_mon -= 1;
  4109. tbFrom.time = mktime(&tmFrom);
  4110. tmTo.tm_year -= 1900;
  4111. tmTo.tm_mon -= 1;
  4112. tbTo.time = mktime(&tmTo);
  4113. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4114. {
  4115. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4116. {
  4117. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4118. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4119. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4120. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4121. }
  4122. if(txProfile.id == -1)
  4123. DEBUG_INFO("TxProfile found.\n");
  4124. else
  4125. DEBUG_INFO("TxProfile updated.\n");
  4126. // Required item
  4127. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4128. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4129. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4130. if(isUnitA)
  4131. {
  4132. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4133. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4134. {
  4135. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4136. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4137. 3:
  4138. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4139. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4140. }
  4141. }
  4142. else
  4143. {
  4144. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4145. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4146. {
  4147. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4148. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4149. 3:
  4150. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4151. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4152. }
  4153. }
  4154. // Optional item
  4155. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4156. {
  4157. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4158. }
  4159. else
  4160. {
  4161. sprintf((char*)txProfile.validFrom, " ");
  4162. }
  4163. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4164. {
  4165. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4166. }
  4167. else
  4168. {
  4169. sprintf((char*)txProfile.validTo, " ");
  4170. }
  4171. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4172. {
  4173. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4174. }
  4175. else
  4176. {
  4177. sprintf((char*)txProfile.recurrencyKind, " ");
  4178. }
  4179. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4180. {
  4181. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4182. }
  4183. else
  4184. {
  4185. sprintf((char*)txProfile.transactionId, " ");
  4186. }
  4187. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4188. {
  4189. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4190. }
  4191. else
  4192. {
  4193. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4194. }
  4195. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4196. {
  4197. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4198. }
  4199. else
  4200. {
  4201. 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));
  4202. }
  4203. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4204. {
  4205. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4206. }
  4207. else
  4208. {
  4209. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4210. }
  4211. }
  4212. }
  4213. }
  4214. else
  4215. {
  4216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4217. {
  4218. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4219. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4220. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4221. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4222. }
  4223. if(txProfile.id == -1)
  4224. DEBUG_INFO("TxProfile found.\n");
  4225. else
  4226. DEBUG_INFO("TxProfile updated.\n");
  4227. // Required item
  4228. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4229. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4230. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4231. if(isUnitA)
  4232. {
  4233. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4234. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4235. {
  4236. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4237. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4238. 3:
  4239. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4240. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4241. }
  4242. }
  4243. else
  4244. {
  4245. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4246. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4247. {
  4248. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4249. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4250. 3:
  4251. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4252. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4253. }
  4254. }
  4255. // Optional item
  4256. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4257. {
  4258. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4259. }
  4260. else
  4261. {
  4262. sprintf((char*)txProfile.validFrom, " ");
  4263. }
  4264. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4265. {
  4266. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4267. }
  4268. else
  4269. {
  4270. sprintf((char*)txProfile.validTo, " ");
  4271. }
  4272. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4273. {
  4274. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4275. }
  4276. else
  4277. {
  4278. sprintf((char*)txProfile.recurrencyKind, " ");
  4279. }
  4280. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4281. {
  4282. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4283. }
  4284. else
  4285. {
  4286. sprintf((char*)txProfile.transactionId, " ");
  4287. }
  4288. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4289. {
  4290. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4291. }
  4292. else
  4293. {
  4294. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4295. }
  4296. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4297. {
  4298. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4299. }
  4300. else
  4301. {
  4302. 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));
  4303. }
  4304. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4305. {
  4306. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4307. }
  4308. else
  4309. {
  4310. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4311. }
  4312. }
  4313. }
  4314. }
  4315. json_object_put(obj);
  4316. }
  4317. fclose(fp);
  4318. /*
  4319. if(txProfile.id != -1)
  4320. {
  4321. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4322. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4323. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4324. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4325. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4326. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4327. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4328. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  4329. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4330. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4331. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4332. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4333. {
  4334. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4335. {
  4336. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4337. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4338. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4339. }
  4340. }
  4341. }
  4342. else
  4343. DEBUG_INFO("TxProfile not found.\n");*/
  4344. }
  4345. // Search default tx profile
  4346. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", connectorId);
  4347. if((access(profileFileName, F_OK))==-1)
  4348. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  4349. if((access(profileFileName, F_OK))!=-1)
  4350. {
  4351. fp = fopen(profileFileName, "r");
  4352. while(getline(&line, &len, fp) != -1)
  4353. {
  4354. json_object *obj = NULL;
  4355. obj = json_tokener_parse(line);
  4356. if(is_error(obj))
  4357. {
  4358. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  4359. }
  4360. else
  4361. {
  4362. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  4363. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  4364. )
  4365. {
  4366. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4367. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4368. )
  4369. {
  4370. struct tm tmFrom, tmTo;
  4371. struct timeb tbFrom, tbTo;
  4372. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  4373. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  4374. {
  4375. tmFrom.tm_year -= 1900;
  4376. tmFrom.tm_mon -= 1;
  4377. tbFrom.time = mktime(&tmFrom);
  4378. tmTo.tm_year -= 1900;
  4379. tmTo.tm_mon -= 1;
  4380. tbTo.time = mktime(&tmTo);
  4381. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4382. {
  4383. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4384. {
  4385. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4386. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4387. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4388. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4389. }
  4390. if(defaultTxProfile.id == -1)
  4391. DEBUG_INFO("TxDefaultProfile found.\n");
  4392. else
  4393. DEBUG_INFO("TxDefaultProfile updated.\n");
  4394. // Required item
  4395. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4396. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4397. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4398. if(isUnitA)
  4399. {
  4400. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4401. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4402. {
  4403. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4404. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4405. 3:
  4406. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4407. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4408. }
  4409. }
  4410. else
  4411. {
  4412. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4413. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4414. {
  4415. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4416. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4417. 3:
  4418. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4419. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4420. }
  4421. }
  4422. // Optional item
  4423. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4424. {
  4425. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4426. }
  4427. else
  4428. {
  4429. sprintf((char*)defaultTxProfile.validFrom, " ");
  4430. }
  4431. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4432. {
  4433. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4434. }
  4435. else
  4436. {
  4437. sprintf((char*)defaultTxProfile.validTo, " ");
  4438. }
  4439. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4440. {
  4441. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4442. }
  4443. else
  4444. {
  4445. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4446. }
  4447. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4448. {
  4449. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4450. }
  4451. else
  4452. {
  4453. sprintf((char*)defaultTxProfile.transactionId, " ");
  4454. }
  4455. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4456. {
  4457. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4458. }
  4459. else
  4460. {
  4461. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4462. }
  4463. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4464. {
  4465. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4466. }
  4467. else
  4468. {
  4469. 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));
  4470. }
  4471. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4472. {
  4473. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4474. }
  4475. else
  4476. {
  4477. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4478. }
  4479. }
  4480. }
  4481. }
  4482. else
  4483. {
  4484. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4485. {
  4486. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4487. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4488. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4489. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4490. }
  4491. if(defaultTxProfile.id == -1)
  4492. DEBUG_INFO("TxDefaultProfile found.\n");
  4493. else
  4494. DEBUG_INFO("TxDefaultProfile updated.\n");
  4495. // Required item
  4496. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4497. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4498. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4499. if(isUnitA)
  4500. {
  4501. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4502. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4503. {
  4504. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4505. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4506. 3:
  4507. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4508. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4509. }
  4510. }
  4511. else
  4512. {
  4513. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4514. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4515. {
  4516. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4517. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4518. 3:
  4519. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4520. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4521. }
  4522. }
  4523. // Optional item
  4524. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4525. {
  4526. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4527. }
  4528. else
  4529. {
  4530. sprintf((char*)defaultTxProfile.validFrom, " ");
  4531. }
  4532. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4533. {
  4534. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4535. }
  4536. else
  4537. {
  4538. sprintf((char*)defaultTxProfile.validTo, " ");
  4539. }
  4540. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4541. {
  4542. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4543. }
  4544. else
  4545. {
  4546. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4547. }
  4548. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4549. {
  4550. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4551. }
  4552. else
  4553. {
  4554. sprintf((char*)defaultTxProfile.transactionId, " ");
  4555. }
  4556. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4557. {
  4558. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4559. }
  4560. else
  4561. {
  4562. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4563. }
  4564. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4565. {
  4566. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4567. }
  4568. else
  4569. {
  4570. 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));
  4571. }
  4572. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4573. {
  4574. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4575. }
  4576. else
  4577. {
  4578. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4579. }
  4580. }
  4581. }
  4582. }
  4583. json_object_put(obj);
  4584. }
  4585. fclose(fp);
  4586. /*
  4587. if(defaultTxProfile.id != -1)
  4588. {
  4589. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  4590. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  4591. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  4592. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  4593. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  4594. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  4595. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  4596. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4597. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  4598. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4599. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4600. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4601. {
  4602. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4603. {
  4604. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4605. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4606. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4607. }
  4608. }
  4609. }
  4610. else
  4611. DEBUG_INFO("TxDefaultProfile not found.\n");
  4612. DEBUG_INFO("------------------------------------\n");*/
  4613. }
  4614. // Search max profile
  4615. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4616. if((access(profileFileName, F_OK))!=-1)
  4617. {
  4618. fp = fopen(profileFileName, "r");
  4619. while(getline(&line, &len, fp) != -1)
  4620. {
  4621. json_object *obj = NULL;
  4622. obj = json_tokener_parse(line);
  4623. if(is_error(obj))
  4624. {
  4625. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4626. }
  4627. else
  4628. {
  4629. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4630. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4631. )
  4632. {
  4633. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4634. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4635. )
  4636. {
  4637. struct tm tmFrom, tmTo;
  4638. struct timeb tbFrom, tbTo;
  4639. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  4640. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  4641. {
  4642. tmFrom.tm_year -= 1900;
  4643. tmFrom.tm_mon -= 1;
  4644. tbFrom.time = mktime(&tmFrom);
  4645. tmTo.tm_year -= 1900;
  4646. tmTo.tm_mon -= 1;
  4647. tbTo.time = mktime(&tmTo);
  4648. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4649. {
  4650. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4651. {
  4652. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4653. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4654. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4655. }
  4656. if(maxProfile.id == -1)
  4657. DEBUG_INFO("MaxProfile found.\n");
  4658. else
  4659. DEBUG_INFO("MaxProfile updated.\n");
  4660. // Required item
  4661. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4662. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4663. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4664. if(isUnitA)
  4665. {
  4666. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4667. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4668. {
  4669. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4670. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4671. 3:
  4672. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4673. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4674. }
  4675. }
  4676. else
  4677. {
  4678. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4679. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4680. {
  4681. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4682. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4683. 3:
  4684. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4685. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4686. }
  4687. }
  4688. // Optional item
  4689. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4690. {
  4691. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4692. }
  4693. else
  4694. {
  4695. sprintf((char*)maxProfile.validFrom, " ");
  4696. }
  4697. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4698. {
  4699. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4700. }
  4701. else
  4702. {
  4703. sprintf((char*)maxProfile.validTo, " ");
  4704. }
  4705. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4706. {
  4707. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4708. }
  4709. else
  4710. {
  4711. sprintf((char*)maxProfile.recurrencyKind, " ");
  4712. }
  4713. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4714. {
  4715. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4716. }
  4717. else
  4718. {
  4719. sprintf((char*)maxProfile.transactionId, " ");
  4720. }
  4721. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4722. {
  4723. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4724. }
  4725. else
  4726. {
  4727. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4728. }
  4729. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4730. {
  4731. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4732. }
  4733. else
  4734. {
  4735. 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));
  4736. }
  4737. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4738. {
  4739. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4740. }
  4741. else
  4742. {
  4743. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4744. }
  4745. }
  4746. }
  4747. }
  4748. else
  4749. {
  4750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4751. {
  4752. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4753. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4754. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4755. }
  4756. if(maxProfile.id == -1)
  4757. DEBUG_INFO("MaxProfile found.\n");
  4758. else
  4759. DEBUG_INFO("MaxProfile updated.\n");
  4760. // Required item
  4761. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4762. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4763. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4764. if(isUnitA)
  4765. {
  4766. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4767. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4768. {
  4769. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4770. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4771. 3:
  4772. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4773. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4774. }
  4775. }
  4776. else
  4777. {
  4778. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4779. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"));idxPeriod++)
  4780. {
  4781. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4782. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4783. 3:
  4784. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4785. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4786. }
  4787. }
  4788. // Optional item
  4789. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4790. {
  4791. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4792. }
  4793. else
  4794. {
  4795. sprintf((char*)maxProfile.validFrom, " ");
  4796. }
  4797. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4798. {
  4799. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4800. }
  4801. else
  4802. {
  4803. sprintf((char*)maxProfile.validTo, " ");
  4804. }
  4805. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4806. {
  4807. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4808. }
  4809. else
  4810. {
  4811. sprintf((char*)maxProfile.recurrencyKind, " ");
  4812. }
  4813. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4814. {
  4815. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4816. }
  4817. else
  4818. {
  4819. sprintf((char*)maxProfile.transactionId, " ");
  4820. }
  4821. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4822. {
  4823. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration"));
  4824. }
  4825. else
  4826. {
  4827. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4828. }
  4829. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4830. {
  4831. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule")));
  4832. }
  4833. else
  4834. {
  4835. 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));
  4836. }
  4837. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4838. {
  4839. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate"));
  4840. }
  4841. else
  4842. {
  4843. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4844. }
  4845. }
  4846. }
  4847. }
  4848. json_object_put(obj);
  4849. }
  4850. fclose(fp);
  4851. /*
  4852. if(maxProfile.id !=-1)
  4853. {
  4854. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4855. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4856. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4857. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4858. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4859. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4860. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4861. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4862. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4863. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4864. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4865. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4866. {
  4867. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4868. {
  4869. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4870. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4871. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4872. }
  4873. }
  4874. }
  4875. else
  4876. DEBUG_INFO("MaxProfile not found.\n");
  4877. DEBUG_INFO("------------------------------------\n");*/
  4878. }
  4879. /*
  4880. * Align found profile start schedule & periods
  4881. */
  4882. //DEBUG_INFO("====================================\n");
  4883. /*
  4884. // For local test usage, force modify found profile start schedule info
  4885. 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);
  4886. 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);
  4887. 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);
  4888. */
  4889. if(txProfile.id != -1)
  4890. {
  4891. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4892. {
  4893. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4894. {
  4895. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4896. 0:
  4897. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4898. }
  4899. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4900. {
  4901. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4902. {
  4903. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4904. 0:
  4905. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4906. if(idxPeriod > 0)
  4907. {
  4908. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4909. {
  4910. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4911. }
  4912. }
  4913. }
  4914. }
  4915. }
  4916. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4917. {
  4918. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4919. {
  4920. 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?
  4921. 0:
  4922. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4923. }
  4924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4925. {
  4926. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4927. {
  4928. 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?
  4929. 0:
  4930. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4931. if(idxPeriod > 0)
  4932. {
  4933. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4934. {
  4935. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4936. }
  4937. }
  4938. }
  4939. }
  4940. }
  4941. else
  4942. {
  4943. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4944. {
  4945. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4946. {
  4947. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4948. 0:
  4949. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4950. }
  4951. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4952. {
  4953. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4954. {
  4955. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4956. 0:
  4957. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4958. if(idxPeriod > 0)
  4959. {
  4960. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4961. {
  4962. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4963. }
  4964. }
  4965. }
  4966. }
  4967. }
  4968. else
  4969. {
  4970. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4971. {
  4972. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4973. 0:
  4974. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4975. }
  4976. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4977. {
  4978. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4979. {
  4980. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4981. 0:
  4982. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4983. if(idxPeriod > 0)
  4984. {
  4985. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4986. {
  4987. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4988. }
  4989. }
  4990. }
  4991. }
  4992. }
  4993. }
  4994. /*
  4995. DEBUG_INFO("txProfile after align.\n");
  4996. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4997. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4998. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4999. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  5000. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  5001. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  5002. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  5003. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5004. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  5005. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5006. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5007. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5008. {
  5009. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5010. {
  5011. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5012. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5013. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5014. }
  5015. }*/
  5016. }
  5017. if(defaultTxProfile.id != -1)
  5018. {
  5019. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5020. {
  5021. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5022. {
  5023. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5024. 0:
  5025. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5026. }
  5027. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5028. {
  5029. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5030. {
  5031. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5032. 0:
  5033. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5034. if(idxPeriod > 0)
  5035. {
  5036. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5037. {
  5038. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5039. }
  5040. }
  5041. }
  5042. }
  5043. }
  5044. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5045. {
  5046. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5047. {
  5048. 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?
  5049. 0:
  5050. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5051. }
  5052. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5053. {
  5054. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5055. {
  5056. 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?
  5057. 0:
  5058. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5059. if(idxPeriod > 0)
  5060. {
  5061. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5062. {
  5063. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5064. }
  5065. }
  5066. }
  5067. }
  5068. }
  5069. else
  5070. {
  5071. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5072. {
  5073. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5074. {
  5075. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5076. 0:
  5077. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5078. }
  5079. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5080. {
  5081. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5082. {
  5083. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5084. 0:
  5085. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5086. if(idxPeriod > 0)
  5087. {
  5088. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5089. {
  5090. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5091. }
  5092. }
  5093. }
  5094. }
  5095. }
  5096. else
  5097. {
  5098. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5099. {
  5100. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5101. 0:
  5102. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5103. }
  5104. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5105. {
  5106. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5107. {
  5108. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5109. 0:
  5110. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5111. if(idxPeriod > 0)
  5112. {
  5113. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5114. {
  5115. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5116. }
  5117. }
  5118. }
  5119. }
  5120. }
  5121. }
  5122. /*
  5123. DEBUG_INFO("defaultTxProfile after align.\n");
  5124. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5125. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5126. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5127. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5128. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5129. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5130. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5131. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5132. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5133. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5134. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5135. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5136. {
  5137. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5138. {
  5139. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5140. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5141. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5142. }
  5143. }
  5144. DEBUG_INFO("------------------------------------\n");*/
  5145. }
  5146. if(maxProfile.id != -1)
  5147. {
  5148. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5149. {
  5150. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5151. {
  5152. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5153. 0:
  5154. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5155. }
  5156. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5157. {
  5158. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5159. {
  5160. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5161. 0:
  5162. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5163. if(idxPeriod > 0)
  5164. {
  5165. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5166. {
  5167. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5168. }
  5169. }
  5170. }
  5171. }
  5172. }
  5173. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5174. {
  5175. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5176. {
  5177. 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?
  5178. 0:
  5179. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5180. }
  5181. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5182. {
  5183. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5184. {
  5185. 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?
  5186. 0:
  5187. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5188. if(idxPeriod > 0)
  5189. {
  5190. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5191. {
  5192. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5193. }
  5194. }
  5195. }
  5196. }
  5197. }
  5198. else
  5199. {
  5200. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5201. {
  5202. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5203. {
  5204. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5205. 0:
  5206. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5207. }
  5208. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5209. {
  5210. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5211. {
  5212. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5213. 0:
  5214. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5215. if(idxPeriod > 0)
  5216. {
  5217. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5218. {
  5219. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5220. }
  5221. }
  5222. }
  5223. }
  5224. }
  5225. else
  5226. {
  5227. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5228. {
  5229. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5230. 0:
  5231. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5232. }
  5233. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5234. {
  5235. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5236. {
  5237. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5238. 0:
  5239. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5240. if(idxPeriod > 0)
  5241. {
  5242. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5243. {
  5244. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5245. }
  5246. }
  5247. }
  5248. }
  5249. }
  5250. }
  5251. /*
  5252. DEBUG_INFO("MaxProfile after align.\n");
  5253. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5254. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5255. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5256. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5257. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5258. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5259. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5260. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5261. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5262. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5263. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5264. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5265. {
  5266. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5267. {
  5268. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5269. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5270. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5271. }
  5272. }
  5273. DEBUG_INFO("------------------------------------\n");*/
  5274. }
  5275. /*
  5276. * Merge to conposite schedule
  5277. */
  5278. //DEBUG_INFO("====================================\n");
  5279. // Find each profile period quantity
  5280. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5281. {
  5282. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5283. limitMax = idx+1;
  5284. }
  5285. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5286. {
  5287. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5288. limitDef = idx+1;
  5289. }
  5290. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5291. {
  5292. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5293. limitTx = idx+1;
  5294. }
  5295. // TxProfile found, composite schedule based on it
  5296. if(txProfile.id != -1)
  5297. {
  5298. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  5299. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  5300. {
  5301. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  5302. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  5303. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  5304. {
  5305. if(maxProfile.id != -1)
  5306. {
  5307. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5308. {
  5309. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  5310. {
  5311. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5312. {
  5313. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5314. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5315. 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);
  5316. }
  5317. else
  5318. {
  5319. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5320. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5321. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  5322. }
  5323. }
  5324. if(idxMaxPeriod == (limitMax-1))
  5325. {
  5326. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5327. {
  5328. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5329. {
  5330. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5331. compositePeriodIdx++;
  5332. }
  5333. else
  5334. {
  5335. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5336. }
  5337. }
  5338. }
  5339. }
  5340. }
  5341. else
  5342. {
  5343. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5344. {
  5345. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5346. compositePeriodIdx++;
  5347. }
  5348. else
  5349. {
  5350. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5351. }
  5352. }
  5353. }
  5354. if(idxTxPeriod == (limitTx-1))
  5355. {
  5356. if(defaultTxProfile.id != -1)
  5357. {
  5358. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  5359. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5360. {
  5361. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  5362. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5363. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  5364. {
  5365. if(maxProfile.id != -1)
  5366. {
  5367. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5368. {
  5369. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5370. {
  5371. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5372. {
  5373. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5374. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5375. 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);
  5376. }
  5377. else
  5378. {
  5379. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5380. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5381. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5382. }
  5383. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5384. {
  5385. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5386. {
  5387. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5388. compositePeriodIdx++;
  5389. }
  5390. else
  5391. {
  5392. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5393. }
  5394. }
  5395. // Delete duplicate period
  5396. if(compositePeriodIdx > 1)
  5397. {
  5398. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5399. {
  5400. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5401. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5402. compositePeriodIdx -= 1;
  5403. }
  5404. }
  5405. }
  5406. else
  5407. {
  5408. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5409. {
  5410. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5411. compositePeriodIdx++;
  5412. }
  5413. else
  5414. {
  5415. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5416. }
  5417. break;
  5418. }
  5419. }
  5420. }
  5421. else
  5422. {
  5423. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5424. {
  5425. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5426. compositePeriodIdx++;
  5427. }
  5428. else
  5429. {
  5430. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5431. }
  5432. }
  5433. }
  5434. }
  5435. }
  5436. }
  5437. }
  5438. }
  5439. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  5440. else if(defaultTxProfile.id != -1)
  5441. {
  5442. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  5443. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5444. {
  5445. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  5446. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5447. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  5448. {
  5449. if(maxProfile.id != -1)
  5450. {
  5451. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5452. {
  5453. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5454. {
  5455. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5456. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5457. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5458. {
  5459. 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);
  5460. }
  5461. else
  5462. {
  5463. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5464. }
  5465. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5466. {
  5467. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5468. {
  5469. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5470. compositePeriodIdx++;
  5471. }
  5472. else
  5473. {
  5474. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5475. }
  5476. }
  5477. // Delete duplicate period
  5478. if(compositePeriodIdx > 1)
  5479. {
  5480. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5481. {
  5482. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5483. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5484. compositePeriodIdx -= 1;
  5485. }
  5486. }
  5487. }
  5488. else
  5489. {
  5490. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5491. {
  5492. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5493. compositePeriodIdx++;
  5494. }
  5495. else
  5496. {
  5497. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5498. }
  5499. break;
  5500. }
  5501. }
  5502. }
  5503. else
  5504. {
  5505. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5506. {
  5507. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5508. compositePeriodIdx++;
  5509. }
  5510. else
  5511. {
  5512. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5513. }
  5514. }
  5515. }
  5516. }
  5517. }
  5518. // Fill other period by MaxProfile
  5519. if(maxProfile.id != -1)
  5520. {
  5521. if(compositePeriodIdx==0)
  5522. {
  5523. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  5524. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  5525. {
  5526. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5527. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5528. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5529. {
  5530. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5531. {
  5532. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5533. compositePeriodIdx++;
  5534. }
  5535. else
  5536. {
  5537. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5538. }
  5539. }
  5540. }
  5541. }
  5542. else
  5543. {
  5544. int lastCompositePeriodIdx = compositePeriodIdx;
  5545. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5546. {
  5547. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5548. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5549. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5550. {
  5551. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  5552. {
  5553. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  5554. {
  5555. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5556. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5557. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  5558. }
  5559. else
  5560. {
  5561. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5562. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5563. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  5564. }
  5565. }
  5566. if(tmpPeriod.limit != -1)
  5567. {
  5568. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  5569. {
  5570. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  5571. {
  5572. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5573. compositePeriodIdx++;
  5574. }
  5575. else
  5576. {
  5577. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5578. }
  5579. }
  5580. // Delete duplicate period
  5581. if(compositePeriodIdx > 1)
  5582. {
  5583. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5584. {
  5585. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5586. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5587. compositePeriodIdx -= 1;
  5588. }
  5589. }
  5590. }
  5591. }
  5592. }
  5593. }
  5594. }
  5595. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  5596. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  5597. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  5598. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  5599. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  5600. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5601. {
  5602. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  5603. {
  5604. compositeProfile.id = 1;
  5605. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  5606. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  5607. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  5608. }
  5609. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  5610. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  5611. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  5612. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  5613. }
  5614. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  5615. if(line)
  5616. free(line);
  5617. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  5618. }
  5619. //==========================================
  5620. // Init all share memory
  5621. //==========================================
  5622. int InitShareMemory()
  5623. {
  5624. int result = PASS;
  5625. int MeterSMId;
  5626. //creat ShmSysConfigAndInfo
  5627. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  5628. {
  5629. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  5630. result = FAIL;
  5631. }
  5632. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5633. {
  5634. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  5635. result = FAIL;
  5636. }
  5637. else
  5638. {}
  5639. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  5640. {
  5641. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  5642. result = FAIL;
  5643. }
  5644. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5645. {
  5646. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  5647. result = FAIL;
  5648. }
  5649. else
  5650. {}
  5651. //creat ShmPsuData
  5652. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  5653. {
  5654. DEBUG_ERROR("shmget ShmPsuData NG\n");
  5655. result = FAIL;
  5656. }
  5657. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5658. {
  5659. DEBUG_ERROR("shmat ShmPsuData NG\n");
  5660. result = FAIL;
  5661. }
  5662. else
  5663. {}
  5664. //creat ShmOCPP20Data
  5665. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  5666. {
  5667. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  5668. result = FAIL;
  5669. }
  5670. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5671. {
  5672. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  5673. result = FAIL;
  5674. }
  5675. else
  5676. {}
  5677. /****************************** For Initial Settings************************************************/
  5678. /*
  5679. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  5680. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  5681. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  5682. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  5683. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  5684. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  5685. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  5686. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  5687. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  5688. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  5689. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  5690. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  5691. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  5692. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  5693. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  5694. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  5695. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  5696. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  5697. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  5698. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  5699. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  5700. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  5701. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  5702. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  5703. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  5704. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  5705. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  5706. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  5707. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  5708. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  5709. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  5710. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  5711. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  5712. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  5713. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  5714. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  5715. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  5716. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  5717. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  5718. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  5719. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  5720. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  5721. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  5722. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  5723. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  5724. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  5725. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  5726. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  5727. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  5728. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  5729. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  5730. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  5731. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  5732. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  5733. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  5734. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  5735. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  5736. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  5737. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  5738. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  5739. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  5740. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  5741. */
  5742. return result;
  5743. }
  5744. int ProcessShareMemory()
  5745. {
  5746. int result = PASS;
  5747. if(InitShareMemory() == FAIL)
  5748. {
  5749. DEBUG_ERROR("InitShareMemory NG\n");
  5750. if(ShmStatusCodeData!=NULL)
  5751. {
  5752. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  5753. }
  5754. result = FAIL;
  5755. }
  5756. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  5757. {
  5758. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  5759. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  5760. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  5761. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  5762. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  5763. ) // 'D' means DC
  5764. {
  5765. // DO series
  5766. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  5767. {
  5768. gunTotalNumber += 1;
  5769. gunType[gun_index] = GUN_TYPE_DO;
  5770. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5771. {
  5772. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  5773. {
  5774. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5775. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5776. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  5777. }
  5778. }
  5779. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5780. {
  5781. case Gun_Type_Chademo:
  5782. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  5783. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  5784. {
  5785. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  5786. {
  5787. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5788. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5789. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  5790. }
  5791. }
  5792. break;
  5793. case Gun_Type_CCS_2:
  5794. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  5795. for (int index = 0; index < CCS_QUANTITY; index++)
  5796. {
  5797. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  5798. {
  5799. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5800. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5801. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  5802. }
  5803. }
  5804. break;
  5805. case Gun_Type_GB:
  5806. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  5807. for (int index = 0; index < GB_QUANTITY; index++)
  5808. {
  5809. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  5810. {
  5811. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5812. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5813. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  5814. }
  5815. }
  5816. break;
  5817. case Gun_Type_AC:
  5818. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  5819. for (int index = 0; index < AC_QUANTITY; index++)
  5820. {
  5821. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  5822. {
  5823. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5824. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5825. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  5826. }
  5827. }
  5828. break;
  5829. default:
  5830. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  5831. break;
  5832. }
  5833. }
  5834. }
  5835. else
  5836. {
  5837. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  5838. {
  5839. gunTotalNumber += 1;
  5840. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5841. {
  5842. case Gun_Type_Chademo:
  5843. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  5844. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  5845. break;
  5846. case Gun_Type_CCS_2:
  5847. gunType[gun_index] = GUN_TYPE_CCS;
  5848. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  5849. break;
  5850. case Gun_Type_GB:
  5851. gunType[gun_index] = GUN_TYPE_GBT;
  5852. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  5853. break;
  5854. case Gun_Type_AC:
  5855. gunType[gun_index] = GUN_TYPE_AC;
  5856. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  5857. break;
  5858. default:
  5859. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  5860. break;
  5861. }
  5862. }
  5863. }
  5864. }
  5865. else
  5866. {
  5867. DEBUG_ERROR("Model name parsing fail.\n");
  5868. result = FAIL;
  5869. }
  5870. if(result != PASS)sleep(5);
  5871. return result;
  5872. }
  5873. //---------------------common routine---------------------------//
  5874. void checkNetworkProfile(void)
  5875. {
  5876. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  5877. json_object *priority;
  5878. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  5879. if(!is_error(priority))
  5880. {
  5881. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  5882. {
  5883. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  5884. {
  5885. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  5886. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  5887. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  5888. {
  5889. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  5890. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  5891. break;
  5892. }
  5893. }
  5894. }
  5895. }
  5896. json_object_put(priority);
  5897. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  5898. }
  5899. void checkRemoteStart(uint8_t connectorIdx)
  5900. {
  5901. uint8_t tempIndex;
  5902. int isAllowStart = TRUE;
  5903. char cmdBuf[512];
  5904. //check Transaction active
  5905. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  5906. {
  5907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5908. {
  5909. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5910. }
  5911. else
  5912. {
  5913. tempIndex = (connectorIdx-1);
  5914. }
  5915. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5916. {
  5917. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  5918. {
  5919. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5920. {
  5921. //Reserved
  5922. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  5923. }
  5924. 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[connectorIdx-1].idToken.idToken) != 0))
  5925. {
  5926. //Reserved
  5927. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  5928. isAllowStart = FALSE;
  5929. }
  5930. else
  5931. {
  5932. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5933. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  5934. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  5935. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  5936. {
  5937. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  5938. isAllowStart = FALSE;
  5939. }
  5940. }//END FOR ELSE
  5941. }
  5942. }// END FOR CHAdeMO_QUANTITY
  5943. }
  5944. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  5945. {
  5946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5947. {
  5948. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5949. }
  5950. else
  5951. {
  5952. tempIndex = (connectorIdx-1);
  5953. }
  5954. for (int index = 0; index < CCS_QUANTITY; index++)
  5955. {
  5956. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5957. {
  5958. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5959. {
  5960. //Reserved
  5961. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  5962. }
  5963. 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[connectorIdx-1].idToken.idToken) != 0))
  5964. {
  5965. //Reserved
  5966. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  5967. isAllowStart = FALSE;
  5968. }
  5969. else
  5970. {
  5971. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5972. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5973. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5974. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5975. {
  5976. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  5977. isAllowStart = FALSE;
  5978. }
  5979. }// END FOR ELSE
  5980. }
  5981. }// END FOR CCS_QUANTITY
  5982. }
  5983. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  5984. {
  5985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5986. {
  5987. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5988. }
  5989. else
  5990. {
  5991. tempIndex = (connectorIdx-1);
  5992. }
  5993. for (int index = 0; index < GB_QUANTITY; index++)
  5994. {
  5995. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  5996. {
  5997. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5998. {
  5999. //Reserved
  6000. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  6001. }
  6002. 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[connectorIdx-1].idToken.idToken) != 0))
  6003. {
  6004. //Reserved
  6005. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  6006. isAllowStart = FALSE;
  6007. }
  6008. else
  6009. {
  6010. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6011. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6012. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6013. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6014. {
  6015. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  6016. isAllowStart = FALSE;
  6017. }
  6018. }// END FOR ELSE
  6019. }
  6020. } // END FOR GB_QUANTITY
  6021. }
  6022. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  6023. {
  6024. tempIndex = (connectorIdx-1);
  6025. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6026. {
  6027. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  6028. {
  6029. 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[connectorIdx-1].idToken.idToken) == 0))
  6030. {
  6031. //Reserved
  6032. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  6033. }
  6034. 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[connectorIdx-1].idToken.idToken) != 0))
  6035. {
  6036. //Reserved
  6037. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  6038. isAllowStart = FALSE;
  6039. }
  6040. else
  6041. {
  6042. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6043. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6044. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6045. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6046. {
  6047. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  6048. isAllowStart = FALSE;
  6049. }
  6050. }// END FOR ELSE
  6051. }
  6052. } // END FOR GB_QUANTITY
  6053. }
  6054. else
  6055. {
  6056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6057. {
  6058. tempIndex = 2;
  6059. }
  6060. else
  6061. {
  6062. tempIndex = (connectorIdx-1);
  6063. }
  6064. for (int index = 0; index < AC_QUANTITY; index++)
  6065. {
  6066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6067. {
  6068. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  6069. {
  6070. //Reserved
  6071. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  6072. }
  6073. 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[connectorIdx-1].idToken.idToken) != 0))
  6074. {
  6075. //Reserved
  6076. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  6077. isAllowStart = FALSE;
  6078. }
  6079. else
  6080. {
  6081. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6082. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6083. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6084. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6085. {
  6086. DEBUG_WARN("AC connector not allow start cause busy.\n");
  6087. isAllowStart = FALSE;
  6088. }
  6089. }//END FOR ELSE
  6090. }
  6091. }// END FOR AC_QUANTITY
  6092. }
  6093. if(isAllowStart == TRUE)
  6094. {
  6095. if(ShmOCPP20Data->RequestStartTransaction[connectorIdx -1].chargingProfile.id > 0)
  6096. {
  6097. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  6098. {
  6099. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  6100. system(cmdBuf);
  6101. }
  6102. }
  6103. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  6104. }
  6105. }
  6106. void CheckSystemValue(void)
  6107. {
  6108. char filenmae[100]={0};
  6109. char str[100]={0};
  6110. int tempIndex = 0;
  6111. //===============================
  6112. // EVSE operation check
  6113. //===============================
  6114. //===============================
  6115. // Heartbeat check
  6116. //===============================
  6117. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  6118. {
  6119. //parameter for test
  6120. sendHeartbeatRequest(0);
  6121. //==============================================
  6122. // Reset Waiting Time
  6123. //==============================================
  6124. HeartBeatWithNOResponse += 1;
  6125. }
  6126. //===============================
  6127. // CSU Trigger Authorize Request
  6128. //===============================
  6129. if(isWebsocketSendable &&
  6130. (server_sign == TRUE) &&
  6131. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6132. (authorizeRetryTimes < 3))
  6133. {
  6134. sendAuthorizeRequest(0);
  6135. authorizeRetryTimes = authorizeRetryTimes + 1;
  6136. if(authorizeRetryTimes < 3)
  6137. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6138. }
  6139. else if((server_sign == TRUE) &&
  6140. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6141. (authorizeRetryTimes >= 3))
  6142. {
  6143. authorizeRetryTimes = 0;
  6144. SetOcppConnStatus(FALSE);
  6145. server_sign = FALSE;
  6146. }
  6147. else if((server_sign == FALSE) &&
  6148. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true") == 0) &&
  6149. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  6150. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6151. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6152. {
  6153. sendAuthorizeRequest(0);
  6154. }
  6155. //===============================
  6156. // NotifyMonitoringReportRequest
  6157. //===============================
  6158. if(isWebsocketSendable &&
  6159. (server_sign == TRUE) &&
  6160. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6161. {
  6162. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  6163. {
  6164. if((strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0) ||
  6165. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0) ||
  6166. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0))
  6167. {
  6168. /*for(uint8_t idxVarMonitoring=0; idxVarMonitoring<10; idxVarMonitoring++)
  6169. {
  6170. if(strcmp((char*)ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].variableMonitoring[idxVarMonitoring].type, (char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion]))
  6171. {
  6172. strcpy(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxVarMonitoring].component, ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].
  6173. }
  6174. }*/
  6175. }
  6176. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  6177. {
  6178. /*
  6179. * TODO:
  6180. * 1. Report component that are ThresholdMonitoring
  6181. */
  6182. }
  6183. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  6184. {
  6185. /*
  6186. * TODO:
  6187. * 1. Report component that are DeltaMonitoring
  6188. */
  6189. }
  6190. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  6191. {
  6192. /*
  6193. * TODO:
  6194. * 1. Report component that are PeriodicMonitoring
  6195. */
  6196. }
  6197. else
  6198. {
  6199. /*
  6200. * TODO:
  6201. * 1. Process unknown criteria condition
  6202. */
  6203. }
  6204. }
  6205. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6206. }
  6207. if(isWebsocketSendable &&
  6208. (server_sign == TRUE) &&
  6209. (ShmOCPP20Data->GetReport.requestId > 0))
  6210. {
  6211. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6212. {
  6213. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6214. {
  6215. /*
  6216. * TODO:
  6217. * 1. Report component that are active
  6218. */
  6219. }
  6220. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6221. {
  6222. /*
  6223. * TODO:
  6224. * 1. Report component that are available
  6225. */
  6226. }
  6227. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6228. {
  6229. /*
  6230. * TODO:
  6231. * 1. Report component that are enable
  6232. */
  6233. }
  6234. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6235. {
  6236. /*
  6237. * TODO:
  6238. * 1. Report component that are problem
  6239. */
  6240. }
  6241. else
  6242. {
  6243. /*
  6244. * TODO:
  6245. * 1. Process unknown criteria condition
  6246. */
  6247. }
  6248. }
  6249. ShmOCPP20Data->GetReport.requestId = 0;
  6250. }
  6251. if(isWebsocketSendable &&
  6252. (server_sign == TRUE) &&
  6253. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6254. {
  6255. uint8_t reportIdx = 0;
  6256. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  6257. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  6258. {
  6259. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6260. {
  6261. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6262. {
  6263. 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))
  6264. {
  6265. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6266. reportIdx++;
  6267. }
  6268. }
  6269. else
  6270. {
  6271. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6272. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6273. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6274. else
  6275. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6276. sendNotifyReportRequest();
  6277. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6278. reportIdx = 0;
  6279. idx_var--;
  6280. }
  6281. }
  6282. }
  6283. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  6284. {
  6285. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6286. {
  6287. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6288. {
  6289. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6290. reportIdx++;
  6291. }
  6292. else
  6293. {
  6294. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6295. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6296. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6297. else
  6298. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6299. sendNotifyReportRequest();
  6300. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6301. reportIdx = 0;
  6302. idx_var--;
  6303. }
  6304. }
  6305. }
  6306. else
  6307. {
  6308. /*
  6309. * TODO:
  6310. * 1. Fill out summary inventory to response message, currently not support
  6311. */
  6312. }
  6313. if(reportIdx > 0)
  6314. {
  6315. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6316. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6317. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6318. else
  6319. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6320. sendNotifyReportRequest();
  6321. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6322. reportIdx = 0;
  6323. }
  6324. ShmOCPP20Data->GetBaseReport.requestId = 0;
  6325. }
  6326. if(isWebsocketSendable &&
  6327. (server_sign == TRUE) &&
  6328. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  6329. {
  6330. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  6331. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  6332. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  6333. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  6334. else
  6335. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  6336. sendNotifyEventRequest();
  6337. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  6338. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  6339. }
  6340. if(isWebsocketSendable &&
  6341. (server_sign == TRUE) &&
  6342. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  6343. {
  6344. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  6345. {
  6346. /*
  6347. * TODO:
  6348. * 1.
  6349. */
  6350. }
  6351. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  6352. {
  6353. /*
  6354. * TODO:
  6355. * 1.
  6356. */
  6357. }
  6358. else
  6359. {
  6360. /*
  6361. * TODO:
  6362. * 1.
  6363. */
  6364. }
  6365. sendGet15118EVCertificateRequest();
  6366. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  6367. }
  6368. if(isWebsocketSendable &&
  6369. (server_sign == TRUE) &&
  6370. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  6371. {
  6372. sendSecurityEventNotificationRequest();
  6373. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  6374. }
  6375. if(isWebsocketSendable &&
  6376. (server_sign == TRUE) &&
  6377. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  6378. {
  6379. sendNotifyCustomerInformationRequest();
  6380. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  6381. }
  6382. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6383. {
  6384. // ClockAlign MeterValue
  6385. 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))
  6386. {
  6387. //check Transaction active
  6388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6389. {
  6390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6391. {
  6392. tempIndex = ((gun_index==2) ? 1: 0);
  6393. }
  6394. else
  6395. {
  6396. tempIndex = gun_index;
  6397. }
  6398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6399. {
  6400. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6401. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6402. {
  6403. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6404. }
  6405. }// End for CHAdeMO
  6406. }
  6407. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6408. {
  6409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6410. {
  6411. tempIndex = ((gun_index==2) ? 1: 0);
  6412. }
  6413. else
  6414. {
  6415. tempIndex = gun_index;
  6416. }
  6417. for (int index = 0; index < CCS_QUANTITY; index++)
  6418. {
  6419. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6420. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6421. {
  6422. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6423. }
  6424. } // End for CCS
  6425. }
  6426. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6427. {
  6428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6429. {
  6430. tempIndex = ((gun_index==2) ? 1: 0);
  6431. }
  6432. else
  6433. {
  6434. tempIndex = gun_index;
  6435. }
  6436. for (int index = 0; index < GB_QUANTITY; index++)
  6437. {
  6438. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6439. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6440. {
  6441. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6442. }
  6443. }// End for GB
  6444. }
  6445. else if(gunType[gun_index] == GUN_TYPE_DO)
  6446. {
  6447. tempIndex = gun_index;
  6448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6449. {
  6450. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6451. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6452. {
  6453. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6454. }
  6455. }
  6456. }
  6457. else
  6458. {
  6459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6460. {
  6461. tempIndex = 2;
  6462. }
  6463. else
  6464. {
  6465. tempIndex = gun_index;
  6466. }
  6467. for (int index = 0; index < AC_QUANTITY; index++)
  6468. {
  6469. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6470. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6471. {
  6472. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6473. }
  6474. }//End for AC
  6475. }
  6476. }
  6477. }
  6478. //===============================
  6479. // Each connector operation check
  6480. //===============================
  6481. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  6482. {
  6483. //==========================================
  6484. // Check remote start without connector id
  6485. //==========================================
  6486. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  6487. {
  6488. int connectorIdInt = -1;
  6489. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  6490. {
  6491. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  6492. {
  6493. connectorIdInt = (gun_index+1);
  6494. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  6495. checkRemoteStart(connectorIdInt);
  6496. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  6497. break;
  6498. }
  6499. }
  6500. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  6501. {
  6502. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  6503. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  6504. }
  6505. }
  6506. //==========================================
  6507. // csu trigger DataTransferReq
  6508. //==========================================
  6509. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  6510. {
  6511. sendDataTransferRequest(gun_index);
  6512. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  6513. }
  6514. //==============================================
  6515. // Charger status notification & Transaction event report
  6516. //==============================================
  6517. //--- Check Mode Change ---//
  6518. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6519. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6520. {
  6521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6522. {
  6523. tempIndex = ((gun_index==2) ? 1: 0);
  6524. }
  6525. else
  6526. {
  6527. tempIndex = gun_index;
  6528. }
  6529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6530. {
  6531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6532. {
  6533. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  6534. {
  6535. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  6536. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  6537. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6538. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6539. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  6540. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  6541. {
  6542. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6543. }
  6544. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6545. {
  6546. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6547. if((access(filenmae,F_OK))!=-1)
  6548. {
  6549. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6550. sprintf(str,"rm -f %s",filenmae);
  6551. system(str);
  6552. }
  6553. }
  6554. }
  6555. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6556. #if 1 // for TempStopTransaction
  6557. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6558. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6559. {
  6560. checkTempStopTransaction(gun_index);
  6561. }
  6562. #endif
  6563. }
  6564. }
  6565. }
  6566. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6567. {
  6568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6569. {
  6570. tempIndex = ((gun_index==2) ? 1: 0);
  6571. }
  6572. else
  6573. {
  6574. tempIndex = gun_index;
  6575. }
  6576. for (int index = 0; index < CCS_QUANTITY; index++)
  6577. {
  6578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6579. {
  6580. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  6581. {
  6582. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  6583. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  6584. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6585. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6586. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  6587. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  6588. {
  6589. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6590. }
  6591. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6592. {
  6593. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6594. if((access(filenmae,F_OK))!=-1)
  6595. {
  6596. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6597. sprintf(str,"rm -f %s",filenmae);
  6598. system(str);
  6599. }
  6600. }
  6601. }
  6602. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6603. #if 1 // for TempStopTransaction
  6604. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6605. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6606. {
  6607. checkTempStopTransaction(gun_index);
  6608. }
  6609. #endif
  6610. }
  6611. }
  6612. }
  6613. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6614. {
  6615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6616. {
  6617. tempIndex = ((gun_index==2) ? 1: 0);
  6618. }
  6619. else
  6620. {
  6621. tempIndex = gun_index;
  6622. }
  6623. for (int index = 0; index < GB_QUANTITY; index++)
  6624. {
  6625. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6626. {
  6627. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  6628. {
  6629. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  6630. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  6631. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6632. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6633. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  6634. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  6635. {
  6636. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6637. }
  6638. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6639. {
  6640. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6641. if((access(filenmae,F_OK))!=-1)
  6642. {
  6643. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6644. sprintf(str,"rm -f %s",filenmae);
  6645. system(str);
  6646. }
  6647. }
  6648. }
  6649. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6650. #if 1 // for TempStopTransaction
  6651. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6652. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6653. {
  6654. checkTempStopTransaction(gun_index);
  6655. }
  6656. #endif
  6657. }
  6658. }
  6659. }
  6660. else if(gunType[gun_index] == GUN_TYPE_DO)
  6661. {
  6662. tempIndex = gun_index;
  6663. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6664. {
  6665. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6666. {
  6667. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  6668. {
  6669. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  6670. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  6671. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6672. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  6673. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE) &&
  6674. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != AcPreviousSystemStatus[index]))
  6675. {
  6676. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6677. }
  6678. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  6679. {
  6680. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6681. if((access(filenmae,F_OK))!=-1)
  6682. {
  6683. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6684. sprintf(str,"rm -f %s",filenmae);
  6685. system(str);
  6686. }
  6687. }
  6688. }
  6689. 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);
  6690. #if 1 // for TempStopTransaction
  6691. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  6692. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6693. {
  6694. checkTempStopTransaction(gun_index);
  6695. }
  6696. #endif
  6697. }
  6698. }
  6699. }
  6700. else
  6701. {
  6702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6703. {
  6704. tempIndex = 2;
  6705. }
  6706. else
  6707. {
  6708. tempIndex = gun_index;
  6709. }
  6710. for (int index = 0; index < AC_QUANTITY; index++)
  6711. {
  6712. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6713. {
  6714. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  6715. {
  6716. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  6717. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6718. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6719. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  6720. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  6721. {
  6722. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6723. }
  6724. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  6725. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  6726. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6727. {
  6728. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6729. if((access(filenmae,F_OK))!=-1)
  6730. {
  6731. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6732. sprintf(str,"rm -f %s",filenmae);
  6733. system(str);
  6734. }
  6735. }
  6736. }
  6737. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6738. #if 1 // for TempStopTransaction
  6739. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6740. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6741. {
  6742. checkTempStopTransaction(gun_index);
  6743. }
  6744. #endif
  6745. }
  6746. }// END
  6747. }
  6748. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  6749. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  6750. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") == 0) &&
  6751. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  6752. {
  6753. sendStatusNotificationRequest(gun_index);
  6754. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  6755. }
  6756. //==============================================
  6757. // CSU Trigger Smart Charging Profile
  6758. //==============================================
  6759. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  6760. {
  6761. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  6762. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  6763. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  6764. }
  6765. //==============================================
  6766. // CSU transaction event
  6767. //==============================================
  6768. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON || cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  6769. {
  6770. sendTransactionEventRequest(gun_index);
  6771. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  6772. cpinitateMsg.bits[gun_index].TriggerTransactionEventReq = OFF;
  6773. //storeTempStopTransaction(gun_index);
  6774. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  6775. }
  6776. //==============================================
  6777. // Meter report
  6778. //==============================================
  6779. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  6780. {
  6781. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  6782. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  6783. }
  6784. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  6785. {
  6786. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  6787. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  6788. }
  6789. // Sample period MeterValue
  6790. if(getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)>3)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1):3))
  6791. {
  6792. //check Transaction active
  6793. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6794. {
  6795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6796. {
  6797. tempIndex = ((gun_index==2) ? 1: 0);
  6798. }
  6799. else
  6800. {
  6801. tempIndex = gun_index;
  6802. }
  6803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6804. {
  6805. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6806. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6807. {
  6808. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6809. {
  6810. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6811. }
  6812. }
  6813. }// End for CHAdeMO
  6814. }
  6815. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6816. {
  6817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6818. {
  6819. tempIndex = ((gun_index==2) ? 1: 0);
  6820. }
  6821. else
  6822. {
  6823. tempIndex = gun_index;
  6824. }
  6825. for (int index = 0; index < CCS_QUANTITY; index++)
  6826. {
  6827. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6828. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6829. {
  6830. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6831. {
  6832. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6833. }
  6834. }
  6835. } // End for CCS
  6836. }
  6837. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6838. {
  6839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6840. {
  6841. tempIndex = ((gun_index==2) ? 1: 0);
  6842. }
  6843. else
  6844. {
  6845. tempIndex = gun_index;
  6846. }
  6847. for (int index = 0; index < GB_QUANTITY; index++)
  6848. {
  6849. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6850. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6851. {
  6852. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6853. {
  6854. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6855. }
  6856. }
  6857. }// End for GB
  6858. }
  6859. else if(gunType[gun_index] == GUN_TYPE_DO)
  6860. {
  6861. tempIndex = gun_index;
  6862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6863. {
  6864. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6865. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6866. {
  6867. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  6868. {
  6869. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6870. }
  6871. }
  6872. }
  6873. }
  6874. else
  6875. {
  6876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6877. {
  6878. tempIndex = 2;
  6879. }
  6880. else
  6881. {
  6882. tempIndex = gun_index;
  6883. }
  6884. for (int index = 0; index < AC_QUANTITY; index++)
  6885. {
  6886. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6887. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6888. {
  6889. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6890. {
  6891. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6892. }
  6893. }
  6894. }//End for AC
  6895. }
  6896. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  6897. {
  6898. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  6899. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  6900. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  6901. }
  6902. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6903. }
  6904. //==============================================
  6905. // Check Connector reserved
  6906. //==============================================
  6907. //===============================
  6908. // Check if Reserve is expired
  6909. //===============================
  6910. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  6911. {
  6912. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  6913. {
  6914. DEBUG_INFO("reserve expired.\n");
  6915. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  6916. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  6917. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  6918. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  6919. }
  6920. }//END OF Check if Reserve is expired
  6921. //==========================================
  6922. // csu trigger FirmwareStatusNotificationReq
  6923. //==========================================
  6924. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  6925. {
  6926. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  6927. }
  6928. //==========================================
  6929. // csu cleared charging limit request
  6930. //==========================================
  6931. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  6932. {
  6933. sendClearedChargingLimitRequest(gun_index);
  6934. }
  6935. //==========================================
  6936. // csu trigger CancelReservationConf
  6937. //==========================================
  6938. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  6939. {
  6940. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  6941. }
  6942. //==========================================
  6943. // csu notify EV charging need request
  6944. //==========================================
  6945. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  6946. {
  6947. sendNotifyEVChargingNeedsRequest(gun_index);
  6948. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  6949. }
  6950. //==========================================
  6951. // csu notify EV charging schedule request
  6952. //==========================================
  6953. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq == ON))
  6954. {
  6955. sendNotifyEVChargingScheduleRequest(gun_index);
  6956. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  6957. }
  6958. //==========================================
  6959. // csu trigger ChangeAvailabilityConf
  6960. //==========================================
  6961. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  6962. {
  6963. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  6964. }
  6965. //==========================================
  6966. // csu trigger UnlockConnectorConf
  6967. //==========================================
  6968. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  6969. {
  6970. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  6971. }
  6972. //==========================================
  6973. // csu trigger ReserveNowConf
  6974. //==========================================
  6975. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  6976. {
  6977. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  6978. }
  6979. //==========================================
  6980. // csu trigger ReserveNowConf
  6981. //==========================================
  6982. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  6983. {
  6984. sendReservationStatusUpdateRequest(gun_index);
  6985. }
  6986. //==========================================
  6987. // csu trigger LogStatusNotificationReq
  6988. //==========================================
  6989. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  6990. {
  6991. if(isCancelUploadLog == TRUE)
  6992. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  6993. else
  6994. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  6995. }
  6996. //==========================================
  6997. // csu trigger SignCertificateReq
  6998. //==========================================
  6999. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  7000. {
  7001. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  7002. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  7003. {
  7004. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  7005. }
  7006. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  7007. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  7008. {
  7009. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  7010. }
  7011. }
  7012. }
  7013. }
  7014. //==========================================
  7015. // send request routine
  7016. //==========================================
  7017. int sendAuthorizeRequest(int gun_index)
  7018. {
  7019. mtrace();
  7020. int result = FAIL;
  7021. char message[4096]={0};
  7022. char guid[37];
  7023. char tempdata[128]={0};
  7024. json_object *Authorize = json_object_new_object();
  7025. json_object *idToken = json_object_new_object();
  7026. json_object *iso15118CertificateHashData = json_object_new_array();
  7027. DEBUG_INFO("sendAuthorizeRequest...\n");
  7028. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  7029. //Local Authorize
  7030. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "true")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  7031. {
  7032. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  7033. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7034. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  7035. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  7036. result = PASS;
  7037. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7038. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7039. authorizeRetryTimes = 0;
  7040. return result;
  7041. }
  7042. 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)) ||
  7043. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true") == 0)))
  7044. {
  7045. // Query idtag from cache
  7046. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  7047. // Query idtag from list
  7048. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  7049. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  7050. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  7051. {
  7052. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  7053. {
  7054. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7055. }
  7056. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  7057. {
  7058. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7059. }
  7060. // Return authorize result if does not connect to server
  7061. if(!ShmOCPP20Data->OcppConnStatus)
  7062. {
  7063. DEBUG_INFO("Local Authorization Fail.\n");
  7064. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7065. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7066. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  7067. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7068. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7069. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7070. authorizeRetryTimes = 0;
  7071. return result;
  7072. }
  7073. }
  7074. else
  7075. {
  7076. DEBUG_INFO("Local Authorization get result.\n");
  7077. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  7078. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7079. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  7080. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  7081. else
  7082. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  7083. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7084. result = PASS;
  7085. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7086. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7087. authorizeRetryTimes = 0;
  7088. return result;
  7089. }
  7090. }
  7091. //get data from shared memory
  7092. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7093. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  7094. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  7095. if(strcmp((char*)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenType_eMAID]) == 0)
  7096. {
  7097. json_object *OCSPRequestDataType = json_object_new_object();
  7098. json_object_object_add(Authorize, "certificate", json_object_new_string((char*)ShmOCPP20Data->Authorize.certificate));
  7099. for(int idx=0; idx < 4; idx++)
  7100. {
  7101. if(strlen((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL) >= 7)
  7102. {
  7103. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  7104. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  7105. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  7106. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].serialNumber));
  7107. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL));
  7108. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  7109. }
  7110. }
  7111. json_object_object_add(Authorize, "iso15118CertificateHashData", iso15118CertificateHashData);
  7112. }
  7113. json_object_object_add(Authorize, "idToken", idToken);
  7114. random_uuid(guid);
  7115. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  7116. json_object_put(Authorize);
  7117. LWS_Send(message);
  7118. sprintf(tempdata, "Authorize,%d", gun_index);
  7119. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7120. {
  7121. result = PASS;
  7122. }
  7123. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7124. return result;
  7125. }
  7126. int sendBootNotificationRequest()
  7127. {
  7128. mtrace();
  7129. int result = FAIL;
  7130. char message[4096]={0};
  7131. char guid[37]={0};
  7132. char tempdata[128]={0};
  7133. json_object *BootNotification = json_object_new_object();
  7134. json_object *chargingStation = json_object_new_object();
  7135. json_object *modem = json_object_new_object();
  7136. DEBUG_INFO("sendBootNotificationRequest...\n");
  7137. // Fill BootNotification fields
  7138. DB_getBooType();
  7139. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  7140. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7141. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7142. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  7143. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  7144. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  7145. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  7146. {
  7147. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  7148. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  7149. json_object_object_add(chargingStation, "modem", modem);
  7150. }
  7151. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  7152. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  7153. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  7154. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  7155. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  7156. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  7157. random_uuid(guid);
  7158. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  7159. json_object_put(BootNotification);
  7160. LWS_Send(message);
  7161. sprintf(tempdata, "BootNotification,0");
  7162. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7163. {
  7164. result = PASS;
  7165. }
  7166. return result;
  7167. }
  7168. int sendClearedChargingLimitRequest(int gun_index)
  7169. {
  7170. mtrace();
  7171. int result = FAIL;
  7172. char message[4096]={0};
  7173. char guid[37]={0};
  7174. char tempdata[128]={0};
  7175. json_object *ClearedChargingLimit = json_object_new_object();
  7176. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  7177. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  7178. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  7179. random_uuid(guid);
  7180. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  7181. json_object_put(ClearedChargingLimit);
  7182. LWS_Send(message);
  7183. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  7184. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7185. {
  7186. result = PASS;
  7187. }
  7188. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  7189. return result;
  7190. }
  7191. int sendDataTransferRequest(int gun_index)
  7192. {
  7193. mtrace();
  7194. char message[1000]={0};
  7195. char guid[37]={0};
  7196. char tempdata[65]={0};
  7197. int result = FAIL;
  7198. DEBUG_INFO("sendDataTransferRequest...\n");
  7199. random_uuid(guid);
  7200. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  7201. MESSAGE_TYPE_CALL,
  7202. guid,
  7203. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  7204. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  7205. ShmOCPP20Data->DataTransfer[gun_index].data);
  7206. LWS_Send(message);
  7207. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  7208. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7209. {
  7210. result = PASS;
  7211. }
  7212. return result;
  7213. }
  7214. int sendFirmwareStatusNotificationRequest(char *status)
  7215. {
  7216. mtrace();
  7217. int result = FAIL;
  7218. char message[110]={0};
  7219. char guid[37]={0};
  7220. char tempdata[65]={0};
  7221. json_object *FirmwareStatusNotification = json_object_new_object();
  7222. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  7223. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  7224. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  7225. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  7226. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  7227. random_uuid(guid);
  7228. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7229. json_object_put(FirmwareStatusNotification);
  7230. LWS_SendNow(message);
  7231. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7232. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7233. {
  7234. result = PASS;
  7235. }
  7236. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  7237. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  7238. //record status
  7239. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  7240. {
  7241. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  7242. }
  7243. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  7244. {
  7245. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  7246. }
  7247. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  7248. {
  7249. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  7250. }
  7251. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  7252. {
  7253. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  7254. }
  7255. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  7256. {
  7257. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  7258. }
  7259. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  7260. {
  7261. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  7262. }
  7263. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  7264. {
  7265. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  7266. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7267. }
  7268. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  7269. {
  7270. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  7271. }
  7272. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  7273. {
  7274. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  7275. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7276. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  7277. }
  7278. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  7279. {
  7280. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  7281. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7282. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  7283. }
  7284. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  7285. {
  7286. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  7287. }
  7288. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  7289. {
  7290. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  7291. }
  7292. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  7293. {
  7294. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  7295. }
  7296. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  7297. {
  7298. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  7299. }
  7300. return result;
  7301. }
  7302. int sendGet15118EVCertificateRequest()
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. char message[4096]={0};
  7307. char guid[37]={0};
  7308. char tempdata[128]={0};
  7309. json_object *Get15118EVCertificate = json_object_new_object();
  7310. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  7311. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  7312. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  7313. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  7314. random_uuid(guid);
  7315. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  7316. json_object_put(Get15118EVCertificate);
  7317. LWS_Send(message);
  7318. sprintf(tempdata, "Get15118EVCertificate,0");
  7319. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7320. {
  7321. result = PASS;
  7322. }
  7323. return result;
  7324. }
  7325. int sendGetCertificateStatusRequest()
  7326. {
  7327. mtrace();
  7328. int result = FAIL;
  7329. char message[4096]={0};
  7330. char guid[37]={0};
  7331. char tempdata[128]={0};
  7332. json_object *GetCertificateStatus = json_object_new_object();
  7333. json_object *ocspRequestData = json_object_new_object();
  7334. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  7335. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  7336. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  7337. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  7338. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  7339. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  7340. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  7341. random_uuid(guid);
  7342. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  7343. json_object_put(GetCertificateStatus);
  7344. LWS_Send(message);
  7345. sprintf(tempdata, "GetCertificateStatus,0");
  7346. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7347. {
  7348. result = PASS;
  7349. }
  7350. return result;
  7351. }
  7352. int sendHeartbeatRequest()
  7353. {
  7354. mtrace();
  7355. int result = FAIL;
  7356. char message[40096]={0};
  7357. char guid[37]={0};
  7358. char tempdata[128]={0};
  7359. DEBUG_INFO("sendHeartbeatRequest...\n");
  7360. random_uuid(guid);
  7361. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{}]"
  7362. , MESSAGE_TYPE_CALL
  7363. , guid );
  7364. LWS_Send(message);
  7365. sprintf(tempdata, "Heartbeat,%d", 0);
  7366. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7367. {
  7368. result = PASS;
  7369. }
  7370. return result;
  7371. }
  7372. int sendLogStatusNotificationRequest(char *status)
  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 *LogStatusNotification = json_object_new_object();
  7380. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7381. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  7382. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  7383. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  7384. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  7385. random_uuid(guid);
  7386. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7387. json_object_put(LogStatusNotification);
  7388. LWS_SendNow(message);
  7389. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7390. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7391. {
  7392. result = PASS;
  7393. }
  7394. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7395. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  7396. //record status
  7397. if(strcmp(status,"BadMessage")==0)
  7398. {
  7399. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  7400. }
  7401. else if(strcmp(status,"Idle")==0)
  7402. {
  7403. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  7404. }
  7405. else if(strcmp(status,"NotSupportedOperation")==0)
  7406. {
  7407. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  7408. }
  7409. else if(strcmp(status,"PermissionDenied")==0)
  7410. {
  7411. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  7412. }
  7413. else if(strcmp(status,"Uploaded")==0)
  7414. {
  7415. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  7416. }
  7417. else if(strcmp(status,"UploadFailure")==0)
  7418. {
  7419. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  7420. }
  7421. else if(strcmp(status,"Uploading")==0)
  7422. {
  7423. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  7424. }
  7425. return result;
  7426. }
  7427. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  7428. {
  7429. mtrace();
  7430. int result = FAIL;
  7431. char guid[37]={0};
  7432. char tempdata[65]={0};
  7433. int tempIndex = 0;
  7434. json_object *MeterValueReq = json_object_new_object();
  7435. json_object *meterValues = json_object_new_array();
  7436. json_object *sampledValues = json_object_new_array();
  7437. DEBUG_INFO("sendMeterValuesRequest...\n");
  7438. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  7439. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  7440. //set value
  7441. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  7442. //UTC Date time
  7443. struct timeval tmnow;
  7444. struct tm *tm;
  7445. char buf[28];//, usec_buf[6];
  7446. gettimeofday(&tmnow, NULL);
  7447. time_t t;
  7448. t = time(NULL);
  7449. /*UTC time and date*/
  7450. tm = gmtime(&t);
  7451. if(dataType == ReadingContextEnumType_Sample_Clock)
  7452. {
  7453. struct tm *tmTarget;
  7454. struct timeb tbTarget;
  7455. tbTarget.time = mktime(tm);
  7456. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  7457. tmTarget = gmtime(&tbTarget.time);
  7458. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  7459. }
  7460. else
  7461. {
  7462. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7463. }
  7464. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  7465. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  7466. //idx_sample=0;
  7467. //********************************(1)Current.Import L1************************************************/
  7468. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7469. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7470. (dataType == ReadingContextEnumType_Trigger))
  7471. {
  7472. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7473. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7474. {
  7475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7476. {
  7477. tempIndex = ((gun_index==2) ? 1: 0);
  7478. }
  7479. else
  7480. {
  7481. tempIndex = gun_index;
  7482. }
  7483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7484. {
  7485. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7486. {
  7487. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent*100))/100.0;
  7488. }
  7489. }
  7490. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7491. }
  7492. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7493. {
  7494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7495. {
  7496. tempIndex = ((gun_index==2) ? 1: 0);
  7497. }
  7498. else
  7499. {
  7500. tempIndex = gun_index;
  7501. }
  7502. for (int index = 0; index < CCS_QUANTITY; index++)
  7503. {
  7504. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7505. {
  7506. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent*100))/100.0;
  7507. }
  7508. }
  7509. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7510. }
  7511. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7512. {
  7513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7514. {
  7515. tempIndex = ((gun_index==2) ? 1: 0);
  7516. }
  7517. else
  7518. {
  7519. tempIndex = gun_index;
  7520. }
  7521. for (int index = 0; index < GB_QUANTITY; index++)
  7522. {
  7523. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7524. {
  7525. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent*100))/100.0;
  7526. }
  7527. }
  7528. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7529. }
  7530. else if(gunType[gun_index] == GUN_TYPE_DO)
  7531. {
  7532. tempIndex = gun_index;
  7533. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7534. {
  7535. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7536. {
  7537. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent*100))/100.0;
  7538. }
  7539. }
  7540. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7541. }
  7542. else
  7543. {
  7544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7545. {
  7546. tempIndex = 2;
  7547. }
  7548. else
  7549. {
  7550. tempIndex = gun_index;
  7551. }
  7552. for (int index = 0; index < AC_QUANTITY; index++)
  7553. {
  7554. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7555. {
  7556. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent*100))/100.0;
  7557. }
  7558. }
  7559. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7560. }
  7561. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  7562. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7563. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7564. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  7565. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  7566. }
  7567. //idx_sample=1;
  7568. //********************************(2)Energy.Active.Import.Register ************************************************/
  7569. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  7570. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  7571. (dataType == ReadingContextEnumType_Trigger))
  7572. {
  7573. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7574. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7575. {
  7576. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7577. {
  7578. tempIndex = ((gun_index==2) ? 1: 0);
  7579. }
  7580. else
  7581. {
  7582. tempIndex = gun_index;
  7583. }
  7584. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7585. {
  7586. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7587. {
  7588. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*100))/100.0;
  7589. }
  7590. }
  7591. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7592. }
  7593. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7594. {
  7595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7596. {
  7597. tempIndex = ((gun_index==2) ? 1: 0);
  7598. }
  7599. else
  7600. {
  7601. tempIndex = gun_index;
  7602. }
  7603. for (int index = 0; index < CCS_QUANTITY; index++)
  7604. {
  7605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7606. {
  7607. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*100))/100.0;
  7608. }
  7609. }
  7610. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7611. }
  7612. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7613. {
  7614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7615. {
  7616. tempIndex = ((gun_index==2) ? 1: 0);
  7617. }
  7618. else
  7619. {
  7620. tempIndex = gun_index;
  7621. }
  7622. for (int index = 0; index < GB_QUANTITY; index++)
  7623. {
  7624. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7625. {
  7626. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*100))/100.0;
  7627. }
  7628. }
  7629. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7630. }
  7631. else if(gunType[gun_index] == GUN_TYPE_DO)
  7632. {
  7633. tempIndex = gun_index;
  7634. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7635. {
  7636. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7637. {
  7638. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*100))/100.0;
  7639. }
  7640. }
  7641. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7642. }
  7643. else
  7644. {
  7645. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7646. {
  7647. tempIndex = 2;
  7648. }
  7649. else
  7650. {
  7651. tempIndex = gun_index;
  7652. }
  7653. for (int index = 0; index < AC_QUANTITY; index++)
  7654. {
  7655. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7656. {
  7657. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*100))/100.0;
  7658. }
  7659. }
  7660. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7661. }
  7662. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  7663. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  7664. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7665. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  7666. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7667. }
  7668. //idx_sample=2;
  7669. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7670. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7671. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7672. (dataType == ReadingContextEnumType_Trigger))
  7673. {
  7674. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7675. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7676. {
  7677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7678. {
  7679. tempIndex = ((gun_index==2) ? 1: 0);
  7680. }
  7681. else
  7682. {
  7683. tempIndex = gun_index;
  7684. }
  7685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7686. {
  7687. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7688. {
  7689. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*100))/100.0;
  7690. if(dataType == ReadingContextEnumType_Sample_Clock)
  7691. {
  7692. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7693. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7694. }
  7695. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7696. {
  7697. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7698. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7699. }
  7700. else
  7701. {
  7702. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7703. }
  7704. }
  7705. } // END OF FOR CHAdeMO_QUANTITY
  7706. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7707. }
  7708. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7709. {
  7710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7711. {
  7712. tempIndex = ((gun_index==2) ? 1: 0);
  7713. }
  7714. else
  7715. {
  7716. tempIndex = gun_index;
  7717. }
  7718. for (int index = 0; index < CCS_QUANTITY; index++)
  7719. {
  7720. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7721. {
  7722. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*100))/100.0;
  7723. if(dataType == ReadingContextEnumType_Sample_Clock)
  7724. {
  7725. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7726. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7727. }
  7728. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7729. {
  7730. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7731. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7732. }
  7733. else
  7734. {
  7735. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7736. }
  7737. }
  7738. } // END OF CCS_QUANTITY
  7739. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7740. }
  7741. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7742. {
  7743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7744. {
  7745. tempIndex = ((gun_index==2) ? 1: 0);
  7746. }
  7747. else
  7748. {
  7749. tempIndex = gun_index;
  7750. }
  7751. for (int index = 0; index < GB_QUANTITY; index++)
  7752. {
  7753. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7754. {
  7755. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*100))/100.0;
  7756. if(dataType == ReadingContextEnumType_Sample_Clock)
  7757. {
  7758. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7759. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7760. }
  7761. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7762. {
  7763. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7764. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7765. }
  7766. else
  7767. {
  7768. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7769. }
  7770. }
  7771. } // END OF GB_QUANTITY
  7772. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7773. }
  7774. else if(gunType[gun_index] == GUN_TYPE_DO)
  7775. {
  7776. tempIndex = gun_index;
  7777. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7778. {
  7779. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7780. {
  7781. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*100))/100.0;
  7782. if(dataType == ReadingContextEnumType_Sample_Clock)
  7783. {
  7784. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]);
  7785. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7786. }
  7787. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7788. {
  7789. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7790. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7791. }
  7792. else
  7793. {
  7794. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7795. }
  7796. }
  7797. }
  7798. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7799. }
  7800. else
  7801. {
  7802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7803. {
  7804. tempIndex = 2;
  7805. }
  7806. else
  7807. {
  7808. tempIndex = gun_index;
  7809. }
  7810. for (int index = 0; index < AC_QUANTITY; index++)
  7811. {
  7812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7813. {
  7814. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*100))/100.0;
  7815. if(dataType == ReadingContextEnumType_Sample_Clock)
  7816. {
  7817. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7818. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7819. }
  7820. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7821. {
  7822. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7823. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7824. }
  7825. else
  7826. {
  7827. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7828. }
  7829. }
  7830. }
  7831. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7832. }
  7833. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  7834. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  7835. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7836. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  7837. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7838. }
  7839. //idx_sample=3;
  7840. //********************************(4)Power.Active.Import************************************************/
  7841. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7842. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7843. (dataType == ReadingContextEnumType_Trigger))
  7844. {
  7845. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7847. {
  7848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7849. {
  7850. tempIndex = ((gun_index==2) ? 1: 0);
  7851. }
  7852. else
  7853. {
  7854. tempIndex = gun_index;
  7855. }
  7856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7857. {
  7858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7859. {
  7860. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower*100))/100.0;
  7861. }
  7862. } // END OF FOR
  7863. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7864. }
  7865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7866. {
  7867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7868. {
  7869. tempIndex = ((gun_index==2) ? 1: 0);
  7870. }
  7871. else
  7872. {
  7873. tempIndex = gun_index;
  7874. }
  7875. for (int index = 0; index < CCS_QUANTITY; index++)
  7876. {
  7877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7878. {
  7879. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower*100))/100.0;
  7880. }
  7881. }
  7882. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7883. }
  7884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7885. {
  7886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7887. {
  7888. tempIndex = ((gun_index==2) ? 1: 0);
  7889. }
  7890. else
  7891. {
  7892. tempIndex = gun_index;
  7893. }
  7894. for (int index = 0; index < GB_QUANTITY; index++)
  7895. {
  7896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7897. {
  7898. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7899. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower*100))/100.0;
  7900. }
  7901. }
  7902. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7903. }
  7904. else if(gunType[gun_index] == GUN_TYPE_DO)
  7905. {
  7906. tempIndex = gun_index;
  7907. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7908. {
  7909. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7910. {
  7911. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7912. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower*100))/100.0;
  7913. }
  7914. }
  7915. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7916. }
  7917. else
  7918. {
  7919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7920. {
  7921. tempIndex = 2;
  7922. }
  7923. else
  7924. {
  7925. tempIndex = gun_index;
  7926. }
  7927. for (int index = 0; index < AC_QUANTITY; index++)
  7928. {
  7929. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7930. {
  7931. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower*100))/100.0;
  7932. }
  7933. }
  7934. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7935. }
  7936. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  7937. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  7938. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7939. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  7940. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  7941. }
  7942. //idx_sample=4;
  7943. //***********************************************(5)VOLTAGE L1******************************************************/
  7944. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7945. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7946. (dataType == ReadingContextEnumType_Trigger))
  7947. {
  7948. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7949. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7950. {
  7951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7952. {
  7953. tempIndex = ((gun_index==2) ? 1: 0);
  7954. }
  7955. else
  7956. {
  7957. tempIndex = gun_index;
  7958. }
  7959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7960. {
  7961. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7962. {
  7963. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage*100))/100.0;
  7964. }
  7965. }
  7966. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7967. }
  7968. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  7979. {
  7980. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7981. {
  7982. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage*100))/100.0;
  7983. }
  7984. }
  7985. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7986. }
  7987. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7988. {
  7989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7990. {
  7991. tempIndex = ((gun_index==2) ? 1: 0);
  7992. }
  7993. else
  7994. {
  7995. tempIndex = gun_index;
  7996. }
  7997. for (int index = 0; index < GB_QUANTITY; index++)
  7998. {
  7999. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8000. {
  8001. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage*100))/100.0;
  8002. }
  8003. }
  8004. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8005. }
  8006. else if(gunType[gun_index] == GUN_TYPE_DO)
  8007. {
  8008. tempIndex = gun_index;
  8009. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8010. {
  8011. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8012. {
  8013. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage*100))/100.0;
  8014. }
  8015. }
  8016. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8017. }
  8018. else
  8019. {
  8020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8021. {
  8022. tempIndex = 2;
  8023. }
  8024. else
  8025. {
  8026. tempIndex = gun_index;
  8027. }
  8028. for (int index = 0; index < AC_QUANTITY; index++)
  8029. {
  8030. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8031. {
  8032. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage*100))/100.0;
  8033. }
  8034. }
  8035. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8036. }
  8037. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  8038. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8039. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8040. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  8041. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  8042. }
  8043. //***********************************************(6)SOC******************************************************/
  8044. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8045. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8046. (dataType == ReadingContextEnumType_Trigger))
  8047. {
  8048. 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))
  8049. {
  8050. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  8051. {
  8052. tempIndex = ((gun_index==2) ? 1: 0);
  8053. }
  8054. else
  8055. {
  8056. tempIndex = gun_index;
  8057. }
  8058. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8059. {
  8060. //tempIndex = ((gun_index==2) ? 1: 0);
  8061. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8062. {
  8063. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8064. {
  8065. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  8066. }
  8067. }
  8068. }
  8069. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8070. {
  8071. //tempIndex = ((gun_index==2) ? 1: 0);
  8072. for (int index = 0; index < CCS_QUANTITY; index++)
  8073. {
  8074. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8075. {
  8076. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  8077. }
  8078. }
  8079. }
  8080. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8081. {
  8082. //tempIndex = ((gun_index==2) ? 1: 0);
  8083. for (int index = 0; index < GB_QUANTITY; index++)
  8084. {
  8085. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8086. {
  8087. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  8088. }
  8089. }
  8090. }
  8091. else if(gunType[gun_index] == GUN_TYPE_DO)
  8092. {
  8093. //tempIndex = ((gun_index==2) ? 1: 0);
  8094. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8095. {
  8096. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8097. {
  8098. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  8099. }
  8100. }
  8101. }
  8102. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  8103. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  8104. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8105. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  8106. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  8107. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  8108. }
  8109. }
  8110. //********************************(7)Current.Import L2************************************************/
  8111. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8112. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8113. (dataType == ReadingContextEnumType_Trigger))
  8114. {
  8115. // Only for AC 3 phase
  8116. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8117. {
  8118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8119. {
  8120. tempIndex = 2;
  8121. }
  8122. else
  8123. {
  8124. tempIndex = gun_index;
  8125. }
  8126. for (int index = 0; index < AC_QUANTITY; index++)
  8127. {
  8128. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8129. {
  8130. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2*100))/100.0;
  8131. }
  8132. }
  8133. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8134. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  8135. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8136. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8137. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  8138. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  8139. }
  8140. }
  8141. //********************************(8)Current.Import L3************************************************/
  8142. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8143. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8144. (dataType == ReadingContextEnumType_Trigger))
  8145. {
  8146. // Only for AC 3 phase
  8147. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8148. {
  8149. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8150. {
  8151. tempIndex = 2;
  8152. }
  8153. else
  8154. {
  8155. tempIndex = gun_index;
  8156. }
  8157. for (int index = 0; index < AC_QUANTITY; index++)
  8158. {
  8159. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8160. {
  8161. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3*100))/100.0;
  8162. }
  8163. }
  8164. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8165. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  8166. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8167. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8168. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  8169. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  8170. }
  8171. }
  8172. //***********************************************(9)VOLTAGE L2******************************************************/
  8173. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8174. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8175. (dataType == ReadingContextEnumType_Trigger))
  8176. {
  8177. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8178. {
  8179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8180. {
  8181. tempIndex = 2;
  8182. }
  8183. else
  8184. {
  8185. tempIndex = gun_index;
  8186. }
  8187. for (int index = 0; index < AC_QUANTITY; index++)
  8188. {
  8189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8190. {
  8191. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2*100))/100.0;
  8192. }
  8193. }
  8194. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8195. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8196. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8197. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8198. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8199. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8200. }
  8201. }
  8202. //***********************************************(10)VOLTAGE L3******************************************************/
  8203. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8204. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8205. (dataType == ReadingContextEnumType_Trigger))
  8206. {
  8207. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8208. {
  8209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8210. {
  8211. tempIndex = 2;
  8212. }
  8213. else
  8214. {
  8215. tempIndex = gun_index;
  8216. }
  8217. for (int index = 0; index < AC_QUANTITY; index++)
  8218. {
  8219. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8220. {
  8221. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3*100))/100.0;
  8222. }
  8223. }
  8224. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8225. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8226. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8227. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8228. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8229. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8230. }
  8231. }
  8232. //***********************************************(11)Current.Offered******************************************************/
  8233. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8234. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8235. (dataType == ReadingContextEnumType_Trigger))
  8236. {
  8237. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8238. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8239. {
  8240. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8241. {
  8242. tempIndex = ((gun_index==2) ? 1: 0);
  8243. }
  8244. else
  8245. {
  8246. tempIndex = gun_index;
  8247. }
  8248. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8249. {
  8250. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8251. {
  8252. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10);
  8253. }
  8254. } // END OF FOR
  8255. }
  8256. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8257. {
  8258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8259. {
  8260. tempIndex = ((gun_index==2) ? 1: 0);
  8261. }
  8262. else
  8263. {
  8264. tempIndex = gun_index;
  8265. }
  8266. for (int index = 0; index < CCS_QUANTITY; index++)
  8267. {
  8268. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8269. {
  8270. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10);
  8271. }
  8272. }
  8273. }
  8274. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8275. {
  8276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8277. {
  8278. tempIndex = ((gun_index==2) ? 1: 0);
  8279. }
  8280. else
  8281. {
  8282. tempIndex = gun_index;
  8283. }
  8284. for (int index = 0; index < GB_QUANTITY; index++)
  8285. {
  8286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8287. {
  8288. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8289. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10);;
  8290. }
  8291. }
  8292. }
  8293. else if(gunType[gun_index] == GUN_TYPE_DO)
  8294. {
  8295. tempIndex = gun_index;
  8296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8297. {
  8298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8299. {
  8300. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8301. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10);;
  8302. }
  8303. }
  8304. }
  8305. else
  8306. {
  8307. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8308. {
  8309. tempIndex = 2;
  8310. }
  8311. else
  8312. {
  8313. tempIndex = gun_index;
  8314. }
  8315. for (int index = 0; index < AC_QUANTITY; index++)
  8316. {
  8317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8318. {
  8319. uint16_t currentOffer;
  8320. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8321. {
  8322. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8323. }
  8324. else
  8325. {
  8326. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8327. }
  8328. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8329. }
  8330. }
  8331. }
  8332. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8333. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8334. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8335. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8336. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8337. }
  8338. //***********************************************(12)Power.Offered******************************************************/
  8339. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8340. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8341. (dataType == ReadingContextEnumType_Trigger))
  8342. {
  8343. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8344. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8345. {
  8346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8347. {
  8348. tempIndex = ((gun_index==2) ? 1: 0);
  8349. }
  8350. else
  8351. {
  8352. tempIndex = gun_index;
  8353. }
  8354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8355. {
  8356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8357. {
  8358. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100);
  8359. }
  8360. } // END OF FOR
  8361. }
  8362. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8363. {
  8364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8365. {
  8366. tempIndex = ((gun_index==2) ? 1: 0);
  8367. }
  8368. else
  8369. {
  8370. tempIndex = gun_index;
  8371. }
  8372. for (int index = 0; index < CCS_QUANTITY; index++)
  8373. {
  8374. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8375. {
  8376. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100);
  8377. }
  8378. }
  8379. }
  8380. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8381. {
  8382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8383. {
  8384. tempIndex = ((gun_index==2) ? 1: 0);
  8385. }
  8386. else
  8387. {
  8388. tempIndex = gun_index;
  8389. }
  8390. for (int index = 0; index < GB_QUANTITY; index++)
  8391. {
  8392. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8393. {
  8394. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8395. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100);
  8396. }
  8397. }
  8398. }
  8399. else if(gunType[gun_index] == GUN_TYPE_DO)
  8400. {
  8401. tempIndex = gun_index;
  8402. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8403. {
  8404. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8405. {
  8406. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8407. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100);
  8408. }
  8409. }
  8410. }
  8411. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8412. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8413. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8414. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8415. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8416. }
  8417. // Message create ====================================================================================================
  8418. random_uuid(guid);
  8419. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8420. {
  8421. json_object *meterValue = json_object_new_object();
  8422. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8423. {
  8424. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8425. {
  8426. json_object *sampledValue = json_object_new_object();
  8427. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8428. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8429. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8430. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8431. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8432. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8433. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8434. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8435. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8436. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8437. {
  8438. json_object *unitOfMeasure = json_object_new_object();
  8439. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8440. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8441. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8442. }
  8443. json_object_array_add(sampledValues, sampledValue);
  8444. }
  8445. }
  8446. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8447. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8448. json_object_array_add(meterValues, meterValue);
  8449. idxMeter++;
  8450. }
  8451. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8452. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8453. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8454. ,MESSAGE_TYPE_CALL
  8455. ,guid
  8456. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8457. json_object_put(MeterValueReq);
  8458. if((dataType != ReadingContextEnumType_Trigger) &&
  8459. (dataType != ReadingContextEnumType_Sample_Clock))
  8460. {
  8461. // Transaction meter value send by TransactionEvent message
  8462. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8463. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8464. result = PASS;
  8465. }
  8466. else
  8467. {
  8468. // Put request guid to hash map
  8469. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8470. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8471. {
  8472. result = PASS;
  8473. }
  8474. if((dataType != ReadingContextEnumType_Trigger) &&
  8475. (dataType != ReadingContextEnumType_Sample_Clock))
  8476. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8477. else
  8478. {
  8479. if(FirstHeartBeat)
  8480. LWS_Send(queuedata);
  8481. }
  8482. }
  8483. return result;
  8484. }
  8485. int sendNotifyChargingLimitRequest(int gun_index)
  8486. {
  8487. mtrace();
  8488. int result = FAIL;
  8489. char message[4096]={0};
  8490. char guid[37]={0};
  8491. char tempdata[128]={0};
  8492. json_object *NotifyChargingLimit = json_object_new_object();
  8493. json_object *chargingLimit = json_object_new_object();
  8494. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8495. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8496. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8497. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8498. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8499. random_uuid(guid);
  8500. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8501. json_object_put(NotifyChargingLimit);
  8502. LWS_Send(message);
  8503. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8504. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8505. {
  8506. result = PASS;
  8507. }
  8508. return result;
  8509. }
  8510. int sendNotifyCustomerInformationRequest()
  8511. {
  8512. mtrace();
  8513. int result = FAIL;
  8514. char message[4096]={0};
  8515. char guid[37]={0};
  8516. char tempdata[128]={0};
  8517. json_object *NotifyCustomerInformation = json_object_new_object();
  8518. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8519. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8520. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8521. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8522. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8523. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8524. random_uuid(guid);
  8525. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8526. json_object_put(NotifyCustomerInformation);
  8527. LWS_Send(message);
  8528. sprintf(tempdata, "NotifyCustomerInformation,0");
  8529. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8530. {
  8531. result = PASS;
  8532. }
  8533. return result;
  8534. }
  8535. int sendNotifyDisplayMessagesRequest()
  8536. {
  8537. mtrace();
  8538. int result = FAIL;
  8539. char message[4096]={0};
  8540. char guid[37]={0};
  8541. char tempdata[128]={0};
  8542. json_object *NotifyDisplayMessages = json_object_new_object();
  8543. json_object *messageInfos = json_object_new_array();
  8544. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8545. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8546. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8547. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8548. {
  8549. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8550. {
  8551. json_object *messageInfo = json_object_new_object();
  8552. json_object *message = json_object_new_object();
  8553. json_object *display = json_object_new_object();
  8554. json_object *evse = json_object_new_object();
  8555. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8556. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8557. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8558. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8559. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8560. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8561. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8562. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8563. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8564. json_object_object_add(messageInfo, "message", message);
  8565. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8566. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8567. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8568. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8569. json_object_object_add(display, "evse",evse);
  8570. json_object_object_add(messageInfo, "evse", display);
  8571. json_object_array_add(messageInfos, messageInfo);
  8572. }
  8573. }
  8574. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8575. random_uuid(guid);
  8576. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8577. json_object_put(NotifyDisplayMessages);
  8578. LWS_Send(message);
  8579. sprintf(tempdata, "NotifyDisplayMessages,0");
  8580. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8581. {
  8582. result = PASS;
  8583. }
  8584. return result;
  8585. }
  8586. int sendNotifyEVChargingNeedsRequest(int gun_index)
  8587. {
  8588. mtrace();
  8589. int result = FAIL;
  8590. char message[4096]={0};
  8591. char guid[37]={0};
  8592. char tempdata[128]={0};
  8593. json_object *NotifyEVChargingNeeds = json_object_new_object();
  8594. json_object *chargingNeeds = json_object_new_object();
  8595. json_object *acChargingParameters = json_object_new_object();
  8596. json_object *dcChargingParameters = json_object_new_object();
  8597. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8598. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8599. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8600. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8601. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8602. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8603. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8604. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8605. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8606. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8607. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8608. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8609. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8610. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8611. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8612. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8613. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8614. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8615. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8616. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8617. random_uuid(guid);
  8618. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8619. json_object_put(NotifyEVChargingNeeds);
  8620. LWS_Send(message);
  8621. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8622. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8623. {
  8624. result = PASS;
  8625. }
  8626. return result;
  8627. }
  8628. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8629. {
  8630. mtrace();
  8631. int result = FAIL;
  8632. char message[4096]={0};
  8633. char guid[37]={0};
  8634. char tempdata[128]={0};
  8635. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8636. json_object *chargingSchedule = json_object_new_object();
  8637. json_object *periods = json_object_new_array();
  8638. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8639. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8640. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8641. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8642. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8643. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8644. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8645. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8646. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8647. {
  8648. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8649. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8650. {
  8651. json_object *Period = json_object_new_object();
  8652. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8653. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8654. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8655. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8656. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8657. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8658. json_object_array_add(periods, Period);
  8659. }
  8660. }
  8661. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8662. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8663. random_uuid(guid);
  8664. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8665. json_object_put(NotifyEVChargingSchedule);
  8666. LWS_Send(message);
  8667. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8668. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8669. {
  8670. result = PASS;
  8671. }
  8672. return result;
  8673. }
  8674. int sendNotifyEventRequest()
  8675. {
  8676. mtrace();
  8677. int result = FAIL;
  8678. char message[4096]={0};
  8679. char guid[37]={0};
  8680. char tempdata[128]={0};
  8681. json_object *NotifyEvent = json_object_new_object();
  8682. json_object *eventDatas = json_object_new_array();
  8683. DEBUG_INFO("sendNotifyEventRequest...\n");
  8684. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8685. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8686. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8687. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8688. {
  8689. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8690. {
  8691. json_object *eventData = json_object_new_object();
  8692. json_object *component = json_object_new_object();
  8693. json_object *evse = json_object_new_object();
  8694. json_object *variable = json_object_new_object();
  8695. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8696. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8697. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8698. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8699. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8700. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8701. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8702. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8703. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8704. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8705. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8706. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8707. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8708. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8709. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  8710. json_object_object_add(component, "evse",evse);
  8711. json_object_object_add(eventData, "component", component);
  8712. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  8713. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  8714. json_object_object_add(eventData, "variable", variable);
  8715. json_object_array_add(eventDatas, eventData);
  8716. }
  8717. }
  8718. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  8719. random_uuid(guid);
  8720. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  8721. json_object_put(NotifyEvent);
  8722. LWS_Send(message);
  8723. sprintf(tempdata, "NotifyEvent,0");
  8724. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8725. {
  8726. result = PASS;
  8727. }
  8728. return result;
  8729. }
  8730. int sendNotifyMonitoringReportRequest()
  8731. {
  8732. mtrace();
  8733. int result = FAIL;
  8734. char message[4096]={0};
  8735. char guid[37]={0};
  8736. char tempdata[128]={0};
  8737. json_object *NotifyMonitoringReport = json_object_new_object();
  8738. json_object *monitors = json_object_new_array();
  8739. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  8740. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  8741. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  8742. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  8743. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  8744. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  8745. {
  8746. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  8747. {
  8748. json_object *monitor = json_object_new_object();
  8749. json_object *component = json_object_new_object();
  8750. json_object *evse = json_object_new_object();
  8751. json_object *variable = json_object_new_object();
  8752. json_object *variableMonitorings = json_object_new_array();
  8753. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  8754. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  8755. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  8756. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  8757. json_object_object_add(component, "evse",evse);
  8758. json_object_object_add(monitor, "component", component);
  8759. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  8760. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  8761. json_object_object_add(monitor, "variable", variable);
  8762. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  8763. {
  8764. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  8765. {
  8766. json_object *variableMonitoring = json_object_new_object();
  8767. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  8768. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  8769. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  8770. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  8771. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  8772. json_object_array_add(variableMonitorings, variableMonitoring);
  8773. }
  8774. }
  8775. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  8776. json_object_array_add(monitors, monitor);
  8777. }
  8778. }
  8779. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  8780. random_uuid(guid);
  8781. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8782. json_object_put(NotifyMonitoringReport);
  8783. LWS_Send(message);
  8784. sprintf(tempdata, "NotifyMonitoringReport,0");
  8785. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8786. {
  8787. result = PASS;
  8788. }
  8789. return result;
  8790. }
  8791. int sendNotifyReportRequest()
  8792. {
  8793. mtrace();
  8794. int result = FAIL;
  8795. char message[4096]={0};
  8796. char guid[37]={0};
  8797. char tempdata[128]={0};
  8798. json_object *NotifyReport = json_object_new_object();
  8799. json_object *reportDatas = json_object_new_array();
  8800. DEBUG_INFO("sendNotifyReportRequest...\n");
  8801. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  8802. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  8803. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  8804. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  8805. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  8806. {
  8807. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  8808. {
  8809. json_object *reportData = json_object_new_object();
  8810. json_object *component = json_object_new_object();
  8811. json_object *evse = json_object_new_object();
  8812. json_object *variable = json_object_new_object();
  8813. json_object *variableAttributes = json_object_new_array();
  8814. json_object *variableCharacteristics = json_object_new_object();
  8815. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  8816. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  8817. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  8818. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  8819. json_object_object_add(component, "evse",evse);
  8820. json_object_object_add(reportData, "component", component);
  8821. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  8822. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  8823. json_object_object_add(reportData, "variable",variable);
  8824. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  8825. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  8826. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  8827. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  8828. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  8829. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  8830. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  8831. {
  8832. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  8833. {
  8834. json_object *variableAttribute = json_object_new_object();
  8835. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  8836. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  8837. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  8838. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  8839. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  8840. json_object_array_add(variableAttributes, variableAttribute);
  8841. }
  8842. }
  8843. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  8844. json_object_array_add(reportDatas, reportData);
  8845. }
  8846. }
  8847. json_object_object_add(NotifyReport, "reportData", reportDatas);
  8848. random_uuid(guid);
  8849. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  8850. json_object_put(NotifyReport);
  8851. LWS_SendNow(message);
  8852. sprintf(tempdata, "NotifyReport,0");
  8853. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8854. {
  8855. result = PASS;
  8856. }
  8857. return result;
  8858. }
  8859. int sendPublishFirmwareStatusNotificationRequest()
  8860. {
  8861. mtrace();
  8862. int result = FAIL;
  8863. char message[4096]={0};
  8864. char guid[37]={0};
  8865. char tempdata[128]={0};
  8866. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  8867. json_object *locations = json_object_new_array();
  8868. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  8869. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  8870. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  8871. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  8872. {
  8873. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  8874. }
  8875. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  8876. random_uuid(guid);
  8877. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8878. json_object_put(PublishFirmwareStatusNotification);
  8879. LWS_Send(message);
  8880. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  8881. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8882. {
  8883. result = PASS;
  8884. }
  8885. return result;
  8886. }
  8887. int sendReportChargingProfilesRequest(int gun_index)
  8888. {
  8889. mtrace();
  8890. int result = FAIL;
  8891. char message[4096]={0};
  8892. char guid[37]={0};
  8893. char tempdata[128]={0};
  8894. json_object *ReportChargingProfiles = json_object_new_object();
  8895. json_object *chargingProfiles = json_object_new_array();
  8896. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  8897. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  8898. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  8899. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  8900. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  8901. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  8902. {
  8903. json_object *chargingProfile = json_object_new_object();
  8904. json_object *chargingSchedules = json_object_new_array();
  8905. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  8906. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  8907. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  8908. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  8909. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  8910. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  8911. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  8912. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  8913. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  8914. {
  8915. json_object *chargingSchedule = json_object_new_object();
  8916. json_object *chargingSchedulePeriods = json_object_new_array();
  8917. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  8918. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  8919. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  8920. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  8921. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  8922. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  8923. {
  8924. json_object *chargingSchedulePeriod = json_object_new_object();
  8925. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  8926. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  8927. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  8928. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  8929. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  8930. }
  8931. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  8932. json_object_array_add(chargingSchedules, chargingSchedule);
  8933. }
  8934. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  8935. json_object_array_add(chargingProfiles, chargingProfile);
  8936. }
  8937. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  8938. random_uuid(guid);
  8939. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  8940. json_object_put(ReportChargingProfiles);
  8941. LWS_Send(message);
  8942. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  8943. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8944. {
  8945. result = PASS;
  8946. }
  8947. return result;
  8948. }
  8949. int sendReservationStatusUpdateRequest(int gun_index)
  8950. {
  8951. mtrace();
  8952. int result = FAIL;
  8953. char message[4096]={0};
  8954. char guid[37]={0};
  8955. char tempdata[128]={0};
  8956. json_object *ReservationStatusUpdate = json_object_new_object();
  8957. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  8958. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  8959. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  8960. random_uuid(guid);
  8961. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  8962. json_object_put(ReservationStatusUpdate);
  8963. LWS_Send(message);
  8964. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  8965. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8966. {
  8967. result = PASS;
  8968. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  8969. }
  8970. return result;
  8971. }
  8972. int sendSecurityEventNotificationRequest()
  8973. {
  8974. mtrace();
  8975. int result = FAIL;
  8976. char message[4096]={0};
  8977. char guid[37]={0};
  8978. char tempdata[128]={0};
  8979. struct timeval tmnow;
  8980. struct tm *tm;
  8981. char buf[28];//, usec_buf[6];
  8982. json_object *SecurityEventNotification = json_object_new_object();
  8983. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  8984. DB_getSecurityEventType();
  8985. gettimeofday(&tmnow, NULL);
  8986. time_t t;
  8987. t = time(NULL);
  8988. /*UTC time and date*/
  8989. tm = gmtime(&t);
  8990. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8991. #if 0 // remove temporally
  8992. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  8993. strcat(buf,".");
  8994. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  8995. strcat(buf,usec_buf);
  8996. #endif
  8997. printf("%s",buf);
  8998. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  8999. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  9000. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  9001. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  9002. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  9003. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  9004. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  9005. random_uuid(guid);
  9006. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  9007. json_object_put(SecurityEventNotification);
  9008. LWS_Send(message);
  9009. sprintf(tempdata, "SecurityEventNotification,0");
  9010. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9011. {
  9012. result = PASS;
  9013. }
  9014. return result;
  9015. }
  9016. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  9017. {
  9018. mtrace();
  9019. int result = FAIL;
  9020. char message[4096]={0};
  9021. char guid[37]={0};
  9022. char tempdata[128]={0};
  9023. json_object *SignCertificate = json_object_new_object();
  9024. DEBUG_INFO("sendSignCertificateRequest...\n");
  9025. // Read csr file content
  9026. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  9027. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  9028. char *line = NULL;
  9029. size_t len = 0;
  9030. while(getline(&line, &len, fp) != -1)
  9031. {
  9032. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  9033. {
  9034. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  9035. }
  9036. }
  9037. fclose(fp);
  9038. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  9039. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  9040. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  9041. random_uuid(guid);
  9042. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  9043. json_object_put(SignCertificate);
  9044. LWS_Send(message);
  9045. sprintf(tempdata, "SignCertificate,0");
  9046. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9047. {
  9048. result = PASS;
  9049. }
  9050. return result;
  9051. }
  9052. int sendStatusNotificationRequest(int gun_index)
  9053. {
  9054. mtrace();
  9055. int result = FAIL;
  9056. char message[600]={0};
  9057. char guid[37];
  9058. int currentStatus = 0;
  9059. struct timeval tmnow;
  9060. struct tm *tm;
  9061. char buf[28];//, usec_buf[6];
  9062. char tempdata[65]={0};
  9063. int tempIndex = 0;
  9064. uint8_t isStateChanged = TRUE;
  9065. DEBUG_INFO("sendStatusNotificationRequest...\n");
  9066. gettimeofday(&tmnow, NULL);
  9067. time_t t;
  9068. t = time(NULL);
  9069. /*UTC time and date*/
  9070. tm = gmtime(&t);
  9071. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9072. #if 0 // remove temporally
  9073. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9074. strcat(buf,".");
  9075. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9076. strcat(buf,usec_buf);
  9077. #endif
  9078. printf("%s",buf);
  9079. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  9080. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  9081. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  9082. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  9083. /*
  9084. enum _SYSTEM_STATUS
  9085. {
  9086. S_BOOTING = 0,
  9087. S_IDLE, = 1
  9088. S_AUTHORIZING, =2
  9089. S_REASSIGN_CHECK, =3
  9090. S_REASSIGN, =4
  9091. S_PRECHARGE, =5
  9092. S_PREPARING_FOR_EV, =6
  9093. S_PREPARING_FOR_EVSE, =7
  9094. S_CHARGING, =8
  9095. S_TERMINATING, =9
  9096. S_COMPLETE, =10
  9097. S_ALARM, =11
  9098. S_FAULT =12
  9099. }
  9100. */
  9101. //check Transaction active
  9102. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  9103. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9104. {
  9105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9106. {
  9107. tempIndex = ((gun_index==2) ? 1: 0);
  9108. }
  9109. else
  9110. {
  9111. tempIndex = gun_index;
  9112. }
  9113. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9114. {
  9115. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9116. {
  9117. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9118. {
  9119. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9120. {
  9121. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9122. }
  9123. else
  9124. {
  9125. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9126. }
  9127. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9128. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9129. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9130. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9131. }
  9132. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9133. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9134. ) //S_PRECHARGE
  9135. {
  9136. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9137. }
  9138. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9139. {
  9140. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9141. }
  9142. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9143. {
  9144. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9145. }
  9146. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9147. {
  9148. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9149. }
  9150. 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
  9151. {
  9152. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9153. }
  9154. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9155. {
  9156. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9157. }
  9158. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9159. {
  9160. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9161. }
  9162. } //end of the same index
  9163. }//end of for CHAdeMO_QUANTITY
  9164. }
  9165. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9166. {
  9167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9168. {
  9169. tempIndex = ((gun_index==2) ? 1: 0);
  9170. }
  9171. else
  9172. {
  9173. tempIndex = gun_index;
  9174. }
  9175. for (int index = 0; index < CCS_QUANTITY; index++)
  9176. {
  9177. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9178. {
  9179. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9180. {
  9181. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9182. {
  9183. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9184. }
  9185. else
  9186. {
  9187. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9188. }
  9189. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9190. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9191. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9192. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9193. }
  9194. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9195. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9196. ) //S_PRECHARGE
  9197. {
  9198. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9199. }
  9200. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9201. {
  9202. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9203. }
  9204. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9205. {
  9206. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9207. }
  9208. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9209. {
  9210. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9211. }
  9212. 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
  9213. {
  9214. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9215. }
  9216. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9217. {
  9218. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9219. }
  9220. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9221. {
  9222. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9223. }
  9224. } //end of the same index
  9225. } // end of for CCS_QUANTITY
  9226. }
  9227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9228. {
  9229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9230. {
  9231. tempIndex = ((gun_index==2) ? 1: 0);
  9232. }
  9233. else
  9234. {
  9235. tempIndex = gun_index;
  9236. }
  9237. for (int index = 0; index < GB_QUANTITY; index++)
  9238. {
  9239. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9240. {
  9241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9242. {
  9243. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9244. {
  9245. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9246. }
  9247. else
  9248. {
  9249. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9250. }
  9251. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9252. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9253. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9254. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9255. }
  9256. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9257. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9258. ) //S_PRECHARGE
  9259. {
  9260. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9261. }
  9262. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9263. {
  9264. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9265. }
  9266. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9267. {
  9268. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9269. }
  9270. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9271. {
  9272. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9273. }
  9274. 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
  9275. {
  9276. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9277. }
  9278. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9279. {
  9280. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9281. }
  9282. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9283. {
  9284. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9285. }
  9286. } //end of the same index
  9287. } // end of for GB_QUANTITY
  9288. }
  9289. else if(gunType[gun_index] == GUN_TYPE_DO)
  9290. {
  9291. tempIndex = gun_index;
  9292. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9293. {
  9294. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9295. {
  9296. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9297. {
  9298. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9299. {
  9300. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9301. }
  9302. else
  9303. {
  9304. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9305. }
  9306. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9307. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9308. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9309. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9310. }
  9311. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9312. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9313. ) //S_PRECHARGE
  9314. {
  9315. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9316. }
  9317. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9318. {
  9319. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9320. }
  9321. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9322. {
  9323. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9324. }
  9325. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9326. {
  9327. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9328. }
  9329. 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
  9330. {
  9331. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9332. }
  9333. 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
  9334. {
  9335. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9336. }
  9337. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9338. {
  9339. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9340. }
  9341. } //end of the same index
  9342. }
  9343. }
  9344. else
  9345. {
  9346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9347. {
  9348. tempIndex = 2;
  9349. }
  9350. else
  9351. {
  9352. tempIndex = gun_index;
  9353. }
  9354. for (int index = 0; index < AC_QUANTITY; index++)
  9355. {
  9356. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9357. {
  9358. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9359. {
  9360. 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))
  9361. {
  9362. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9363. }
  9364. else
  9365. {
  9366. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9367. }
  9368. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9369. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9370. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9371. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9372. }
  9373. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9374. {
  9375. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9376. }
  9377. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9378. {
  9379. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9380. }
  9381. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9382. {
  9383. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9384. }
  9385. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9386. {
  9387. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9388. }
  9389. 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
  9390. {
  9391. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9392. }
  9393. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9394. {
  9395. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9396. }
  9397. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9398. {
  9399. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9400. }
  9401. }//end of the same index
  9402. }//end of for AC_QUANTITY
  9403. }
  9404. //it's option
  9405. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9406. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9407. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") != 0))
  9408. {
  9409. isStateChanged = FALSE;
  9410. }
  9411. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9412. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9413. random_uuid(guid);
  9414. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9415. , MESSAGE_TYPE_CALL
  9416. , guid
  9417. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9418. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9419. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9420. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9421. if((server_sign == TRUE) && isStateChanged)
  9422. {
  9423. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9424. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9425. LWS_Send(message);
  9426. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9427. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9428. {
  9429. result = PASS;
  9430. }
  9431. }
  9432. else
  9433. {
  9434. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9435. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9436. result = PASS;
  9437. }
  9438. return result;
  9439. }
  9440. int sendTransactionEventRequest(int gun_index)
  9441. {
  9442. mtrace();
  9443. int result = FAIL;
  9444. char message[1024*20]={0};
  9445. char guid[37]={0};
  9446. char tempdata[128]={0};
  9447. uint8_t tempIndex;
  9448. json_object *TransactionEvent = json_object_new_object();
  9449. json_object *transactionInfo = json_object_new_object();
  9450. json_object *idToken = json_object_new_object();
  9451. json_object *evse = json_object_new_object();
  9452. json_object *meterValues = json_object_new_array();
  9453. char TempStopTransaction[256];
  9454. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9455. DEBUG_INFO("sendTransactionEventRequest...\n");
  9456. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9457. {
  9458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9459. {
  9460. tempIndex = ((gun_index==2) ? 1: 0);
  9461. }
  9462. else
  9463. {
  9464. tempIndex = gun_index;
  9465. }
  9466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9467. {
  9468. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9469. {
  9470. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9471. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9472. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9473. else
  9474. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9475. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9476. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9477. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9478. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9479. {
  9480. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9481. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9482. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9483. {
  9484. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9485. }
  9486. else
  9487. {
  9488. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9489. }
  9490. }
  9491. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9492. {
  9493. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9494. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9495. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9496. }
  9497. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9498. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9499. ) //S_PRECHARGE
  9500. {
  9501. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9502. {
  9503. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9504. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9505. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9506. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9507. }
  9508. else
  9509. {
  9510. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9511. }
  9512. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9513. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9514. }
  9515. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9516. {
  9517. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9518. {
  9519. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9520. {
  9521. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9522. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9523. }
  9524. else
  9525. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9526. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9527. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9528. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9529. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9530. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9531. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  9532. }
  9533. else
  9534. {
  9535. storeTempStopTransaction(gun_index);
  9536. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9537. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9538. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9539. }
  9540. }
  9541. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9542. {
  9543. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9544. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9545. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9546. if((access(TempStopTransaction,F_OK))!=-1)
  9547. {
  9548. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9549. }
  9550. }
  9551. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9552. {
  9553. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9554. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9555. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9556. }
  9557. 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
  9558. {
  9559. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9560. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9561. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9562. }
  9563. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9564. {
  9565. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9566. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9567. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9568. }
  9569. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9570. {
  9571. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9572. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9573. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9574. }
  9575. } //end of the same index
  9576. }//end of for CHAdeMO_QUANTITY
  9577. }
  9578. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9579. {
  9580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9581. {
  9582. tempIndex = ((gun_index==2) ? 1: 0);
  9583. }
  9584. else
  9585. {
  9586. tempIndex = gun_index;
  9587. }
  9588. for (int index = 0; index < CCS_QUANTITY; index++)
  9589. {
  9590. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9591. {
  9592. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9593. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9594. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9595. else
  9596. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9597. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9598. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9599. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9600. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9601. {
  9602. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9603. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9604. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9605. {
  9606. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9607. }
  9608. else
  9609. {
  9610. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9611. }
  9612. }
  9613. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9614. {
  9615. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9616. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9617. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9618. }
  9619. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9620. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9621. ) //S_PRECHARGE
  9622. {
  9623. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9624. {
  9625. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9626. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9627. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9628. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9629. }
  9630. else
  9631. {
  9632. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9633. }
  9634. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9635. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9636. }
  9637. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9638. {
  9639. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9640. {
  9641. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9642. {
  9643. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9644. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9645. }
  9646. else
  9647. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9648. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9649. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9650. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9651. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9652. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9653. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  9654. }
  9655. else
  9656. {
  9657. storeTempStopTransaction(gun_index);
  9658. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9659. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9660. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9661. }
  9662. }
  9663. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9664. {
  9665. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9666. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9667. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9668. if((access(TempStopTransaction,F_OK))!=-1)
  9669. {
  9670. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9671. }
  9672. }
  9673. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9674. {
  9675. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9676. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9677. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9678. }
  9679. 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
  9680. {
  9681. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9682. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9683. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9684. }
  9685. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9686. {
  9687. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9688. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9689. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9690. }
  9691. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9692. {
  9693. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9694. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9695. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9696. }
  9697. } //end of the same index
  9698. } // end of for CCS_QUANTITY
  9699. }
  9700. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9701. {
  9702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9703. {
  9704. tempIndex = ((gun_index==2) ? 1: 0);
  9705. }
  9706. else
  9707. {
  9708. tempIndex = gun_index;
  9709. }
  9710. for (int index = 0; index < GB_QUANTITY; index++)
  9711. {
  9712. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9713. {
  9714. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9715. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9716. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9717. else
  9718. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9719. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9720. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9721. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9723. {
  9724. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9725. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9726. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9727. {
  9728. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9729. }
  9730. else
  9731. {
  9732. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9733. }
  9734. }
  9735. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9736. {
  9737. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9738. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9739. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9740. }
  9741. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9742. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9743. ) //S_PRECHARGE
  9744. {
  9745. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9746. {
  9747. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9748. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9749. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9750. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9751. }
  9752. else
  9753. {
  9754. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9755. }
  9756. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9757. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9758. }
  9759. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9760. {
  9761. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9762. {
  9763. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  9764. {
  9765. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9766. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9767. }
  9768. else
  9769. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9770. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9771. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9772. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9773. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9774. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9775. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  9776. }
  9777. else
  9778. {
  9779. storeTempStopTransaction(gun_index);
  9780. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9781. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9782. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9783. }
  9784. }
  9785. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9786. {
  9787. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9788. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9789. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9790. if((access(TempStopTransaction,F_OK))!=-1)
  9791. {
  9792. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9793. }
  9794. }
  9795. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9796. {
  9797. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9798. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9799. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9800. }
  9801. 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
  9802. {
  9803. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9804. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9805. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9806. }
  9807. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9808. {
  9809. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9810. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9811. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9812. }
  9813. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9814. {
  9815. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9816. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9817. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9818. }
  9819. } //end of the same index
  9820. } // end of for GB_QUANTITY
  9821. }
  9822. else if(gunType[gun_index] == GUN_TYPE_DO)
  9823. {
  9824. tempIndex = gun_index;
  9825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9826. {
  9827. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9828. {
  9829. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9830. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9831. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9832. else
  9833. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9834. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9835. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9836. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9837. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9838. {
  9839. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9840. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9841. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9842. {
  9843. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9844. }
  9845. else
  9846. {
  9847. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9848. }
  9849. }
  9850. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9851. {
  9852. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9853. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9854. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9855. }
  9856. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9857. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9858. ) //S_PRECHARGE
  9859. {
  9860. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9861. {
  9862. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9863. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9864. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  9865. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9866. }
  9867. else
  9868. {
  9869. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9870. }
  9871. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9872. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9873. }
  9874. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9875. {
  9876. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9877. {
  9878. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  9879. {
  9880. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9881. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9882. }
  9883. else
  9884. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9885. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9886. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9887. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  9888. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9889. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9890. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  9891. }
  9892. else
  9893. {
  9894. storeTempStopTransaction(gun_index);
  9895. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9896. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9897. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9898. }
  9899. }
  9900. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9901. {
  9902. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9903. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9904. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9905. if((access(TempStopTransaction,F_OK))!=-1)
  9906. {
  9907. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9908. }
  9909. }
  9910. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9911. {
  9912. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9913. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9914. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9915. }
  9916. 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
  9917. {
  9918. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9919. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9920. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9921. }
  9922. 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
  9923. {
  9924. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9925. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9926. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9927. }
  9928. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9929. {
  9930. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9931. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9932. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9933. }
  9934. } //end of the same index
  9935. }
  9936. }
  9937. else
  9938. {
  9939. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9940. {
  9941. tempIndex = 2;
  9942. }
  9943. else
  9944. {
  9945. tempIndex = gun_index;
  9946. }
  9947. for (int index = 0; index < AC_QUANTITY; index++)
  9948. {
  9949. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9950. {
  9951. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9952. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9953. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9954. else
  9955. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9956. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9957. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9958. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9960. {
  9961. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9962. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9963. 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))
  9964. {
  9965. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9966. }
  9967. else
  9968. {
  9969. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9970. }
  9971. }
  9972. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9973. {
  9974. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9975. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9976. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9977. }
  9978. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9979. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9980. ) //S_PRECHARGE
  9981. {
  9982. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9983. {
  9984. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9985. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  9986. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  9987. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9988. }
  9989. else
  9990. {
  9991. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9992. }
  9993. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9994. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9995. }
  9996. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9997. {
  9998. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9999. {
  10000. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10001. {
  10002. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10003. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10004. }
  10005. else
  10006. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10007. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10008. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10009. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10010. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10011. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10012. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  10013. }
  10014. else
  10015. {
  10016. storeTempStopTransaction(gun_index);
  10017. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10018. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10019. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10020. }
  10021. }
  10022. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10023. {
  10024. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10025. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10026. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10027. if((access(TempStopTransaction,F_OK))!=-1)
  10028. {
  10029. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10030. }
  10031. }
  10032. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10033. {
  10034. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10035. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10036. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10037. }
  10038. 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
  10039. {
  10040. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10041. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10042. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10043. }
  10044. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10045. {
  10046. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10047. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10048. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10049. }
  10050. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10051. {
  10052. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10053. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10054. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10055. }
  10056. }//end of the same index
  10057. }//end of for AC_QUANTITY
  10058. }
  10059. // Check if this message is triggered by TriggerMessage
  10060. if(cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  10061. {
  10062. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10063. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Trigger]);
  10064. }
  10065. // Message
  10066. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  10067. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  10068. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  10069. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  10070. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  10071. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  10072. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  10073. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  10074. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  10075. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  10076. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  10077. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  10078. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  10079. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  10080. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  10081. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  10082. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  10083. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  10084. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10085. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  10086. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  10087. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  10088. {
  10089. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  10090. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  10091. json_object_object_add(TransactionEvent, "idToken", idToken);
  10092. }
  10093. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  10094. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  10095. json_object_object_add(TransactionEvent, "evse", evse);
  10096. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  10097. {
  10098. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  10099. {
  10100. json_object *meterValue = json_object_new_object();
  10101. json_object *sampledValues = json_object_new_array();
  10102. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  10103. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  10104. {
  10105. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  10106. ((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) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  10107. {
  10108. if(((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)) ||
  10109. (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  10110. {
  10111. json_object *sampledValue = json_object_new_object();
  10112. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  10113. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  10114. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  10115. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  10116. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  10117. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  10118. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  10119. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  10120. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  10121. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  10122. {
  10123. json_object *unitOfMeasure = json_object_new_object();
  10124. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  10125. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  10126. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  10127. }
  10128. json_object_array_add(sampledValues, sampledValue);
  10129. }
  10130. }
  10131. }
  10132. json_object_object_add(meterValue, "sampledValue", sampledValues);
  10133. json_object_array_add(meterValues, meterValue);
  10134. }
  10135. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10136. }
  10137. random_uuid(guid);
  10138. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  10139. json_object_put(TransactionEvent);
  10140. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  10141. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  10142. {
  10143. result = PASS;
  10144. }
  10145. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  10146. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10147. OCPP_insert_transaction_msg(YES, message);
  10148. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10149. {
  10150. OCPP_insert_transaction_msg(NO, message);
  10151. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  10152. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  10153. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  10154. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  10155. }
  10156. return result;
  10157. }
  10158. //==========================================
  10159. // send confirm routine
  10160. //==========================================
  10161. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  10162. {
  10163. mtrace();
  10164. int result = FAIL;
  10165. char message[4096]={0};
  10166. json_object *CancelReservation = json_object_new_object();
  10167. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  10168. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  10169. sprintf(message,"[%d,\"%s\",%s]"
  10170. ,MESSAGE_TYPE_CALLRESULT
  10171. ,uuid
  10172. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  10173. json_object_put(CancelReservation);
  10174. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  10175. LWS_Send(message);
  10176. result = TRUE;
  10177. return result;
  10178. }
  10179. int sendCertificateSignedConfirmation(char *uuid)
  10180. {
  10181. mtrace();
  10182. int result = FAIL;
  10183. char message[4096]={0};
  10184. json_object *CertificateSigned = json_object_new_object();
  10185. json_object *statusInfo = json_object_new_object();
  10186. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  10187. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10188. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10189. {
  10190. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10191. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10192. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10193. }
  10194. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10195. sprintf(message,"[%d,\"%s\",%s]"
  10196. ,MESSAGE_TYPE_CALLRESULT
  10197. ,uuid
  10198. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10199. json_object_put(CertificateSigned);
  10200. LWS_Send(message);
  10201. result = TRUE;
  10202. return result;
  10203. }
  10204. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10205. {
  10206. mtrace();
  10207. int result = FAIL;
  10208. char message[4096]={0};
  10209. json_object *ChangeAvailability = json_object_new_object();
  10210. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10211. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10212. sprintf(message,"[%d,\"%s\",%s]"
  10213. ,MESSAGE_TYPE_CALLRESULT
  10214. ,uuid
  10215. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10216. json_object_put(ChangeAvailability);
  10217. LWS_Send(message);
  10218. result = TRUE;
  10219. return result;
  10220. }
  10221. int sendClearCacheConfirmation(char *uuid)
  10222. {
  10223. mtrace();
  10224. int result = FAIL;
  10225. char message[4096]={0};
  10226. json_object *ClearCache = json_object_new_object();
  10227. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10228. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10229. sprintf(message,"[%d,\"%s\",%s]"
  10230. ,MESSAGE_TYPE_CALLRESULT
  10231. ,uuid
  10232. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10233. json_object_put(ClearCache);
  10234. LWS_Send(message);
  10235. result = TRUE;
  10236. return result;
  10237. }
  10238. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10239. {
  10240. mtrace();
  10241. int result = FAIL;
  10242. char message[500]={0};
  10243. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10244. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10245. LWS_Send(message);
  10246. return result;
  10247. }
  10248. int sendClearDisplayMessageConfirmation(char *uuid)
  10249. {
  10250. mtrace();
  10251. int result = FAIL;
  10252. char message[4096]={0};
  10253. json_object *ClearDisplayMessage = json_object_new_object();
  10254. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10255. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10256. sprintf(message,"[%d,\"%s\",%s]"
  10257. ,MESSAGE_TYPE_CALLRESULT
  10258. ,uuid
  10259. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10260. json_object_put(ClearDisplayMessage);
  10261. LWS_Send(message);
  10262. result = TRUE;
  10263. return result;
  10264. }
  10265. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10266. {
  10267. mtrace();
  10268. int result = FAIL;
  10269. char message[4096]={0};
  10270. json_object *ClearVariableMonitoring = json_object_new_object();
  10271. json_object *clearMonitoringResults = json_object_new_array();
  10272. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10273. for(int idx=0;idx<variableQuantity;idx++)
  10274. {
  10275. json_object *clearMonitoringResult = json_object_new_object();
  10276. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10277. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10278. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10279. }
  10280. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10281. sprintf(message,"[%d,\"%s\",%s]"
  10282. ,MESSAGE_TYPE_CALLRESULT
  10283. ,uuid
  10284. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10285. json_object_put(ClearVariableMonitoring);
  10286. LWS_Send(message);
  10287. result = TRUE;
  10288. return result;
  10289. }
  10290. int sendCostUpdatedConfirmation(char *uuid)
  10291. {
  10292. mtrace();
  10293. int result = FAIL;
  10294. char message[4096]={0};
  10295. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10296. sprintf(message,"[%d,\"%s\",{}]"
  10297. ,MESSAGE_TYPE_CALLRESULT
  10298. ,uuid);
  10299. LWS_Send(message);
  10300. result = TRUE;
  10301. return result;
  10302. }
  10303. int sendCustomerInformationConfirmation(char *uuid)
  10304. {
  10305. mtrace();
  10306. int result = FAIL;
  10307. char message[4096]={0};
  10308. json_object *CustomerInformation = json_object_new_object();
  10309. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10310. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10311. sprintf(message,"[%d,\"%s\",%s]"
  10312. ,MESSAGE_TYPE_CALLRESULT
  10313. ,uuid
  10314. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10315. json_object_put(CustomerInformation);
  10316. LWS_Send(message);
  10317. result = TRUE;
  10318. return result;
  10319. }
  10320. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10321. {
  10322. mtrace();
  10323. int result = FAIL;
  10324. char message[4096]={0};
  10325. json_object *DataTransfer = json_object_new_object();
  10326. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10327. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10328. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10329. sprintf(message,"[%d,\"%s\",%s]"
  10330. ,MESSAGE_TYPE_CALLRESULT
  10331. ,uuid
  10332. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10333. json_object_put(DataTransfer);
  10334. LWS_Send(message);
  10335. result = TRUE;
  10336. return result;
  10337. }
  10338. int sendDeleteCertificateConfirmation(char *uuid)
  10339. {
  10340. mtrace();
  10341. int result = FAIL;
  10342. char message[4096]={0};
  10343. json_object *DeleteCertificate = json_object_new_object();
  10344. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10345. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10346. sprintf(message,"[%d,\"%s\",%s]"
  10347. ,MESSAGE_TYPE_CALLRESULT
  10348. ,uuid
  10349. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10350. json_object_put(DeleteCertificate);
  10351. LWS_Send(message);
  10352. result = TRUE;
  10353. return result;
  10354. }
  10355. int sendGetBaseReportConfirmation(char *uuid)
  10356. {
  10357. mtrace();
  10358. int result = FAIL;
  10359. char message[4096]={0};
  10360. json_object *GetBaseReport = json_object_new_object();
  10361. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10362. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10363. sprintf(message,"[%d,\"%s\",%s]"
  10364. ,MESSAGE_TYPE_CALLRESULT
  10365. ,uuid
  10366. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10367. json_object_put(GetBaseReport);
  10368. LWS_Send(message);
  10369. result = TRUE;
  10370. return result;
  10371. }
  10372. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10373. {
  10374. mtrace();
  10375. int result = FAIL;
  10376. char message[4096]={0};
  10377. json_object *GetChargingProfiles = json_object_new_object();
  10378. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10379. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10380. sprintf(message,"[%d,\"%s\",%s]"
  10381. ,MESSAGE_TYPE_CALLRESULT
  10382. ,uuid
  10383. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10384. json_object_put(GetChargingProfiles);
  10385. LWS_Send(message);
  10386. result = TRUE;
  10387. return result;
  10388. }
  10389. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  10390. {
  10391. mtrace();
  10392. int result = FAIL;
  10393. char message[4096]={0};
  10394. int CompositeScheduleIndex = 0;
  10395. json_object *GetCompositeSchedule = json_object_new_object();
  10396. json_object *schedule = json_object_new_object();
  10397. json_object *chargingSchedule = json_object_new_object();
  10398. json_object *chargingSchedulePeriod = json_object_new_array();
  10399. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10400. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10401. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  10402. json_object_object_add(schedule, "evseId", json_object_new_int(connectorIdInt));
  10403. if(nPeriod == 0)
  10404. {
  10405. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10406. {
  10407. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10408. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10409. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10410. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10411. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10412. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10413. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10414. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10415. uint8_t isNullSchedulePeriod = TRUE;
  10416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10417. {
  10418. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10419. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10420. {
  10421. json_object *Period = json_object_new_object();
  10422. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10423. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10424. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10425. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10426. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10427. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10428. json_object_array_add(chargingSchedulePeriod, Period);
  10429. isNullSchedulePeriod = FALSE;
  10430. }
  10431. }
  10432. if(isNullSchedulePeriod == TRUE)
  10433. {
  10434. json_object *Period = json_object_new_object();
  10435. json_object_object_add(Period, "startPeriod", json_object_new_int(0));
  10436. float limit = ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  10437. json_object_object_add(Period, "limit", json_object_new_double(limit));
  10438. json_object_array_add(chargingSchedulePeriod, Period);
  10439. }
  10440. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10441. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10442. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10443. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10444. }
  10445. }
  10446. else
  10447. {
  10448. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10449. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10450. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10451. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10452. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10453. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10454. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10455. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10456. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10457. {
  10458. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10459. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10460. {
  10461. json_object *Period = json_object_new_object();
  10462. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10463. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10464. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10465. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10466. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10467. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10468. json_object_array_add(chargingSchedulePeriod, Period);
  10469. }
  10470. }
  10471. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10472. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10473. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10474. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10475. }
  10476. sprintf(message,"[%d,\"%s\",%s]"
  10477. ,MESSAGE_TYPE_CALLRESULT
  10478. ,uuid
  10479. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10480. json_object_put(GetCompositeSchedule);
  10481. LWS_Send(message);
  10482. result = TRUE;
  10483. return result;
  10484. }
  10485. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10486. {
  10487. mtrace();
  10488. int result = FAIL;
  10489. char message[4096]={0};
  10490. json_object *GetGetDisplayMessages = json_object_new_object();
  10491. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10492. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10493. sprintf(message,"[%d,\"%s\",%s]"
  10494. ,MESSAGE_TYPE_CALLRESULT
  10495. ,uuid
  10496. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10497. json_object_put(GetGetDisplayMessages);
  10498. LWS_Send(message);
  10499. result = TRUE;
  10500. return result;
  10501. }
  10502. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10503. {
  10504. mtrace();
  10505. int result = FAIL;
  10506. char message[4096]={0};
  10507. json_object *GetInstalledCertificateIds = json_object_new_object();
  10508. json_object *certificateHashDataChains = json_object_new_array();
  10509. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10510. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10511. for(int idx=0;idx<certQuantity;idx++)
  10512. {
  10513. json_object *cert = json_object_new_object();
  10514. json_object *certificateHashData = json_object_new_object();
  10515. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10516. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10517. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10518. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10519. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10520. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10521. json_object_array_add(certificateHashDataChains, cert);
  10522. }
  10523. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10524. sprintf(message,"[%d,\"%s\",%s]"
  10525. ,MESSAGE_TYPE_CALLRESULT
  10526. ,uuid
  10527. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10528. json_object_put(GetInstalledCertificateIds);
  10529. LWS_Send(message);
  10530. result = TRUE;
  10531. return result;
  10532. }
  10533. int sendGetLocalListVersionConfirmation(char *uuid)
  10534. {
  10535. mtrace();
  10536. int result = FAIL;
  10537. char message[4096]={0};
  10538. json_object *GetLocalListVersion = json_object_new_object();
  10539. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10540. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10541. sprintf(message,"[%d,\"%s\",%s]"
  10542. ,MESSAGE_TYPE_CALLRESULT
  10543. ,uuid
  10544. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10545. json_object_put(GetLocalListVersion);
  10546. LWS_Send(message);
  10547. result = TRUE;
  10548. return result;
  10549. }
  10550. int sendGetLogConfirmation(char *uuid)
  10551. {
  10552. mtrace();
  10553. int result = FAIL;
  10554. char message[4096]={0};
  10555. json_object *GetLog = json_object_new_object();
  10556. DEBUG_INFO("sendGetLogConfirmation...\n");
  10557. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10558. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10559. sprintf(message,"[%d,\"%s\",%s]"
  10560. ,MESSAGE_TYPE_CALLRESULT
  10561. ,uuid
  10562. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10563. json_object_put(GetLog);
  10564. LWS_Send(message);
  10565. result = TRUE;
  10566. return result;
  10567. }
  10568. int sendGetMonitoringReportConfirmation(char *uuid)
  10569. {
  10570. mtrace();
  10571. int result = FAIL;
  10572. char message[4096]={0};
  10573. json_object *GetMonitoringReport = json_object_new_object();
  10574. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10575. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10576. sprintf(message,"[%d,\"%s\",%s]"
  10577. ,MESSAGE_TYPE_CALLRESULT
  10578. ,uuid
  10579. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10580. json_object_put(GetMonitoringReport);
  10581. LWS_Send(message);
  10582. result = TRUE;
  10583. return result;
  10584. }
  10585. int sendGetReportConfirmation(char *uuid)
  10586. {
  10587. mtrace();
  10588. int result = FAIL;
  10589. char message[4096]={0};
  10590. json_object *GetReport = json_object_new_object();
  10591. DEBUG_INFO("sendGetReportConfirmation...\n");
  10592. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10593. sprintf(message,"[%d,\"%s\",%s]"
  10594. ,MESSAGE_TYPE_CALLRESULT
  10595. ,uuid
  10596. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10597. json_object_put(GetReport);
  10598. LWS_Send(message);
  10599. result = TRUE;
  10600. return result;
  10601. }
  10602. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  10603. {
  10604. mtrace();
  10605. int result = FAIL;
  10606. char message[4096]={0};
  10607. json_object *GetTransactionStatus = json_object_new_object();
  10608. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10609. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  10610. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  10611. sprintf(message,"[%d,\"%s\",%s]"
  10612. ,MESSAGE_TYPE_CALLRESULT
  10613. ,uuid
  10614. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10615. json_object_put(GetTransactionStatus);
  10616. LWS_Send(message);
  10617. result = TRUE;
  10618. return result;
  10619. }
  10620. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10621. {
  10622. mtrace();
  10623. int result = FAIL;
  10624. char message[4096]={0};
  10625. json_object *GetVariables = json_object_new_object();
  10626. json_object *getVariableResults = json_object_new_array();
  10627. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10628. for(int idx=0;idx<variableQuantity;idx++)
  10629. {
  10630. json_object *variableResult = json_object_new_object();
  10631. json_object *component = json_object_new_object();
  10632. json_object *variable = json_object_new_object();
  10633. json_object *evse = json_object_new_object();
  10634. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10635. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10636. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10637. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10638. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10639. if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id > 0)
  10640. {
  10641. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10642. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10643. json_object_object_add(component, "evse", evse);
  10644. }
  10645. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10646. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10647. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10648. json_object_object_add(variableResult, "component", component);
  10649. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10650. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10651. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10652. json_object_object_add(variableResult, "variable", variable);
  10653. json_object_array_add(getVariableResults, variableResult);
  10654. }
  10655. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10656. sprintf(message,"[%d,\"%s\",%s]"
  10657. ,MESSAGE_TYPE_CALLRESULT
  10658. ,uuid
  10659. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10660. json_object_put(GetVariables);
  10661. LWS_Send(message);
  10662. result = TRUE;
  10663. return result;
  10664. }
  10665. int sendInstallCertificateConfirmation(char *uuid)
  10666. {
  10667. mtrace();
  10668. int result = FAIL;
  10669. char message[4096]={0};
  10670. json_object *InstallCertificate = json_object_new_object();
  10671. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10672. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10673. sprintf(message,"[%d,\"%s\",%s]"
  10674. ,MESSAGE_TYPE_CALLRESULT
  10675. ,uuid
  10676. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  10677. json_object_put(InstallCertificate);
  10678. LWS_Send(message);
  10679. result = TRUE;
  10680. return result;
  10681. }
  10682. int sendPublishFirmwareConfirmation(char *uuid)
  10683. {
  10684. mtrace();
  10685. int result = FAIL;
  10686. char message[4096]={0};
  10687. json_object *PublishFirmware = json_object_new_object();
  10688. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  10689. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  10690. sprintf(message,"[%d,\"%s\",%s]"
  10691. ,MESSAGE_TYPE_CALLRESULT
  10692. ,uuid
  10693. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  10694. json_object_put(PublishFirmware);
  10695. LWS_Send(message);
  10696. result = TRUE;
  10697. return result;
  10698. }
  10699. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  10700. {
  10701. mtrace();
  10702. int result = FAIL;
  10703. char message[4096]={0};
  10704. json_object *RemoteStartTransaction = json_object_new_object();
  10705. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  10706. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  10707. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  10708. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  10709. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  10710. sprintf(message,"[%d,\"%s\",%s]"
  10711. ,MESSAGE_TYPE_CALLRESULT
  10712. ,uuid
  10713. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  10714. json_object_put(RemoteStartTransaction);
  10715. LWS_Send(message);
  10716. result = TRUE;
  10717. return result;
  10718. }
  10719. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  10720. {
  10721. mtrace();
  10722. int result = FAIL;
  10723. char message[4096]={0};
  10724. json_object *RemoteStopTransaction = json_object_new_object();
  10725. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  10726. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  10727. sprintf(message,"[%d,\"%s\",%s]"
  10728. ,MESSAGE_TYPE_CALLRESULT
  10729. ,uuid
  10730. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  10731. json_object_put(RemoteStopTransaction);
  10732. LWS_Send(message);
  10733. result = TRUE;
  10734. return result;
  10735. }
  10736. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  10737. {
  10738. mtrace();
  10739. int result = FAIL;
  10740. char message[4096]={0};
  10741. json_object *ReserveNow = json_object_new_object();
  10742. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  10743. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  10744. sprintf(message,"[%d,\"%s\",%s]"
  10745. ,MESSAGE_TYPE_CALLRESULT
  10746. ,uuid
  10747. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  10748. json_object_put(ReserveNow);
  10749. LWS_Send(message);
  10750. result = TRUE;
  10751. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  10752. return result;
  10753. }
  10754. int sendResetConfirmation(char *uuid)
  10755. {
  10756. mtrace();
  10757. int result = FAIL;
  10758. char message[4096]={0};
  10759. json_object *Reset = json_object_new_object();
  10760. DEBUG_INFO("sendResetConfirmation...\n");
  10761. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  10762. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  10763. sprintf(message,"[%d,\"%s\",%s]"
  10764. ,MESSAGE_TYPE_CALLRESULT
  10765. ,uuid
  10766. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  10767. json_object_put(Reset);
  10768. LWS_Send(message);
  10769. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  10770. {
  10771. DB_updateBootType(BootReasonEnumType_RemoteReset);
  10772. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10773. }
  10774. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  10775. {
  10776. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  10777. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10778. }
  10779. result = TRUE;
  10780. return result;
  10781. }
  10782. int sendSendLocalListConfirmation(char *uuid)
  10783. {
  10784. mtrace();
  10785. int result = FAIL;
  10786. char message[4096]={0};
  10787. json_object *SendLocalList = json_object_new_object();
  10788. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  10789. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  10790. sprintf(message,"[%d,\"%s\",%s]"
  10791. ,MESSAGE_TYPE_CALLRESULT
  10792. ,uuid
  10793. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  10794. json_object_put(SendLocalList);
  10795. LWS_Send(message);
  10796. result = TRUE;
  10797. return result;
  10798. }
  10799. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  10800. {
  10801. mtrace();
  10802. int result = FAIL;
  10803. char message[4096]={0};
  10804. json_object *SetChargingProfile = json_object_new_object();
  10805. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  10806. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  10807. sprintf(message,"[%d,\"%s\",%s]"
  10808. ,MESSAGE_TYPE_CALLRESULT
  10809. ,uuid
  10810. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10811. json_object_put(SetChargingProfile);
  10812. LWS_Send(message);
  10813. result = TRUE;
  10814. return result;
  10815. }
  10816. int sendSetDisplayMessagesConfirmation(char *uuid)
  10817. {
  10818. mtrace();
  10819. int result = FAIL;
  10820. char message[4096]={0};
  10821. json_object *SetDisplayMessage = json_object_new_object();
  10822. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  10823. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  10824. sprintf(message,"[%d,\"%s\",%s]"
  10825. ,MESSAGE_TYPE_CALLRESULT
  10826. ,uuid
  10827. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10828. json_object_put(SetDisplayMessage);
  10829. LWS_Send(message);
  10830. result = TRUE;
  10831. return result;
  10832. }
  10833. int sendSetMonitoringBaseConfirmation(char *uuid)
  10834. {
  10835. mtrace();
  10836. int result = FAIL;
  10837. char message[4096]={0};
  10838. json_object *SetMonitoringBase = json_object_new_object();
  10839. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  10840. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  10841. sprintf(message,"[%d,\"%s\",%s]"
  10842. ,MESSAGE_TYPE_CALLRESULT
  10843. ,uuid
  10844. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  10845. json_object_put(SetMonitoringBase);
  10846. LWS_Send(message);
  10847. result = TRUE;
  10848. return result;
  10849. }
  10850. int sendSetMonitoringLevelConfirmation(char *uuid)
  10851. {
  10852. mtrace();
  10853. int result = FAIL;
  10854. char message[4096]={0};
  10855. json_object *SetMonitoringLevel = json_object_new_object();
  10856. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  10857. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  10858. sprintf(message,"[%d,\"%s\",%s]"
  10859. ,MESSAGE_TYPE_CALLRESULT
  10860. ,uuid
  10861. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  10862. json_object_put(SetMonitoringLevel);
  10863. LWS_Send(message);
  10864. result = TRUE;
  10865. return result;
  10866. }
  10867. int sendSetNetworkProfileConfirmation(char *uuid)
  10868. {
  10869. mtrace();
  10870. int result = FAIL;
  10871. char message[4096]={0};
  10872. json_object *SetNetworkProfile = json_object_new_object();
  10873. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  10874. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  10875. sprintf(message,"[%d,\"%s\",%s]"
  10876. ,MESSAGE_TYPE_CALLRESULT
  10877. ,uuid
  10878. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  10879. json_object_put(SetNetworkProfile);
  10880. LWS_Send(message);
  10881. result = TRUE;
  10882. return result;
  10883. }
  10884. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10885. {
  10886. mtrace();
  10887. int result = FAIL;
  10888. char message[4096]={0};
  10889. json_object *SetVariableMonitoring = json_object_new_object();
  10890. json_object *setMonitoringResults = json_object_new_array();
  10891. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  10892. for(int idx=0;idx<variableQuantity;idx++)
  10893. {
  10894. json_object *variableMonitorResult = json_object_new_object();
  10895. json_object *component = json_object_new_object();
  10896. json_object *variable = json_object_new_object();
  10897. json_object *evse = json_object_new_object();
  10898. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  10899. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  10900. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  10901. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  10902. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  10903. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  10904. json_object_object_add(component, "evse", evse);
  10905. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  10906. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  10907. json_object_object_add(variableMonitorResult, "component", component);
  10908. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  10909. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  10910. json_object_object_add(variableMonitorResult, "variable", variable);
  10911. json_object_array_add(setMonitoringResults, variableMonitorResult);
  10912. }
  10913. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  10914. sprintf(message,"[%d,\"%s\",%s]"
  10915. ,MESSAGE_TYPE_CALLRESULT
  10916. ,uuid
  10917. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10918. json_object_put(SetVariableMonitoring);
  10919. LWS_Send(message);
  10920. result = TRUE;
  10921. return result;
  10922. }
  10923. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  10924. {
  10925. mtrace();
  10926. int result = FAIL;
  10927. char message[4096]={0};
  10928. json_object *SetVariable = json_object_new_object();
  10929. json_object *setVariableResults = json_object_new_array();
  10930. DEBUG_INFO("sendSetVariableConfirmation...\n");
  10931. for(int idx=0;idx<variableQuantity;idx++)
  10932. {
  10933. json_object *variableResult = json_object_new_object();
  10934. json_object *component = json_object_new_object();
  10935. json_object *variable = json_object_new_object();
  10936. json_object *evse = json_object_new_object();
  10937. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  10938. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  10939. if(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id > 0)
  10940. {
  10941. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  10942. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  10943. json_object_object_add(component, "evse", evse);
  10944. }
  10945. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  10946. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance) > 0)
  10947. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  10948. json_object_object_add(variableResult, "component", component);
  10949. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  10950. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance)>0)
  10951. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  10952. json_object_object_add(variableResult, "variable", variable);
  10953. json_object_array_add(setVariableResults, variableResult);
  10954. }
  10955. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  10956. sprintf(message,"[%d,\"%s\",%s]"
  10957. ,MESSAGE_TYPE_CALLRESULT
  10958. ,uuid
  10959. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  10960. json_object_put(SetVariable);
  10961. LWS_Send(message);
  10962. result = TRUE;
  10963. return result;
  10964. }
  10965. int sendTriggerMessageConfirmation(char *uuid)
  10966. {
  10967. mtrace();
  10968. int result = FAIL;
  10969. char message[4096]={0};
  10970. json_object *TriggerMessage = json_object_new_object();
  10971. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  10972. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  10973. sprintf(message,"[%d,\"%s\",%s]",
  10974. MESSAGE_TYPE_CALLRESULT,
  10975. uuid,
  10976. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  10977. json_object_put(TriggerMessage);
  10978. LWS_Send(message);
  10979. result = TRUE;
  10980. return result;
  10981. }
  10982. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  10983. {
  10984. mtrace();
  10985. int result = FAIL;
  10986. char message[4096]={0};
  10987. json_object *UnlockConnector = json_object_new_object();
  10988. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  10989. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  10990. sprintf(message,"[%d,\"%s\",%s]",
  10991. MESSAGE_TYPE_CALLRESULT,
  10992. uuid,
  10993. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  10994. json_object_put(UnlockConnector);
  10995. LWS_Send(message);
  10996. result = TRUE;
  10997. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  10998. return result;
  10999. }
  11000. int sendUnpublishFirmwareConfirmation(char *uuid)
  11001. {
  11002. mtrace();
  11003. int result = FAIL;
  11004. char message[4096]={0};
  11005. json_object *UnpublishFirmware = json_object_new_object();
  11006. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  11007. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  11008. sprintf(message,"[%d,\"%s\",%s]"
  11009. ,MESSAGE_TYPE_CALLRESULT
  11010. ,uuid
  11011. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  11012. json_object_put(UnpublishFirmware);
  11013. LWS_Send(message);
  11014. result = TRUE;
  11015. return result;
  11016. }
  11017. int sendUpdateFirmwareConfirmation(char *uuid)
  11018. {
  11019. mtrace();
  11020. int result = FAIL;
  11021. char message[4096]={0};
  11022. json_object *UpdateFirmware = json_object_new_object();
  11023. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  11024. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  11025. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  11026. sprintf(message,"[%d,\"%s\",%s]"
  11027. ,MESSAGE_TYPE_CALLRESULT
  11028. ,uuid
  11029. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  11030. json_object_put(UpdateFirmware);
  11031. LWS_Send(message);
  11032. result = TRUE;
  11033. return result;
  11034. }
  11035. int sendUnknownConfirmation(char *uuid)
  11036. {
  11037. mtrace();
  11038. int result = FAIL;
  11039. char message[256]={0};
  11040. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  11041. DEBUG_INFO("sendUnknownConfirmation...\n");
  11042. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  11043. LWS_Send(message);
  11044. result = TRUE;
  11045. return result;
  11046. }
  11047. //==========================================
  11048. // send CallError routine
  11049. //==========================================
  11050. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  11051. {
  11052. mtrace();
  11053. char message[220]={0};
  11054. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  11055. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  11056. LWS_Send(message);
  11057. }
  11058. //==========================================
  11059. // Handle server request routine Start
  11060. //==========================================
  11061. int handleCancelReservationRequest(char *uuid, char *payload)
  11062. {
  11063. mtrace();
  11064. int result = FAIL;
  11065. int gunNO = 0;
  11066. int reservationIdInt = -1;
  11067. DEBUG_INFO("handleCancelReservationRequest...\n");
  11068. json_object *CancelReservation;
  11069. CancelReservation = json_tokener_parse(payload);
  11070. if(!is_error(CancelReservation))
  11071. {
  11072. // Required data
  11073. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  11074. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  11075. }
  11076. json_object_put(CancelReservation);
  11077. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  11078. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  11079. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  11080. if(reservationIdInt != -1)
  11081. {
  11082. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11083. //check Transaction active
  11084. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  11085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11086. {
  11087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  11088. {
  11089. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11090. if(gunType[2] == GUN_TYPE_CHAdeMO)
  11091. {
  11092. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  11093. }
  11094. else
  11095. {
  11096. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  11097. }
  11098. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11099. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11100. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11101. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11102. goto end;
  11103. }
  11104. }
  11105. for (int index = 0; index < CCS_QUANTITY; index++)
  11106. {
  11107. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  11108. {
  11109. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11110. if(gunType[2] == GUN_TYPE_CCS)
  11111. {
  11112. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  11113. }
  11114. else
  11115. {
  11116. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  11117. }
  11118. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11119. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11120. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11121. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11122. goto end;
  11123. }
  11124. }
  11125. for (int index = 0; index < GB_QUANTITY; index++)
  11126. {
  11127. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  11128. {
  11129. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11130. if(gunType[2] == GUN_TYPE_GBT)
  11131. {
  11132. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  11133. }
  11134. else
  11135. {
  11136. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11137. }
  11138. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11139. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11140. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11141. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11142. goto end;
  11143. }
  11144. }
  11145. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11146. {
  11147. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  11148. {
  11149. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11150. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11151. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11152. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11153. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11154. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11155. goto end;
  11156. }
  11157. }
  11158. for (int index = 0; index < AC_QUANTITY; index++)
  11159. {
  11160. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  11161. {
  11162. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11164. {
  11165. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  11166. }
  11167. else
  11168. {
  11169. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  11170. }
  11171. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11172. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11173. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11174. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11175. goto end;
  11176. }
  11177. }
  11178. }
  11179. //The reservationId does NOT match the reservationId
  11180. sendCancelReservationConfirmation(uuid, gunNO);
  11181. end:
  11182. // Fill in ocpp packet uuid
  11183. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  11184. return result;
  11185. }
  11186. int handleCertificateSignedRequest(char *uuid, char *payload)
  11187. {
  11188. mtrace();
  11189. int result = FAIL;
  11190. json_object *CertificateSigned;
  11191. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11192. CertificateSigned = json_tokener_parse(payload);
  11193. if(!is_error(CertificateSigned))
  11194. {
  11195. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  11196. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  11197. // Required data
  11198. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  11199. // Optional data
  11200. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  11201. {
  11202. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  11203. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11204. {
  11205. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11206. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11207. fclose(fp);
  11208. }
  11209. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11210. {
  11211. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  11212. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11213. fclose(fp);
  11214. }
  11215. }
  11216. else
  11217. {
  11218. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11219. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11220. fclose(fp);
  11221. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  11222. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11223. fclose(fp);
  11224. }
  11225. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11226. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11227. }
  11228. else
  11229. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11230. json_object_put(CertificateSigned);
  11231. sendCertificateSignedConfirmation(uuid);
  11232. return result;
  11233. }
  11234. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11235. {
  11236. mtrace();
  11237. int result = FAIL;
  11238. int evseId = 0, gunIndex = 0;
  11239. char operationalStatus[16]={0};
  11240. char comfirmstr[20];
  11241. int specificId = FALSE;
  11242. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11243. json_object *ChangeAvailability;
  11244. ChangeAvailability = json_tokener_parse(payload);
  11245. if(!is_error(ChangeAvailability))
  11246. {
  11247. // Required data
  11248. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11249. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11250. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11251. {
  11252. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11253. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11254. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11255. }
  11256. }
  11257. json_object_put(ChangeAvailability);
  11258. if((evseId != 0) && (evseId <= gunTotalNumber))
  11259. {
  11260. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  11261. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11262. }
  11263. else if(evseId == 0)
  11264. {
  11265. for(int i=0; i < gunTotalNumber; i++)
  11266. {
  11267. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  11268. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11269. }
  11270. }
  11271. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11272. {
  11273. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  11274. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11275. }
  11276. else if(gunIndex == 0)
  11277. {
  11278. for(int i=0; i < gunTotalNumber; i++)
  11279. {
  11280. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  11281. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11282. }
  11283. }
  11284. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11285. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11286. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  11287. {
  11288. specificId = TRUE;
  11289. }
  11290. if(specificId == FALSE)
  11291. goto end;
  11292. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11293. {
  11294. //----------------------gunIndex is 0 ------------------------------------------------//
  11295. if(gunIndex == 0)
  11296. {
  11297. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11298. {
  11299. for(int i=0; i < gunTotalNumber; i++)
  11300. {
  11301. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11302. {
  11303. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11304. {
  11305. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11306. {
  11307. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11308. goto end;
  11309. }
  11310. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11311. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11312. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11313. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11314. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11315. {
  11316. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11317. goto end;
  11318. }
  11319. }
  11320. }//END FOR CHAdeMO_QUANTITY
  11321. for (int index = 0; index < CCS_QUANTITY; index++)
  11322. {
  11323. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11324. {
  11325. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11326. {
  11327. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11328. goto end;
  11329. }
  11330. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11331. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11332. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11333. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11334. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11335. {
  11336. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11337. goto end;
  11338. }
  11339. }
  11340. }//END FOR CCS_QUANTITY
  11341. for (int index = 0; index < GB_QUANTITY; index++)
  11342. {
  11343. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11344. {
  11345. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11346. {
  11347. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11348. goto end;
  11349. }
  11350. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11351. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11352. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11353. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11354. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11355. {
  11356. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11357. goto end;
  11358. }
  11359. }
  11360. }// END FOR GB_QUANTITY
  11361. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11362. {
  11363. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11364. {
  11365. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11366. {
  11367. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11368. goto end;
  11369. }
  11370. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11371. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11372. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11373. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11374. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11375. {
  11376. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11377. goto end;
  11378. }
  11379. }
  11380. }// END FOR DO_QUANTITY
  11381. for (int index = 0; index < AC_QUANTITY; index++)
  11382. {
  11383. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11384. {
  11385. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11386. {
  11387. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11388. goto end;
  11389. }
  11390. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11391. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11392. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11393. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11394. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11395. {
  11396. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11397. goto end;
  11398. }
  11399. }
  11400. }//END FOR AC_QUANTITY
  11401. }// END FOR gunTotalNumber
  11402. }
  11403. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11404. {
  11405. for(int i=0; i < gunTotalNumber; i++)
  11406. {
  11407. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11408. {
  11409. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11410. goto end;
  11411. }
  11412. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11413. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11414. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11415. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11416. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11417. {
  11418. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11419. goto end;
  11420. }
  11421. }
  11422. }
  11423. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11424. goto end;
  11425. }
  11426. //----------------------gunIndex is not 0 ------------------------------------------------//
  11427. //check Transaction active
  11428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11429. {
  11430. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  11431. {
  11432. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11433. {
  11434. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11435. goto end;
  11436. }
  11437. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11438. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11439. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11440. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11441. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11442. {
  11443. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11444. goto end;
  11445. }
  11446. else
  11447. {
  11448. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11449. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11450. goto end;
  11451. }
  11452. }
  11453. }//END FOR CHAdeMO_QUANTITY
  11454. for (int index = 0; index < CCS_QUANTITY; index++)
  11455. {
  11456. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  11457. {
  11458. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11459. {
  11460. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11461. goto end;
  11462. }
  11463. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11464. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11465. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11466. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11467. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11468. {
  11469. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11470. goto end;
  11471. }
  11472. else
  11473. {
  11474. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11475. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11476. goto end;
  11477. }
  11478. }
  11479. }//END FOR CCS_QUANTITY
  11480. for (int index = 0; index < GB_QUANTITY; index++)
  11481. {
  11482. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  11483. {
  11484. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11485. {
  11486. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11487. goto end;
  11488. }
  11489. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11490. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11491. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11492. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11493. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11494. {
  11495. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11496. goto end;
  11497. }
  11498. else
  11499. {
  11500. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11501. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11502. goto end;
  11503. }
  11504. }
  11505. }// END FOR GB_QUANTITY
  11506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11507. {
  11508. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  11509. {
  11510. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11511. {
  11512. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11513. goto end;
  11514. }
  11515. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11516. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11517. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11518. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11519. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11520. {
  11521. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11522. goto end;
  11523. }
  11524. else
  11525. {
  11526. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11527. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11528. goto end;
  11529. }
  11530. }
  11531. }// END FOR DO_QUANTITY
  11532. for (int index = 0; index < AC_QUANTITY; index++)
  11533. {
  11534. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  11535. {
  11536. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11537. {
  11538. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11539. goto end;
  11540. }
  11541. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11542. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11543. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11544. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11545. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11546. {
  11547. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11548. goto end;
  11549. }
  11550. else
  11551. {
  11552. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11553. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11554. goto end;
  11555. }
  11556. }
  11557. }//END FOR AC_QUANTITY
  11558. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11559. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11560. {
  11561. //----------------------gunIndex is 0 ------------------------------------------------//
  11562. if(gunIndex == 0)
  11563. {
  11564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11565. {
  11566. for(int i=0; i < gunTotalNumber; i++)
  11567. {
  11568. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11569. {
  11570. 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
  11571. {
  11572. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11573. goto end;
  11574. }
  11575. }//END FOR CHAdeMO_QUANTITY
  11576. for (int index = 0; index < CCS_QUANTITY; index++)
  11577. {
  11578. 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
  11579. {
  11580. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11581. goto end;
  11582. }
  11583. }//END FOR CCS_QUANTITY
  11584. for (int index = 0; index < GB_QUANTITY; index++)
  11585. {
  11586. 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
  11587. {
  11588. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11589. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11590. goto end;
  11591. }
  11592. }// END FOR GB_QUANTITY
  11593. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11594. {
  11595. 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
  11596. {
  11597. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11598. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11599. goto end;
  11600. }
  11601. }// END FOR DO_QUANTITY
  11602. for (int index = 0; index < AC_QUANTITY; index++)
  11603. {
  11604. 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
  11605. {
  11606. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11607. goto end;
  11608. }
  11609. }//END FOR CHAdeMO_QUANTITY
  11610. }// END FOR gunTotalNumber
  11611. }
  11612. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11613. {
  11614. for(int i=0; i < gunTotalNumber; i++)
  11615. {
  11616. for (int index = 0; index < AC_QUANTITY; index++)
  11617. {
  11618. 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
  11619. {
  11620. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11621. goto end;
  11622. }
  11623. }//END FOR CHAdeMO_QUANTITY
  11624. } // END FOR gunTotalNumber
  11625. }
  11626. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11627. goto end;
  11628. }
  11629. //----------------------gunIndex is not 0 ------------------------------------------------//
  11630. //check Transaction active
  11631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11632. {
  11633. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11634. {
  11635. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11636. goto end;
  11637. }
  11638. }//END FOR CHAdeMO_QUANTITY
  11639. for (int index = 0; index < CCS_QUANTITY; index++)
  11640. {
  11641. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11642. {
  11643. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11644. goto end;
  11645. }
  11646. }//END FOR CCS_QUANTITY
  11647. for (int index = 0; index < GB_QUANTITY; index++)
  11648. {
  11649. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11650. {
  11651. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11652. goto end;
  11653. }
  11654. }// END FOR GB_QUANTITY
  11655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11656. {
  11657. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11658. {
  11659. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11660. goto end;
  11661. }
  11662. }// END FOR DO_QUANTITY
  11663. for (int index = 0; index < AC_QUANTITY; index++)
  11664. {
  11665. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11666. {
  11667. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11668. goto end;
  11669. }
  11670. }//END FOR AC_QUANTITY
  11671. }//END FOR AvailabilityEnumTypeStr[Operative]
  11672. end:
  11673. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11674. {
  11675. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  11676. }
  11677. else
  11678. {
  11679. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  11680. }
  11681. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11682. {
  11683. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11684. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11685. }
  11686. else if(gunIndex == 0)
  11687. {
  11688. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11689. {
  11690. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  11691. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  11692. }
  11693. }
  11694. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  11695. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11696. return result;
  11697. }
  11698. int handleClearCacheRequest(char *uuid, char *payload)
  11699. {
  11700. mtrace();
  11701. int result = FAIL;
  11702. char rmFileCmd[100]={0};
  11703. struct stat stats;
  11704. DEBUG_INFO("handleClearCacheRequest...\n");
  11705. stat("/Storage/OCPP", &stats);
  11706. // Check for directory existence
  11707. if (S_ISDIR(stats.st_mode) == 1)
  11708. {}
  11709. else
  11710. {
  11711. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  11712. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  11713. system(rmFileCmd);
  11714. }
  11715. if(DB_cleanLocalCache() != PASS)
  11716. {
  11717. DEBUG_INFO("open AuthorizationCache file failed\n");
  11718. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  11719. }
  11720. else
  11721. {
  11722. DEBUG_INFO("open AuthorizationCache file successful\n");
  11723. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  11724. }
  11725. sendClearCacheConfirmation(uuid);
  11726. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11727. return result;
  11728. }
  11729. int handleClearChargingProfileRequest(char *uuid, char *payload)
  11730. {
  11731. mtrace();
  11732. int result = FAIL;
  11733. int resultRename;
  11734. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  11735. char chargingProfilePurposeStr[26]={0};
  11736. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  11737. char tempchargingProfilePurposeStr[26]={0};
  11738. char sstr[160]={0};
  11739. char str[100]={0};
  11740. int c = 0;
  11741. char *loc;
  11742. char fname[200]={0};
  11743. char comfirmstr[20]={0};
  11744. char word[1600]={0};
  11745. int clearflag = FALSE;
  11746. int chargingProfileIdIsNULL = FALSE;
  11747. int connectorIsNULL = FALSE;
  11748. int chargingProfilePurposeIsNULL = FALSE;
  11749. int stackLevelIsNULL = FALSE;
  11750. //int GotoEnd = FALSE;
  11751. FILE *fptr1, *fptr2;
  11752. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  11753. int n_chargingProfile=0;
  11754. int isEmptyFile = FALSE;
  11755. char sLineWord[1600]={0};
  11756. char chargingProfiles[10][100]={0};
  11757. int ChargeProfileCount = 0;
  11758. int ch;
  11759. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  11760. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  11761. json_object *ClearChargingProfile;
  11762. ClearChargingProfile = json_tokener_parse(payload);
  11763. if(!is_error(ClearChargingProfile))
  11764. {
  11765. // Optional data
  11766. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  11767. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  11768. else
  11769. chargingProfileIdIsNULL = TRUE;
  11770. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  11771. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  11772. else
  11773. connectorIsNULL = TRUE;
  11774. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  11775. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  11776. else
  11777. chargingProfilePurposeIsNULL = TRUE;
  11778. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  11779. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  11780. else
  11781. stackLevelIsNULL = TRUE;
  11782. }
  11783. json_object_put(ClearChargingProfile);
  11784. if(connectorIsNULL == FALSE)
  11785. {
  11786. switch(connectorIdInt)
  11787. {
  11788. case 0:
  11789. if(chargingProfilePurposeIsNULL == TRUE)
  11790. {
  11791. int l = 0;
  11792. strcpy(fname, ChargingStationMaxProfile_JSON);
  11793. if((access(fname,F_OK))!=-1)
  11794. {
  11795. strcpy(chargingProfiles[l], fname);
  11796. l = l + 1;
  11797. }
  11798. strcpy(fname, TxDefaultProfile_0_JSON);
  11799. if((access(fname,F_OK))!=-1)
  11800. {
  11801. strcpy(chargingProfiles[l], fname);
  11802. l = l + 1;
  11803. }
  11804. ChargeProfileCount = l;
  11805. }
  11806. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  11807. {
  11808. strcpy(fname, ChargingStationMaxProfile_JSON);
  11809. if((access(fname,F_OK))!=-1)
  11810. {
  11811. strcpy(chargingProfiles[0], fname);
  11812. ChargeProfileCount = 1;
  11813. }
  11814. }
  11815. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11816. {
  11817. strcpy(fname, TxDefaultProfile_0_JSON);
  11818. if((access(fname,F_OK))!=-1)
  11819. {
  11820. strcpy(chargingProfiles[0], fname);
  11821. ChargeProfileCount = 1;
  11822. }
  11823. }
  11824. break;
  11825. default:
  11826. if(chargingProfilePurposeIsNULL == TRUE)
  11827. {
  11828. int m = 0;
  11829. memset(fname, 0, ARRAY_SIZE(fname));
  11830. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11831. if((access(fname,F_OK))!=-1)
  11832. {
  11833. strcpy(chargingProfiles[m], fname);
  11834. m = m + 1;
  11835. }
  11836. memset(fname, 0, ARRAY_SIZE(fname));
  11837. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11838. if((access(fname,F_OK))!=-1)
  11839. {
  11840. strcpy(chargingProfiles[m], fname);
  11841. m = m + 1;
  11842. }
  11843. ChargeProfileCount = m;
  11844. }
  11845. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11846. {
  11847. //strcpy(fname, TxDefaultProfile_1_JSON);
  11848. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11849. if((access(fname,F_OK))!=-1)
  11850. {
  11851. strcpy(chargingProfiles[0], fname);
  11852. ChargeProfileCount = 1;
  11853. }
  11854. }
  11855. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  11856. {
  11857. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11858. if((access(fname,F_OK))!=-1)
  11859. {
  11860. strcpy(chargingProfiles[0], fname);
  11861. ChargeProfileCount = 1;
  11862. }
  11863. }
  11864. //strcpy(fname, ChargePointMaxProfile_JSON );
  11865. break;
  11866. }
  11867. }
  11868. else // Check all Charging Profiles
  11869. {
  11870. int i = 0;
  11871. char fnametemp[200]={0};
  11872. ChargeProfileCount = 0;
  11873. //Check ChargePointMaxProfile.json exit
  11874. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11875. {
  11876. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  11877. i = i + 1;
  11878. }
  11879. //Check TxDefaultProfile_%d.json
  11880. for(int j=1; j <= gunTotalNumber; j++)
  11881. {
  11882. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11883. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  11884. if((access(fnametemp,F_OK))!=-1)
  11885. {
  11886. strcpy(chargingProfiles[i], fnametemp);
  11887. i = i + 1;
  11888. }
  11889. }
  11890. //Check TxProfile_%d.json
  11891. for(int j=1; j <= gunTotalNumber; j++)
  11892. {
  11893. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11894. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  11895. if((access(fnametemp,F_OK))!=-1)
  11896. {
  11897. strcpy(chargingProfiles[i], fnametemp);
  11898. i = i + 1;
  11899. }
  11900. }
  11901. ChargeProfileCount = i;
  11902. }// End connectorIsNULL is TRUE
  11903. if(ChargeProfileCount == 0)
  11904. {
  11905. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11906. goto end;
  11907. }
  11908. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  11909. {
  11910. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11911. goto end;
  11912. }
  11913. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  11914. {
  11915. memset(str, 0, ARRAY_SIZE(str));
  11916. // clear temp file
  11917. sprintf(str,"rm -f %s",temp);
  11918. system(str);
  11919. for(int k=0; k < ChargeProfileCount; k++)
  11920. {
  11921. memset(str, 0, ARRAY_SIZE(str));
  11922. //clear file in C
  11923. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11924. system(str);
  11925. }
  11926. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11927. goto end;
  11928. }
  11929. else if(connectorIsNULL == TRUE)
  11930. {
  11931. for(int k=0; k < ChargeProfileCount; k++)
  11932. {
  11933. fptr1 = fopen(chargingProfiles[k], "r");
  11934. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  11935. //Check Charging Profile Count
  11936. while(fscanf(fptr1, "%s", word) != EOF)
  11937. {
  11938. //DEBUG_INFO("word=%s\n",word);
  11939. if(strstr(word, "id")!= NULL)
  11940. {
  11941. //DEBUG_INFO("test id \n");
  11942. n_chargingProfile = n_chargingProfile + 1;
  11943. //DEBUG_INFO("id Found\n");
  11944. }
  11945. }
  11946. rewind(fptr1);
  11947. //search Charging Profile Element
  11948. //int i= 0;
  11949. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11950. {
  11951. //------------------------tempconnectorIdInt------------------------//
  11952. loc = strstr(sLineWord, "connectorId");
  11953. c = 0;
  11954. memset(sstr ,0, sizeof(sstr) );
  11955. while (loc[strlen("connectorId")+2+c] != ',')
  11956. {
  11957. sstr[c] = loc[strlen("connectorId")+2+c];
  11958. c++;
  11959. }
  11960. sstr[c] = '\0';
  11961. tempconnectorIdInt = atoi(sstr);
  11962. printf("file's gun number is %d\n", tempconnectorIdInt);
  11963. //--------------------------id--------------------//
  11964. c = 0;
  11965. loc = strstr(sLineWord, "id");
  11966. memset(sstr ,0, ARRAY_SIZE(sstr));
  11967. while (loc[strlen("id")+2+c] != ',')
  11968. {
  11969. sstr[c] = loc[strlen("id")+2+c];
  11970. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11971. c++;
  11972. }
  11973. sstr[c] = '\0';
  11974. tempchargingProfileIdInt = atoi(sstr);
  11975. //stackLevel
  11976. c = 0;
  11977. loc = strstr(sLineWord, "stackLevel");
  11978. memset(sstr ,0, ARRAY_SIZE(sstr));
  11979. while (loc[strlen("stackLevel")+2+c] != ',')
  11980. {
  11981. sstr[c] = loc[strlen("stackLevel")+2+c];
  11982. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11983. c++;
  11984. }
  11985. sstr[c] = '\0';
  11986. tempstackLevelInt = atoi(sstr);
  11987. c = 0;
  11988. loc = strstr(sLineWord, "chargingProfilePurpose");
  11989. memset(sstr ,0, ARRAY_SIZE(sstr));
  11990. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11991. {
  11992. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11993. c++;
  11994. }
  11995. sstr[c] = '\0';
  11996. strcpy(tempchargingProfilePurposeStr, sstr);
  11997. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  11998. {
  11999. //------- not write to fptr2-------//
  12000. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12001. //clearflag = TRUE;
  12002. }
  12003. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  12004. {
  12005. //------- not write to fptr2-------//
  12006. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12007. }
  12008. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12009. {
  12010. //------- not write to fptr2-------//
  12011. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12012. }
  12013. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  12014. {
  12015. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12016. }
  12017. else
  12018. {
  12019. fprintf(fptr2, sLineWord);//writing data into file
  12020. }
  12021. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12022. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12023. if(clearflag == TRUE)
  12024. {
  12025. fclose(fptr1);
  12026. fclose(fptr2);
  12027. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12028. system(str);
  12029. // clear temp file
  12030. sprintf(str,"rm -f %s",temp);
  12031. system(str);
  12032. }
  12033. else
  12034. {
  12035. fclose(fptr1);
  12036. fclose(fptr2);
  12037. memset(str, 0, ARRAY_SIZE(str));
  12038. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12039. system(str);
  12040. resultRename = rename(temp, chargingProfiles[k]);
  12041. if(resultRename == 0)
  12042. {
  12043. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  12044. }
  12045. else
  12046. {
  12047. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  12048. }
  12049. if(comfirmstr[0]== 0)
  12050. {
  12051. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12052. }
  12053. //Check chargingProfile is empty file
  12054. /*------ Read the file ----------------*/
  12055. fptr1=fopen(chargingProfiles[k],"r");
  12056. ch=fgetc(fptr1);
  12057. rewind(fptr1);
  12058. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12059. if(ch!=EOF)
  12060. {
  12061. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12062. {
  12063. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12064. if(sLineWord[0]=='\0')
  12065. {
  12066. isEmptyFile = TRUE;
  12067. break;
  12068. }
  12069. else
  12070. {
  12071. isEmptyFile = FALSE;
  12072. break;
  12073. }
  12074. }
  12075. }
  12076. else
  12077. isEmptyFile = TRUE;
  12078. fclose(fptr1);
  12079. if(isEmptyFile == TRUE)
  12080. {
  12081. memset(str, 0, ARRAY_SIZE(str));
  12082. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12083. system(str);
  12084. }
  12085. }
  12086. }// End of while(int k=0; k < ChargePointCount; k++)
  12087. }
  12088. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  12089. {
  12090. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  12091. for(int k=0; k < ChargeProfileCount; k++)
  12092. {
  12093. fptr1 = fopen(chargingProfiles[k], "r");
  12094. fptr2 = fopen(temp, "w+");
  12095. //Check Charging Profile Count
  12096. while(fscanf(fptr1, "%s", word) != EOF)
  12097. {
  12098. //DEBUG_INFO("word=%s\n",word);
  12099. if(strstr(word, "id")!= NULL)
  12100. {
  12101. n_chargingProfile = n_chargingProfile + 1;
  12102. }
  12103. }
  12104. rewind(fptr1);
  12105. //search Charging Profile Element
  12106. //int i= 0;
  12107. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12108. {
  12109. //*************************tempconnectorIdInt*********************************/
  12110. loc = strstr(sLineWord, "connectorId");
  12111. c = 0;
  12112. memset(sstr ,0, ARRAY_SIZE(sstr));
  12113. while (loc[strlen("connectorId")+2+c] != ',')
  12114. {
  12115. sstr[c] = loc[strlen("connectorId")+2+c];
  12116. c++;
  12117. }
  12118. sstr[c] = '\0';
  12119. tempconnectorIdInt = atoi(sstr);
  12120. //id
  12121. c = 0;
  12122. loc = strstr(sLineWord, "id");
  12123. memset(sstr ,0, ARRAY_SIZE(sstr));
  12124. while (loc[strlen("id")+2+c] != ',')
  12125. {
  12126. sstr[c] = loc[strlen("id")+2+c];
  12127. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12128. c++;
  12129. }
  12130. sstr[c] = '\0';
  12131. tempchargingProfileIdInt = atoi(sstr);
  12132. //stackLevel
  12133. c = 0;
  12134. loc = strstr(sLineWord, "stackLevel");
  12135. memset(sstr ,0, ARRAY_SIZE(sstr));
  12136. while (loc[strlen("stackLevel")+2+c] != ',')
  12137. {
  12138. sstr[c] = loc[strlen("stackLevel")+2+c];
  12139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12140. c++;
  12141. }
  12142. sstr[c] = '\0';
  12143. tempstackLevelInt = atoi(sstr);
  12144. c = 0;
  12145. loc = strstr(sLineWord, "chargingProfilePurpose");
  12146. memset(sstr ,0, ARRAY_SIZE(sstr));
  12147. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12148. {
  12149. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12150. c++;
  12151. }
  12152. sstr[c] = '\0';
  12153. strcpy(tempchargingProfilePurposeStr, sstr);
  12154. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12155. {
  12156. //------- not write to fptr2-------//
  12157. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12158. //clearflag = TRUE;
  12159. }
  12160. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12161. {
  12162. //------- not write to fptr2-------//
  12163. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12164. }
  12165. else if(stackLevelIsNULL == TRUE)
  12166. {
  12167. //Clear Whole File
  12168. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12169. clearflag = TRUE;
  12170. break;
  12171. }
  12172. else
  12173. {
  12174. fprintf(fptr2, sLineWord);//writing data into file
  12175. }
  12176. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12177. }
  12178. if(clearflag == TRUE)
  12179. {
  12180. fclose(fptr1);
  12181. fclose(fptr2);
  12182. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12183. system(str);
  12184. // clear temp file
  12185. sprintf(str,"rm -f %s",temp);
  12186. system(str);
  12187. }
  12188. else
  12189. {
  12190. fclose(fptr1);
  12191. fclose(fptr2);
  12192. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12193. system(str);
  12194. resultRename = rename(temp, chargingProfiles[k]);
  12195. if(resultRename == 0)
  12196. {
  12197. DEBUG_INFO("File ChargingProfile renamed successfully");
  12198. }
  12199. else
  12200. {
  12201. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  12202. }
  12203. if(comfirmstr[0]== 0)
  12204. {
  12205. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12206. }
  12207. //Check chargingProfile is empty file
  12208. /*------ Read the file ----------------*/
  12209. fptr1=fopen(chargingProfiles[k],"r");
  12210. ch=fgetc(fptr1);
  12211. rewind(fptr1);
  12212. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12213. if(ch!=EOF)
  12214. {
  12215. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12216. {
  12217. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12218. if(sLineWord[0]=='\0')
  12219. {
  12220. isEmptyFile = TRUE;
  12221. break;
  12222. }
  12223. else
  12224. {
  12225. isEmptyFile = FALSE;
  12226. break;
  12227. }
  12228. }
  12229. }
  12230. else
  12231. isEmptyFile = TRUE;
  12232. fclose(fptr1);
  12233. if(isEmptyFile == TRUE)
  12234. {
  12235. memset(str, 0, ARRAY_SIZE(str));
  12236. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12237. system(str);
  12238. }
  12239. /*------- End of reading ---------------*/
  12240. }
  12241. } // while(int k=0; k < ChargeProfileCount; k++)
  12242. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12243. end:
  12244. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12245. {
  12246. if(connectorIdInt == 0)
  12247. {
  12248. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12249. {
  12250. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12251. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12252. }
  12253. }
  12254. else
  12255. {
  12256. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12257. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  12258. }
  12259. }
  12260. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12261. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12262. return result;
  12263. }
  12264. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12265. {
  12266. mtrace();
  12267. int result = FAIL;
  12268. json_object *ClearDisplayMessage;
  12269. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12270. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12271. ClearDisplayMessage = json_tokener_parse(payload);
  12272. if(!is_error(ClearDisplayMessage))
  12273. {
  12274. // Required data
  12275. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12276. {
  12277. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12278. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12279. }
  12280. }
  12281. json_object_put(ClearDisplayMessage);
  12282. sendCostUpdatedConfirmation(uuid);
  12283. return result;
  12284. }
  12285. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12286. {
  12287. mtrace();
  12288. int result = FAIL;
  12289. json_object *ClearVariableMonitorin;
  12290. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12291. ClearVariableMonitorin = json_tokener_parse(payload);
  12292. if(!is_error(ClearVariableMonitorin))
  12293. {
  12294. // Required data
  12295. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12296. {
  12297. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  12298. {
  12299. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  12300. /*
  12301. * TODO:
  12302. * 1. Check response
  12303. */
  12304. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12305. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12306. }
  12307. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  12308. }
  12309. }
  12310. json_object_put(ClearVariableMonitorin);
  12311. return result;
  12312. }
  12313. int handleCostUpdatedRequest(char *uuid, char *payload)
  12314. {
  12315. mtrace();
  12316. int result = FAIL;
  12317. json_object *CostUpdate;
  12318. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12319. CostUpdate = json_tokener_parse(payload);
  12320. if(!is_error(CostUpdate))
  12321. {
  12322. // Required data
  12323. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12324. {
  12325. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12326. }
  12327. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12328. {
  12329. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12330. }
  12331. }
  12332. json_object_put(CostUpdate);
  12333. sendCostUpdatedConfirmation(uuid);
  12334. return result;
  12335. }
  12336. int handleCustomerInformationRequest(char *uuid, char *payload)
  12337. {
  12338. mtrace();
  12339. int result = FAIL;
  12340. json_object *CustomerInformation;
  12341. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12342. CustomerInformation = json_tokener_parse(payload);
  12343. if(!is_error(CustomerInformation))
  12344. {
  12345. // Required data
  12346. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12347. {
  12348. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12349. }
  12350. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12351. {
  12352. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12353. }
  12354. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12355. {
  12356. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12357. }
  12358. // Optional data
  12359. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12360. {
  12361. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12362. {
  12363. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12364. }
  12365. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12366. {
  12367. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12368. }
  12369. }
  12370. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12371. {
  12372. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12373. {
  12374. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12375. }
  12376. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12377. {
  12378. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12379. }
  12380. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12381. {
  12382. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12383. }
  12384. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12385. {
  12386. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12387. }
  12388. }
  12389. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12390. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12391. }
  12392. else
  12393. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12394. json_object_put(CustomerInformation);
  12395. sendCustomerInformationConfirmation(uuid);
  12396. return result;
  12397. }
  12398. void createFirmwareVersionByDataTransfer(void)
  12399. {
  12400. json_object *FirmwareDataTransfer = json_object_new_object();
  12401. // AC & DC model
  12402. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12403. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12404. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12405. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12406. // DC model
  12407. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12408. {
  12409. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12410. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12411. (gunType[3] != GUN_TYPE_UNKNOWN))
  12412. {
  12413. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12414. }
  12415. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  12416. {
  12417. // DS DM DW
  12418. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12419. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12420. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12421. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12422. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12423. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12424. }
  12425. else
  12426. {
  12427. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12428. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12429. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12430. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12431. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12432. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12433. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12434. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12435. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12436. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12437. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12438. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12439. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12440. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12441. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12442. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12443. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12444. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12445. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12446. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12447. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12448. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12449. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12450. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12451. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12452. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12453. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12454. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12455. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12456. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12457. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12458. }
  12459. }
  12460. // 4G model
  12461. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12462. {
  12463. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12464. }
  12465. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12466. json_object_put(FirmwareDataTransfer);
  12467. }
  12468. int handleDataTransferRequest(char *uuid, char *payload)
  12469. {
  12470. mtrace();
  12471. int result = PASS;
  12472. DEBUG_INFO("handleDataTransferRequest...\n");
  12473. if((uuid != NULL) && (payload != NULL))
  12474. {
  12475. json_object *DataTransfer;
  12476. DataTransfer = json_tokener_parse(payload);
  12477. if(!is_error(DataTransfer))
  12478. {
  12479. // Required data
  12480. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12481. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12482. // Optional data
  12483. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12484. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12485. if(json_object_object_get(DataTransfer, "data") != NULL)
  12486. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12487. result = PASS;
  12488. }
  12489. json_object_put(DataTransfer);
  12490. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12491. {
  12492. // Send all moudle firmware version on EVSE
  12493. createFirmwareVersionByDataTransfer();
  12494. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12495. }
  12496. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12497. {
  12498. system("/usr/bin/run_tmate_restart.sh &");
  12499. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12500. }
  12501. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12502. {
  12503. json_object *data;
  12504. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12505. if(!is_error(data))
  12506. {
  12507. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  12508. {
  12509. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12510. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12511. if(json_object_object_get(data, "SOC") != NULL)
  12512. {
  12513. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12514. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12515. }
  12516. if(json_object_object_get(data, "Energy") != NULL)
  12517. {
  12518. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12519. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12520. }
  12521. if(json_object_object_get(data, "Duration") != NULL)
  12522. {
  12523. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12524. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12525. }
  12526. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12527. }
  12528. else
  12529. {
  12530. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12531. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12532. }
  12533. }
  12534. else
  12535. {
  12536. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12537. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12538. }
  12539. json_object_put(data);
  12540. }
  12541. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12542. {
  12543. json_object *data;
  12544. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12545. if(!is_error(data))
  12546. {
  12547. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12548. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12549. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12550. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12551. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12552. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12553. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12554. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12555. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12556. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12557. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12558. }
  12559. else
  12560. {
  12561. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12562. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12563. }
  12564. json_object_put(data);
  12565. }
  12566. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12567. {
  12568. json_object *data;
  12569. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12570. if(!is_error(data))
  12571. {
  12572. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12573. if(json_object_object_get(data, "Content_Type") != NULL)
  12574. {
  12575. 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))
  12576. {
  12577. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12578. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12579. {
  12580. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12581. }
  12582. }
  12583. else
  12584. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12585. }
  12586. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12587. }
  12588. else
  12589. {
  12590. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12591. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12592. }
  12593. json_object_put(data);
  12594. }
  12595. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12596. {
  12597. json_object *data;
  12598. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12599. if(!is_error(data))
  12600. {
  12601. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12602. if(json_object_object_get(data, "ConnectorId") != NULL)
  12603. {
  12604. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12605. }
  12606. if(json_object_object_get(data, "Page_Index") != NULL)
  12607. {
  12608. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  12609. }
  12610. if(json_object_object_get(data, "Duration") != NULL)
  12611. {
  12612. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  12613. }
  12614. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  12615. }
  12616. else
  12617. {
  12618. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12619. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12620. }
  12621. json_object_put(data);
  12622. }
  12623. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  12624. {
  12625. json_object *data;
  12626. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12627. if(!is_error(data))
  12628. {
  12629. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12630. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  12631. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  12632. {
  12633. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  12634. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  12635. else
  12636. {
  12637. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12638. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12639. }
  12640. }
  12641. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  12642. {
  12643. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  12644. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  12645. else
  12646. {
  12647. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12648. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12649. }
  12650. }
  12651. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  12652. {
  12653. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  12654. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  12655. else
  12656. {
  12657. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12658. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12659. }
  12660. }
  12661. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  12662. {
  12663. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  12664. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  12665. else
  12666. {
  12667. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12668. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12669. }
  12670. }
  12671. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  12672. {
  12673. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  12674. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  12675. else
  12676. {
  12677. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12678. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12679. }
  12680. }
  12681. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  12682. {
  12683. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  12684. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  12685. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  12686. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  12687. else
  12688. {
  12689. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12690. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12691. }
  12692. }
  12693. if(json_object_object_get(data, "isAuthentication") != NULL)
  12694. {
  12695. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  12696. {
  12697. case 0:
  12698. case 1:
  12699. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  12700. break;
  12701. default:
  12702. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12703. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12704. break;
  12705. }
  12706. }
  12707. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  12708. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12709. }
  12710. else
  12711. {
  12712. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12713. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12714. }
  12715. json_object_put(data);
  12716. }
  12717. else
  12718. {
  12719. // Can not find valid message id
  12720. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12721. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  12722. ,ShmOCPP20Data->DataTransfer[0].vendorId
  12723. ,ShmOCPP20Data->DataTransfer[0].messageId
  12724. ,ShmOCPP20Data->DataTransfer[0].data);
  12725. }
  12726. }
  12727. else
  12728. {
  12729. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12730. result = FAIL;
  12731. }
  12732. sendDataTransferConfirmation(uuid, 0);
  12733. return result;
  12734. }
  12735. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12736. {
  12737. mtrace();
  12738. int result = FAIL;
  12739. json_object *DeleteCertificate;
  12740. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12741. DeleteCertificate = json_tokener_parse(payload);
  12742. if(!is_error(DeleteCertificate))
  12743. {
  12744. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  12745. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  12746. // Required data
  12747. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  12748. {
  12749. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  12750. {
  12751. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12752. }
  12753. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  12754. {
  12755. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12756. }
  12757. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  12758. {
  12759. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12760. }
  12761. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  12762. {
  12763. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12764. }
  12765. /*
  12766. * TODO:
  12767. * 1. Delete certification and response
  12768. */
  12769. if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA256]) != NULL)
  12770. {
  12771. }
  12772. else if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA384]) != NULL)
  12773. {
  12774. }
  12775. else
  12776. {
  12777. }
  12778. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  12779. }
  12780. }
  12781. else
  12782. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  12783. json_object_put(DeleteCertificate);
  12784. sendDeleteCertificateConfirmation(uuid);
  12785. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12786. return result;
  12787. }
  12788. int handleGetBaseReportRequest(char *uuid, char *payload)
  12789. {
  12790. mtrace();
  12791. int result = FAIL;
  12792. json_object *GetBaseRepor;
  12793. DEBUG_INFO("handleGetBaseReportRequest...\n");
  12794. GetBaseRepor = json_tokener_parse(payload);
  12795. if(!is_error(GetBaseRepor))
  12796. {
  12797. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  12798. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  12799. // Required data
  12800. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  12801. {
  12802. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  12803. }
  12804. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  12805. {
  12806. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  12807. }
  12808. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  12809. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12810. else
  12811. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12812. }
  12813. else
  12814. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12815. json_object_put(GetBaseRepor);
  12816. sendGetBaseReportConfirmation(uuid);
  12817. return result;
  12818. }
  12819. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  12820. {
  12821. mtrace();
  12822. int result = FAIL;
  12823. int gun_index = -1;
  12824. json_object *GetChargingProfiles;
  12825. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  12826. GetChargingProfiles = json_tokener_parse(payload);
  12827. if(!is_error(GetChargingProfiles))
  12828. {
  12829. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  12830. {
  12831. 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;
  12832. }
  12833. if(gun_index >-1)
  12834. {
  12835. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  12836. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  12837. // Required data
  12838. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  12839. {
  12840. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  12841. }
  12842. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  12843. {
  12844. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  12845. {
  12846. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  12847. }
  12848. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  12849. {
  12850. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  12851. }
  12852. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  12853. {
  12854. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  12855. {
  12856. 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)));
  12857. }
  12858. }
  12859. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  12860. {
  12861. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  12862. {
  12863. 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));
  12864. }
  12865. }
  12866. }
  12867. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  12868. }
  12869. else
  12870. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  12871. }
  12872. json_object_put(GetChargingProfiles);
  12873. sendGetChargingProfilesConfirmation(uuid, gun_index);
  12874. return result;
  12875. }
  12876. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  12877. {
  12878. mtrace();
  12879. int result = FAIL;
  12880. int connectorIdInt, durationInt;
  12881. char chargingRateUnitStr[4]={0};
  12882. char comfirmstr[20];
  12883. int confirmPeriods = 0;
  12884. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  12885. json_object *GetCompositeSchedule;
  12886. GetCompositeSchedule = json_tokener_parse(payload);
  12887. if(!is_error(GetCompositeSchedule))
  12888. {
  12889. // Required data
  12890. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  12891. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  12892. else
  12893. connectorIdInt = -1;
  12894. if(json_object_object_get(GetCompositeSchedule, "duration"))
  12895. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  12896. else
  12897. durationInt = 86400;
  12898. // Optional data
  12899. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  12900. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  12901. }
  12902. json_object_put(GetCompositeSchedule);
  12903. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  12904. if((connectorIdInt == 0) ||
  12905. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  12906. {
  12907. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  12908. struct ChargingProfileType tmpProfile[1];
  12909. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  12910. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  12911. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  12912. {
  12913. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  12914. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, FALSE);
  12915. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  12916. }
  12917. else
  12918. {
  12919. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  12920. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, TRUE);
  12921. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  12922. }
  12923. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  12924. {
  12925. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  12926. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  12927. }
  12928. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct ChargingScheduleType));
  12929. strcpy((char *)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.startDateTime, (char *)tmpProfile[0].chargingSchedule[0].startSchedule);
  12930. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  12931. {
  12932. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  12933. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  12934. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  12935. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  12936. (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))
  12937. {
  12938. confirmPeriods = idx;
  12939. break;
  12940. }
  12941. }
  12942. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  12943. {
  12944. confirmPeriods += 1;
  12945. }
  12946. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12947. }
  12948. else
  12949. {
  12950. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  12951. }
  12952. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  12953. return result;
  12954. }
  12955. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  12956. {
  12957. mtrace();
  12958. int result = FAIL;
  12959. json_object *GetDisplayMessages;
  12960. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  12961. GetDisplayMessages = json_tokener_parse(payload);
  12962. if(!is_error(GetDisplayMessages))
  12963. {
  12964. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  12965. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  12966. // Required data
  12967. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  12968. {
  12969. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  12970. }
  12971. // Optional data
  12972. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  12973. {
  12974. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  12975. }
  12976. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  12977. {
  12978. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  12979. }
  12980. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  12981. {
  12982. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  12983. {
  12984. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  12985. }
  12986. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  12987. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  12988. }
  12989. else
  12990. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  12991. }
  12992. json_object_put(GetDisplayMessages);
  12993. return result;
  12994. }
  12995. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12996. {
  12997. mtrace();
  12998. int result = FAIL;
  12999. json_object *GetInstalledCertificateIds;
  13000. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13001. GetInstalledCertificateIds = json_tokener_parse(payload);
  13002. if(!is_error(GetInstalledCertificateIds))
  13003. {
  13004. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  13005. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  13006. // Optional data
  13007. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  13008. {
  13009. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  13010. {
  13011. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  13012. /*
  13013. * TODO:
  13014. * 1. Get installed certificate info for response
  13015. */
  13016. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GRootCertificate]) != NULL)
  13017. {
  13018. }
  13019. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_MORootCertificate]) != NULL)
  13020. {
  13021. }
  13022. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_CSMSRootCertificate]) != NULL)
  13023. {
  13024. }
  13025. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GCertificateChain]) != NULL)
  13026. {
  13027. }
  13028. else
  13029. {
  13030. }
  13031. }
  13032. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13033. }
  13034. else
  13035. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13036. }
  13037. json_object_put(GetInstalledCertificateIds);
  13038. sendInstallCertificateConfirmation(uuid);
  13039. return result;
  13040. }
  13041. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  13042. {
  13043. mtrace();
  13044. int result = FAIL;
  13045. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  13046. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  13047. {
  13048. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  13049. localversion = 0;
  13050. }
  13051. else
  13052. {
  13053. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  13054. localversion = 0;
  13055. DB_getListVerion();
  13056. }
  13057. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  13058. sendGetLocalListVersionConfirmation(uuid);
  13059. return result;
  13060. }
  13061. static char fnamePlusPath[100]={0};
  13062. static char fnamePWithNoPath[60]={0};
  13063. void checkUploadLog(void)
  13064. {
  13065. FILE *fp;
  13066. /* Open the command for reading. */
  13067. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  13068. if (fp == NULL) {
  13069. printf("Failed to run command\n" );
  13070. exit(1);
  13071. }
  13072. int ftppathlen = 0;
  13073. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  13074. int i = 0;
  13075. /* Read the output a line at a time - output it. */
  13076. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  13077. if(i==0)
  13078. {
  13079. ftppathlen = strlen(fnamePlusPath);
  13080. printf("%s\n", fnamePlusPath);
  13081. fnamePlusPath[ftppathlen]='\0';
  13082. break;
  13083. }
  13084. i= i+1;
  13085. }
  13086. /* close */
  13087. pclose(fp);
  13088. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  13089. {
  13090. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  13091. {
  13092. fnamePlusPath[k]='\0';
  13093. }
  13094. }
  13095. i=1;
  13096. //char fname[60]={0};
  13097. while(i < ftppathlen)
  13098. {
  13099. int len=ftppathlen-i;
  13100. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  13101. {
  13102. printf("compare '/' all right\n");
  13103. break;
  13104. }
  13105. i=i+1;
  13106. }
  13107. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  13108. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  13109. fnamePWithNoPath[i+1] = '\0';
  13110. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  13111. {
  13112. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  13113. {
  13114. fnamePWithNoPath[j]='\0';
  13115. }
  13116. }
  13117. FILE* fp1 = fopen(fnamePlusPath, "r");
  13118. if (fp1)
  13119. {
  13120. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  13121. // file exists
  13122. fclose(fp1);
  13123. }
  13124. else
  13125. {
  13126. // file doesn't exist
  13127. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  13128. }
  13129. }
  13130. void* GetLogProcess(void* data)
  13131. {
  13132. th_GetLog = pthread_self();
  13133. pthread_detach(pthread_self());
  13134. mtrace();
  13135. int requestId, retriesInt=0, retryIntervalInt=0;
  13136. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  13137. 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};
  13138. int port=0;
  13139. int isSuccess = FALSE;
  13140. char ftpbuf[1024]={0};
  13141. char cmdBuf[2048];
  13142. struct tm *tmNow;
  13143. time_t CurrentTime;
  13144. struct tm tmStart;
  13145. struct tm tmStop;
  13146. CurrentTime = time(NULL);
  13147. tmNow=localtime(&CurrentTime);
  13148. uint16_t targetYear, targetMonth;
  13149. json_object *GetLog;
  13150. DEBUG_INFO("GetGetProcess...\n");
  13151. GetLog = json_tokener_parse(data);
  13152. if(!is_error(GetLog))
  13153. {
  13154. // Required data
  13155. if(json_object_object_get(GetLog, "requestId") != NULL)
  13156. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13157. if(json_object_object_get(GetLog, "logType") != NULL)
  13158. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13159. if(json_object_object_get(GetLog, "log") != NULL)
  13160. {
  13161. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  13162. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13163. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13164. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13165. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13166. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13167. }
  13168. // Optional data
  13169. if(json_object_object_get(GetLog, "retries") != NULL)
  13170. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13171. else
  13172. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  13173. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13174. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13175. else
  13176. retryIntervalInt = 30;
  13177. }
  13178. json_object_put(GetLog);
  13179. ShmOCPP20Data->GetLog.requestId = requestId;
  13180. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  13181. {
  13182. /*
  13183. * TODO:
  13184. * 1. Pack security log
  13185. */
  13186. }
  13187. else
  13188. {
  13189. // Pack log to compress file
  13190. 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) &&
  13191. (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))
  13192. {
  13193. // Pack system log
  13194. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13195. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13196. targetYear = tmStart.tm_year;
  13197. targetMonth = tmStart.tm_mon;
  13198. do
  13199. {
  13200. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13201. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13202. if(targetMonth+1>=13)
  13203. {
  13204. targetYear += 1;
  13205. targetMonth = 1;
  13206. }
  13207. else
  13208. {
  13209. targetMonth += 1;
  13210. }
  13211. }while((targetYear < (tmNow->tm_year+1900)) ||
  13212. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13213. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13214. system(cmdBuf);
  13215. // Pack charging & event log
  13216. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13217. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13218. targetYear = tmStart.tm_year;
  13219. targetMonth = tmStart.tm_mon;
  13220. do
  13221. {
  13222. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13223. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  13224. if(targetMonth+1>=13)
  13225. {
  13226. targetYear += 1;
  13227. targetMonth = 1;
  13228. }
  13229. else
  13230. {
  13231. targetMonth += 1;
  13232. }
  13233. }while((targetYear < (tmNow->tm_year+1900)) ||
  13234. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13235. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13236. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13237. system(cmdBuf);
  13238. // Combine log file
  13239. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13240. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13241. }
  13242. else
  13243. {
  13244. system("exec /root/logPackTools 'log' 6");
  13245. }
  13246. }
  13247. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13248. system(cmdBuf);
  13249. checkUploadLog();
  13250. //****************location*******************/
  13251. if(strcmp(remoteLocation,"")==0)
  13252. {
  13253. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13254. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13255. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13256. goto end;
  13257. }
  13258. memset(protocol, 0, ARRAY_SIZE(protocol));
  13259. memset(user, 0, ARRAY_SIZE(user) );
  13260. memset(password, 0, ARRAY_SIZE(password));
  13261. memset(host, 0, ARRAY_SIZE(host));
  13262. memset(path, 0, ARRAY_SIZE(path));
  13263. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13264. memset(host1, 0, ARRAY_SIZE(host1));
  13265. memset(path1, 0, ARRAY_SIZE(path1));
  13266. /*location: ftp://user:password@host:port/path*/
  13267. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13268. if((access(fnamePlusPath,F_OK))!=-1)
  13269. {
  13270. DEBUG_INFO("fnamePlusPath exist.\n");
  13271. }
  13272. else
  13273. {
  13274. DEBUG_INFO("fnamePlusPath not exist!\n");
  13275. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13276. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13277. goto end;
  13278. }
  13279. if(strchr(remoteLocation,'@')==NULL)
  13280. {
  13281. sscanf(remoteLocation,
  13282. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13283. protocol, host, &port, path);
  13284. strcpy(user,"anonymous");
  13285. strcpy(password,"");
  13286. }
  13287. else
  13288. {
  13289. //DEBUG_INFO("pch=%s\n", pch);
  13290. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13291. protocol, user, password, host, &port, path);
  13292. }
  13293. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13294. {
  13295. DEBUG_INFO("protocol is not ftp/http ! \n");
  13296. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13297. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13298. goto end;
  13299. }
  13300. if(strncmp(remoteLocation,"http", 4) == 0)
  13301. {
  13302. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13303. sprintf(ftppath,"/%s", path);
  13304. do
  13305. {
  13306. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13307. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13308. sleep(3);
  13309. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  13310. if(!isSuccess)
  13311. {
  13312. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13313. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13314. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13315. sleep(retryIntervalInt);
  13316. }
  13317. else
  13318. {
  13319. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13320. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13321. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13322. }
  13323. retriesInt--;
  13324. }while((isSuccess == 0)&&(retriesInt >= 0));
  13325. }
  13326. else
  13327. {
  13328. sscanf(host,"%[^/]%s",host1, path1);
  13329. if(strlen(path) > 0)
  13330. sprintf(ftppath,"/%s", path);
  13331. else
  13332. sprintf(ftppath,"/%s", path1);
  13333. int ftppathlen=strlen(ftppath);
  13334. int i=1;
  13335. char filenametemp[50];
  13336. while(i < ftppathlen)
  13337. {
  13338. int len=ftppathlen-i;
  13339. if(ftppath[len]== 47) // '/' ascll code: 47
  13340. {
  13341. DEBUG_INFO("find '/' all right\n");
  13342. break;
  13343. }
  13344. i=i+1;
  13345. }
  13346. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13347. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13348. filenametemp[i+1] = 0;
  13349. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13350. if(port == 0)
  13351. port = 21;
  13352. do
  13353. {
  13354. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13355. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13356. sleep(3);
  13357. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  13358. if(!isSuccess)
  13359. {
  13360. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13361. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13362. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13363. sleep(retryIntervalInt);
  13364. }
  13365. else
  13366. {
  13367. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13368. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13369. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13370. }
  13371. retriesInt--;
  13372. }while((!isSuccess)&&(retriesInt >= 0));
  13373. }
  13374. end:
  13375. system("rm -f /mnt/*");
  13376. sleep(5);
  13377. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  13378. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13379. interLock.isGetLogGoing = OFF;
  13380. pthread_exit(NULL);
  13381. }
  13382. int handleGetLogRequest(char *uuid, char *payload)
  13383. {
  13384. mtrace();
  13385. int result = FAIL;
  13386. char fName[258];
  13387. time_t CurrentTime;
  13388. struct tm *tm;
  13389. pthread_t th_Status;
  13390. DEBUG_INFO("handleGetLogRequest...\n");
  13391. CurrentTime = time(NULL);
  13392. tm = localtime(&CurrentTime);
  13393. 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);
  13394. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  13395. if(interLock.isGetLogGoing)
  13396. {
  13397. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  13398. isCancelUploadLog = TRUE;
  13399. pthread_cancel(th_GetLog);
  13400. interLock.isGetLogGoing = OFF;
  13401. sleep(1);
  13402. isCancelUploadLog = OFF;
  13403. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_AcceptedCanceled]);
  13404. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13405. sleep(1);
  13406. }
  13407. else
  13408. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  13409. sendGetLogConfirmation(uuid);
  13410. if(!interLock.isGetLogGoing)
  13411. {
  13412. interLock.isGetLogGoing = ON;
  13413. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  13414. sleep(1);
  13415. }
  13416. else
  13417. {
  13418. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  13419. }
  13420. return result;
  13421. }
  13422. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  13423. {
  13424. mtrace();
  13425. int result = FAIL;
  13426. json_object *GetMonitoringReport;
  13427. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  13428. GetMonitoringReport = json_tokener_parse(payload);
  13429. if(!is_error(GetMonitoringReport))
  13430. {
  13431. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  13432. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  13433. // Required data
  13434. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  13435. {
  13436. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  13437. }
  13438. // Optional data
  13439. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  13440. {
  13441. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  13442. }
  13443. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  13444. {
  13445. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  13446. {
  13447. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  13448. {
  13449. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  13450. {
  13451. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  13452. {
  13453. 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")));
  13454. }
  13455. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13456. {
  13457. 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")));
  13458. }
  13459. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13460. {
  13461. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse"), "id") != NULL)
  13462. {
  13463. 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"));
  13464. }
  13465. 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)
  13466. {
  13467. 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"));
  13468. }
  13469. }
  13470. }
  13471. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  13472. {
  13473. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13474. {
  13475. 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")));
  13476. }
  13477. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13478. {
  13479. 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")));
  13480. }
  13481. }
  13482. }
  13483. }
  13484. }
  13485. }
  13486. json_object_put(GetMonitoringReport);
  13487. /*
  13488. * TODO:
  13489. * 1. Response result
  13490. */
  13491. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13492. sendGetMonitoringReportConfirmation(uuid);
  13493. return result;
  13494. }
  13495. int handleGetReportRequest(char *uuid, char *payload)
  13496. {
  13497. mtrace();
  13498. int result = FAIL;
  13499. json_object *GetReport;
  13500. DEBUG_INFO("handleGetReportRequest...\n");
  13501. GetReport = json_tokener_parse(payload);
  13502. if(!is_error(GetReport))
  13503. {
  13504. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  13505. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  13506. // Required data
  13507. if(json_object_object_get(GetReport, "requestId") != NULL)
  13508. {
  13509. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  13510. }
  13511. // Optional data
  13512. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  13513. {
  13514. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  13515. }
  13516. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  13517. {
  13518. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  13519. {
  13520. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  13521. {
  13522. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  13523. {
  13524. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  13525. {
  13526. 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")));
  13527. }
  13528. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13529. {
  13530. 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")));
  13531. }
  13532. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13533. {
  13534. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse"), "id") != NULL)
  13535. {
  13536. ShmOCPP20Data->GetReport.componentVariable[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse"), "id"));
  13537. }
  13538. 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)
  13539. {
  13540. ShmOCPP20Data->GetReport.componentVariable[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse"), "connectorId"));
  13541. }
  13542. }
  13543. }
  13544. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  13545. {
  13546. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13547. {
  13548. 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")));
  13549. }
  13550. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13551. {
  13552. 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")));
  13553. }
  13554. }
  13555. }
  13556. }
  13557. }
  13558. }
  13559. json_object_put(GetReport);
  13560. /*
  13561. * TODO:
  13562. * 1. Response result
  13563. */
  13564. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13565. sendGetReportConfirmation(uuid);
  13566. return result;
  13567. }
  13568. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  13569. {
  13570. mtrace();
  13571. int result = FAIL;
  13572. int8_t gun_index = -1;
  13573. json_object *GetTransactionStatus;
  13574. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  13575. GetTransactionStatus = json_tokener_parse(payload);
  13576. if(!is_error(GetTransactionStatus))
  13577. {
  13578. /*
  13579. * TODO:
  13580. * 1. Check transaction locate which connector
  13581. */
  13582. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  13583. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  13584. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  13585. {
  13586. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  13587. }
  13588. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  13589. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  13590. }
  13591. json_object_put(GetTransactionStatus);
  13592. sendGetTransactionStatusConfirmation(uuid, gun_index);
  13593. return result;
  13594. }
  13595. int handleGetVariablesRequest(char *uuid, char *payload)
  13596. {
  13597. mtrace();
  13598. int result = FAIL;
  13599. int isUnknownComponent = TRUE;
  13600. json_object *GetVariables;
  13601. DEBUG_INFO("handleGetVariablesRequest...\n");
  13602. GetVariables = json_tokener_parse(payload);
  13603. if(!is_error(GetVariables))
  13604. {
  13605. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  13606. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  13607. // Required data
  13608. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  13609. {
  13610. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  13611. {
  13612. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  13613. {
  13614. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  13615. {
  13616. 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")));
  13617. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  13618. }
  13619. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  13620. {
  13621. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  13622. }*/
  13623. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  13624. {
  13625. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  13626. {
  13627. 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")));
  13628. }
  13629. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  13630. {
  13631. 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")));
  13632. }
  13633. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  13634. {
  13635. 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)
  13636. {
  13637. 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"));
  13638. }
  13639. 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)
  13640. {
  13641. 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"));
  13642. }
  13643. }
  13644. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  13645. }
  13646. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  13647. {
  13648. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  13649. {
  13650. 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")));
  13651. }
  13652. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  13653. {
  13654. 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")));
  13655. }
  13656. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  13657. }
  13658. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  13659. {
  13660. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  13661. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  13662. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  13663. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  13664. {
  13665. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  13666. isUnknownComponent = FALSE;
  13667. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  13668. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  13669. {
  13670. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  13671. break;
  13672. }
  13673. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  13674. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  13675. {
  13676. struct sysinfo s_info;
  13677. int error = sysinfo(&s_info);
  13678. if(error != 0)
  13679. {
  13680. DEBUG_WARN("System uptime get error: %d\n", error);
  13681. }
  13682. else
  13683. {
  13684. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  13685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  13686. }
  13687. }
  13688. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  13689. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  13690. {
  13691. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  13692. }
  13693. else
  13694. {
  13695. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  13696. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  13697. }
  13698. break;
  13699. }
  13700. else
  13701. {
  13702. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  13703. {
  13704. isUnknownComponent = FALSE;
  13705. }
  13706. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  13707. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  13708. }
  13709. }
  13710. if(isUnknownComponent == TRUE)
  13711. {
  13712. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  13713. }
  13714. }
  13715. }
  13716. }
  13717. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  13718. }
  13719. json_object_put(GetVariables);
  13720. return result;
  13721. }
  13722. int handleInstallCertificateRequest(char *uuid, char *payload)
  13723. {
  13724. mtrace();
  13725. int result = FAIL;
  13726. json_object *InstallCertificate;
  13727. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13728. InstallCertificate = json_tokener_parse(payload);
  13729. if(!is_error(InstallCertificate))
  13730. {
  13731. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  13732. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  13733. // Required data
  13734. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  13735. {
  13736. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13737. }
  13738. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  13739. {
  13740. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13741. }
  13742. }
  13743. json_object_put(InstallCertificate);
  13744. /*
  13745. * TODO:
  13746. * 1. Install certification preocess and response
  13747. */
  13748. if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]))
  13749. {
  13750. }
  13751. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]))
  13752. {
  13753. }
  13754. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]))
  13755. {
  13756. }
  13757. else
  13758. {
  13759. }
  13760. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13761. sendInstallCertificateConfirmation(uuid);
  13762. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13763. return result;
  13764. }
  13765. int handlePublishFirmwareRequest(char *uuid, char *payload)
  13766. {
  13767. mtrace();
  13768. int result = FAIL;
  13769. json_object *PublishFirmware;
  13770. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  13771. PublishFirmware = json_tokener_parse(payload);
  13772. if(!is_error(PublishFirmware))
  13773. {
  13774. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  13775. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  13776. // Required data
  13777. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  13778. {
  13779. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  13780. }
  13781. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  13782. {
  13783. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  13784. }
  13785. // Optional data
  13786. if(json_object_object_get(PublishFirmware, "location") != NULL)
  13787. {
  13788. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  13789. }
  13790. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  13791. {
  13792. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  13793. }
  13794. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  13795. {
  13796. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  13797. }
  13798. }
  13799. json_object_put(PublishFirmware);
  13800. /*
  13801. * TODO:
  13802. * 1. Publish firmware preocess and response
  13803. */
  13804. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13805. sendPublishFirmwareConfirmation(uuid);
  13806. return result;
  13807. }
  13808. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  13809. {
  13810. mtrace();
  13811. int result = FAIL;
  13812. int8_t connectorIdx = -1;
  13813. uint8_t tempIndex;
  13814. uint8_t isOverConnectorMax = FALSE;
  13815. uint8_t isPeriodOverMax = FALSE;
  13816. uint8_t isTxProfile = TRUE;
  13817. uint8_t isAllowStart = TRUE;
  13818. uint8_t filename[128]={0};
  13819. char cmdBuf[128];
  13820. FILE *filePtr;
  13821. json_object *RemoteStartTransaction;
  13822. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  13823. RemoteStartTransaction = json_tokener_parse(payload);
  13824. if(!is_error(RemoteStartTransaction))
  13825. {
  13826. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  13827. {
  13828. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  13829. {
  13830. connectorIdx = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  13831. }
  13832. else
  13833. {
  13834. isOverConnectorMax = TRUE;
  13835. DEBUG_WARN("Connector id shall not equal 0 and less than max connector id.\n");
  13836. }
  13837. }
  13838. else
  13839. {
  13840. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13841. {
  13842. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  13843. {
  13844. connectorIdx = (idx+1);
  13845. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdx);
  13846. break;
  13847. }
  13848. }
  13849. }
  13850. if(isOverConnectorMax == FALSE)
  13851. {
  13852. if(connectorIdx > 0)
  13853. {
  13854. DEBUG_INFO("Connector id: %d\n", connectorIdx);
  13855. memset(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1], 0, sizeof(struct RequestStartTransaction_20));
  13856. memcpy(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid));
  13857. // Required data
  13858. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  13859. {
  13860. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  13861. }
  13862. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  13863. {
  13864. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  13865. {
  13866. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  13867. }
  13868. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  13869. {
  13870. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  13871. }
  13872. }
  13873. // Optional data
  13874. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  13875. {
  13876. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  13877. {
  13878. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  13879. }
  13880. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  13881. {
  13882. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  13883. }
  13884. }
  13885. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  13886. {
  13887. // Check periods is over max configuration
  13888. 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))
  13889. {
  13890. isPeriodOverMax = TRUE;
  13891. }
  13892. // Check profile purpose is TxProfile
  13893. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13894. {
  13895. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  13896. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  13897. }
  13898. else
  13899. {
  13900. isTxProfile = FALSE;
  13901. }
  13902. }
  13903. //check Transaction active
  13904. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  13905. {
  13906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13907. {
  13908. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13909. }
  13910. else
  13911. {
  13912. tempIndex = (connectorIdx-1);
  13913. }
  13914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13915. {
  13916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  13917. {
  13918. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13919. {
  13920. //Reserved
  13921. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  13922. }
  13923. 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[connectorIdx-1].idToken.idToken) != 0))
  13924. {
  13925. //Reserved
  13926. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  13927. isAllowStart = FALSE;
  13928. }
  13929. else
  13930. {
  13931. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13932. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  13933. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  13934. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  13935. {
  13936. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  13937. isAllowStart = FALSE;
  13938. }
  13939. }//END FOR ELSE
  13940. }
  13941. }// END FOR CHAdeMO_QUANTITY
  13942. }
  13943. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  13944. {
  13945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13946. {
  13947. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13948. }
  13949. else
  13950. {
  13951. tempIndex = (connectorIdx-1);
  13952. }
  13953. for (int index = 0; index < CCS_QUANTITY; index++)
  13954. {
  13955. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13956. {
  13957. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13958. {
  13959. //Reserved
  13960. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  13961. }
  13962. 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[connectorIdx-1].idToken.idToken) != 0))
  13963. {
  13964. //Reserved
  13965. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  13966. isAllowStart = FALSE;
  13967. }
  13968. else
  13969. {
  13970. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13971. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13972. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13973. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13974. {
  13975. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  13976. isAllowStart = FALSE;
  13977. }
  13978. }// END FOR ELSE
  13979. }
  13980. }// END FOR CCS_QUANTITY
  13981. }
  13982. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  13983. {
  13984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13985. {
  13986. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13987. }
  13988. else
  13989. {
  13990. tempIndex = (connectorIdx-1);
  13991. }
  13992. for (int index = 0; index < GB_QUANTITY; index++)
  13993. {
  13994. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  13995. {
  13996. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13997. {
  13998. //Reserved
  13999. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  14000. }
  14001. 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[connectorIdx-1].idToken.idToken) != 0))
  14002. {
  14003. //Reserved
  14004. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  14005. isAllowStart = FALSE;
  14006. }
  14007. else
  14008. {
  14009. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14010. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  14011. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  14012. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  14013. {
  14014. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  14015. isAllowStart = FALSE;
  14016. }
  14017. }// END FOR ELSE
  14018. }
  14019. } // END FOR GB_QUANTITY
  14020. }
  14021. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  14022. {
  14023. tempIndex = (connectorIdx-1);
  14024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14025. {
  14026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  14027. {
  14028. 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[connectorIdx-1].idToken.idToken) == 0))
  14029. {
  14030. //Reserved
  14031. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  14032. }
  14033. 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[connectorIdx-1].idToken.idToken) != 0))
  14034. {
  14035. //Reserved
  14036. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  14037. isAllowStart = FALSE;
  14038. }
  14039. else
  14040. {
  14041. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14042. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  14043. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  14044. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  14045. {
  14046. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  14047. isAllowStart = FALSE;
  14048. }
  14049. }// END FOR ELSE
  14050. }
  14051. } // END FOR GB_QUANTITY
  14052. }
  14053. else
  14054. {
  14055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14056. {
  14057. tempIndex = 2;
  14058. }
  14059. else
  14060. {
  14061. tempIndex = (connectorIdx-1);
  14062. }
  14063. for (int index = 0; index < AC_QUANTITY; index++)
  14064. {
  14065. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  14066. {
  14067. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  14068. {
  14069. //Reserved
  14070. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  14071. }
  14072. 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[connectorIdx-1].idToken.idToken) != 0))
  14073. {
  14074. //Reserved
  14075. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  14076. isAllowStart = FALSE;
  14077. }
  14078. else
  14079. {
  14080. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14081. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  14082. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  14083. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  14084. {
  14085. DEBUG_WARN("AC connector not allow start cause busy.\n");
  14086. isAllowStart = FALSE;
  14087. }
  14088. }//END FOR ELSE
  14089. }
  14090. }// END FOR AC_QUANTITY
  14091. }
  14092. }
  14093. else
  14094. {
  14095. DEBUG_INFO("Connector id does not specific.\n");
  14096. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14097. {
  14098. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  14099. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  14100. // Required data
  14101. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  14102. {
  14103. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  14104. }
  14105. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  14106. {
  14107. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  14108. {
  14109. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  14110. }
  14111. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  14112. {
  14113. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  14114. }
  14115. }
  14116. // Optional data
  14117. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  14118. {
  14119. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  14120. {
  14121. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  14122. }
  14123. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  14124. {
  14125. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  14126. }
  14127. }
  14128. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  14129. {
  14130. // Check periods is over max configuration
  14131. 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))
  14132. {
  14133. isPeriodOverMax = TRUE;
  14134. }
  14135. // Check profile purpose is TxProfile
  14136. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14137. {
  14138. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  14139. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14140. }
  14141. else
  14142. {
  14143. isTxProfile = FALSE;
  14144. }
  14145. }
  14146. }
  14147. }
  14148. }
  14149. // Profile replace or add info
  14150. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  14151. {
  14152. if(connectorIdx != -1)
  14153. {
  14154. if(strlen((char*)filename) > 0)
  14155. {
  14156. // Save profile to file
  14157. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  14158. system(cmdBuf);
  14159. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", connectorIdx);
  14160. filePtr = fopen((char*)filename, "w");
  14161. fprintf(filePtr, "{\"evseId\":%d,\"chargingProfile\":%s}\n", connectorIdx, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  14162. fclose(filePtr);
  14163. }
  14164. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  14165. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14166. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_transactionId);
  14167. result = PASS;
  14168. }
  14169. else
  14170. {
  14171. uint8_t isHasIdleConnector = FALSE;
  14172. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14173. {
  14174. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  14175. {
  14176. isHasIdleConnector = TRUE;
  14177. break;
  14178. }
  14179. }
  14180. if(isHasIdleConnector == TRUE)
  14181. {
  14182. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  14183. if(strlen((char*)filename) > 0)
  14184. {
  14185. // Save profile to file
  14186. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14187. system(cmdBuf);
  14188. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  14189. filePtr = fopen((char*)filename, "w");
  14190. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  14191. fclose(filePtr);
  14192. }
  14193. refreshStartTimer(&clientTime.RemoteStartWait);
  14194. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  14195. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14196. {
  14197. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14198. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  14199. }
  14200. result = PASS;
  14201. }
  14202. else
  14203. {
  14204. DEBUG_INFO("There is not any connector is idle.\n");
  14205. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14206. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14207. }
  14208. }
  14209. }
  14210. else
  14211. {
  14212. if(isOverConnectorMax != FALSE)
  14213. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  14214. if(isPeriodOverMax)
  14215. DEBUG_WARN("Profile periods quantity is over spec.\n");
  14216. if(!isTxProfile)
  14217. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  14218. if(!isAllowStart)
  14219. DEBUG_WARN("Target connector does not allow start.\n");
  14220. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((connectorIdx-1)<0?0:(connectorIdx-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  14221. }
  14222. }
  14223. json_object_put(RemoteStartTransaction);
  14224. sendRemoteStartTransactionConfirmation(uuid, ((connectorIdx-1)<0?0:(connectorIdx-1)));
  14225. return result;
  14226. }
  14227. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  14228. {
  14229. mtrace();
  14230. int result = FAIL;
  14231. int match = FALSE;
  14232. int GunNO = 0;
  14233. int tempIndex = 0;
  14234. char transactionIdStr[37];
  14235. int transactionIdIsNULL= TRUE;
  14236. json_object *RemoteStopTransaction;
  14237. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  14238. if(server_pending == TRUE)
  14239. {
  14240. return 0;
  14241. }
  14242. RemoteStopTransaction = json_tokener_parse(payload);
  14243. if(!is_error(RemoteStopTransaction))
  14244. {
  14245. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  14246. {
  14247. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  14248. transactionIdIsNULL = FALSE;
  14249. }
  14250. }
  14251. json_object_put(RemoteStopTransaction);
  14252. if(transactionIdIsNULL == FALSE)
  14253. {
  14254. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14255. {
  14256. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  14257. {
  14258. //check Transaction active
  14259. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14260. {
  14261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14262. {
  14263. tempIndex = ((gun_index==2) ? 1: 0);
  14264. }
  14265. else
  14266. {
  14267. tempIndex = gun_index;
  14268. }
  14269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14270. {
  14271. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14272. {
  14273. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14274. {
  14275. match = TRUE;
  14276. GunNO = gun_index;
  14277. }
  14278. }
  14279. }// END FOR CHAdeMO_QUANTITY
  14280. }
  14281. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14282. {
  14283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14284. {
  14285. tempIndex = ((gun_index==2) ? 1: 0);
  14286. }
  14287. else
  14288. {
  14289. tempIndex = gun_index;
  14290. }
  14291. for (int index = 0; index < CCS_QUANTITY; index++)
  14292. {
  14293. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14294. {
  14295. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14296. {
  14297. match = TRUE;
  14298. GunNO = gun_index;
  14299. }
  14300. }
  14301. }// END FOR CCS_QUANTITY
  14302. }
  14303. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14304. {
  14305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14306. {
  14307. tempIndex = ((gun_index==2) ? 1: 0);
  14308. }
  14309. else
  14310. {
  14311. tempIndex = gun_index;
  14312. }
  14313. for (int index = 0; index < GB_QUANTITY; index++)
  14314. {
  14315. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14316. {
  14317. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14318. {
  14319. match = TRUE;
  14320. GunNO = gun_index;
  14321. }
  14322. }
  14323. }// END FOR GB_QUANTITY
  14324. }
  14325. else if(gunType[gun_index] == GUN_TYPE_DO)
  14326. {
  14327. tempIndex = gun_index;
  14328. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14329. {
  14330. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14331. {
  14332. 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
  14333. {
  14334. match = TRUE;
  14335. GunNO = gun_index;
  14336. }
  14337. }
  14338. }// END FOR GB_QUANTITY
  14339. }
  14340. else
  14341. {
  14342. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14343. {
  14344. tempIndex = 2;
  14345. }
  14346. else
  14347. {
  14348. tempIndex = gun_index;
  14349. }
  14350. for (int index = 0; index < AC_QUANTITY; index++)
  14351. {
  14352. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14353. {
  14354. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14355. {
  14356. match = TRUE;
  14357. GunNO = gun_index;
  14358. }
  14359. }
  14360. }// END FOR CHAdeMO_QUANTITY
  14361. } // END FOR AC ELSE
  14362. }// CHECK IF ResponseTransactionId == transactionIdInt
  14363. }//END FOR
  14364. if( match == TRUE)
  14365. {
  14366. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  14367. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14368. }
  14369. else
  14370. {
  14371. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14372. }
  14373. }
  14374. else
  14375. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14376. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  14377. return result;
  14378. }
  14379. int handleReserveNowRequest(char *uuid, char *payload)
  14380. {
  14381. mtrace();
  14382. int result = FAIL;
  14383. int connectorIdInt=0, reservationIdInt=0;
  14384. int tempIndex = 0;
  14385. json_object *ReserveNow;
  14386. DEBUG_INFO("handleReserveNowRequest ...\n");
  14387. ReserveNow = json_tokener_parse(payload);
  14388. if(!is_error(ReserveNow))
  14389. {
  14390. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  14391. {
  14392. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  14393. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  14394. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  14395. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  14396. }
  14397. // Required data
  14398. if(json_object_object_get(ReserveNow, "id") != NULL)
  14399. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "id"));
  14400. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  14401. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  14402. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  14403. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  14404. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  14405. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  14406. // Optional data
  14407. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  14408. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  14409. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  14410. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  14411. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  14412. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  14413. result = PASS;
  14414. }
  14415. json_object_put(ReserveNow);
  14416. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14417. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  14418. {
  14419. //check Transaction active
  14420. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  14421. {
  14422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14423. {
  14424. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14425. }
  14426. else
  14427. {
  14428. tempIndex = connectorIdInt -1;
  14429. }
  14430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14431. {
  14432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14433. {
  14434. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  14435. {
  14436. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  14437. {
  14438. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14439. {
  14440. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  14441. {
  14442. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14443. }
  14444. else
  14445. {
  14446. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14447. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14448. }
  14449. }
  14450. 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'))
  14451. {
  14452. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14453. }
  14454. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14455. {
  14456. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14457. }
  14458. else
  14459. {
  14460. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14461. }
  14462. }
  14463. 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
  14464. {
  14465. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14466. }
  14467. }
  14468. else
  14469. {
  14470. //replace reservation
  14471. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14472. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14473. }
  14474. }
  14475. } // END FOR CHAdeMO_QUANTITY
  14476. }
  14477. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  14478. {
  14479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14480. {
  14481. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14482. }
  14483. else
  14484. {
  14485. tempIndex = connectorIdInt -1;
  14486. }
  14487. for (int index = 0; index < CCS_QUANTITY; index++)
  14488. {
  14489. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14490. {
  14491. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  14492. {
  14493. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14494. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  14495. {
  14496. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14497. {
  14498. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  14499. {
  14500. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14501. }
  14502. else
  14503. {
  14504. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14505. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14506. }
  14507. }
  14508. 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'))
  14509. {
  14510. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14511. }
  14512. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  14513. {
  14514. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14515. }
  14516. else
  14517. {
  14518. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14519. }
  14520. }
  14521. 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
  14522. {
  14523. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14524. }
  14525. }
  14526. else
  14527. {
  14528. //replace reservation
  14529. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14530. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14531. }
  14532. }
  14533. } // END FOR CCS_QUANTITY
  14534. }
  14535. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  14536. {
  14537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14538. {
  14539. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14540. }
  14541. else
  14542. {
  14543. tempIndex = connectorIdInt -1;
  14544. }
  14545. for (int index = 0; index < GB_QUANTITY; index++)
  14546. {
  14547. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14548. {
  14549. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  14550. {
  14551. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14552. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  14553. {
  14554. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14555. {
  14556. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  14557. {
  14558. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14559. }
  14560. else
  14561. {
  14562. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14563. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14564. }
  14565. }
  14566. 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'))
  14567. {
  14568. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14569. }
  14570. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14571. {
  14572. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14573. }
  14574. else
  14575. {
  14576. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14577. }
  14578. }
  14579. 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
  14580. {
  14581. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14582. }
  14583. }
  14584. else
  14585. {
  14586. //replace reservation
  14587. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14588. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14589. }
  14590. }
  14591. }// END FOR GB_QUANTITY
  14592. }
  14593. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  14594. {
  14595. tempIndex = connectorIdInt -1;
  14596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14597. {
  14598. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14599. {
  14600. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  14601. {
  14602. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14603. 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
  14604. {
  14605. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14606. {
  14607. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  14608. {
  14609. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14610. }
  14611. else
  14612. {
  14613. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14614. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14615. }
  14616. }
  14617. 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'))
  14618. {
  14619. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14620. }
  14621. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14622. {
  14623. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14624. }
  14625. else
  14626. {
  14627. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14628. }
  14629. }
  14630. 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
  14631. {
  14632. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14633. }
  14634. }
  14635. else
  14636. {
  14637. //replace reservation
  14638. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14639. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14640. }
  14641. }
  14642. }// END FOR DO_QUANTITY
  14643. }
  14644. else
  14645. {
  14646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14647. {
  14648. tempIndex = 2;
  14649. }
  14650. else
  14651. {
  14652. tempIndex = (connectorIdInt -1);
  14653. }
  14654. for (int index = 0; index < AC_QUANTITY; index++)
  14655. {
  14656. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14657. {
  14658. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  14659. {
  14660. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  14661. {
  14662. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14663. {
  14664. 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))
  14665. {
  14666. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14667. }
  14668. else
  14669. {
  14670. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14671. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14672. }
  14673. }
  14674. 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'))
  14675. {
  14676. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14677. }
  14678. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14679. {
  14680. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14681. }
  14682. else
  14683. {
  14684. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14685. }
  14686. }
  14687. 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
  14688. {
  14689. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14690. }
  14691. }
  14692. else
  14693. {
  14694. //replace reservation
  14695. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14696. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14697. }
  14698. }
  14699. } // END FOR AC_QUANTITY
  14700. }
  14701. }
  14702. else if(connectorIdInt == 0)
  14703. {
  14704. //check Transaction active
  14705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14706. {
  14707. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  14708. {
  14709. 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'))
  14710. {
  14711. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14712. goto end;
  14713. }
  14714. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14715. {
  14716. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14717. goto end;
  14718. }
  14719. 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
  14720. {
  14721. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14722. goto end;
  14723. }
  14724. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14725. {
  14726. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14727. goto end;
  14728. }
  14729. }
  14730. }// END FOR CHAdeMO_QUANTITY
  14731. for (int index = 0; index < CCS_QUANTITY; index++)
  14732. {
  14733. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  14734. {
  14735. 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'))
  14736. {
  14737. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14738. goto end;
  14739. }
  14740. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  14741. {
  14742. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14743. goto end;
  14744. }
  14745. 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
  14746. {
  14747. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14748. goto end;
  14749. }
  14750. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14751. {
  14752. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14753. goto end;
  14754. }
  14755. }
  14756. } // END FOR CCS_QUANTITY
  14757. for (int index = 0; index < GB_QUANTITY; index++)
  14758. {
  14759. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  14760. {
  14761. 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'))
  14762. {
  14763. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14764. goto end;
  14765. }
  14766. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14767. {
  14768. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14769. goto end;
  14770. }
  14771. 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
  14772. {
  14773. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14774. goto end;
  14775. }
  14776. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14777. {
  14778. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14779. goto end;
  14780. }
  14781. }
  14782. } // END FOR GB_QUANTITY
  14783. for (int index = 0; index < AC_QUANTITY; index++)
  14784. {
  14785. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  14786. {
  14787. 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'))
  14788. {
  14789. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14790. goto end;
  14791. }
  14792. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14793. {
  14794. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14795. goto end;
  14796. }
  14797. 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
  14798. {
  14799. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14800. goto end;
  14801. }
  14802. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14803. {
  14804. 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))
  14805. {
  14806. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14807. goto end;
  14808. }
  14809. }
  14810. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14811. {
  14812. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14813. goto end;
  14814. }
  14815. }
  14816. }// END FOR AC_QUANTITY
  14817. //The connectorId is 0
  14818. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  14819. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14820. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  14821. result = TRUE;
  14822. return result;
  14823. }
  14824. else
  14825. {
  14826. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14827. }
  14828. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  14829. {
  14830. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  14831. result = TRUE;
  14832. return result;
  14833. }
  14834. end:
  14835. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  14836. return result;
  14837. }
  14838. int handleResetRequest(char *uuid, char *payload)
  14839. {
  14840. mtrace();
  14841. int result = FAIL;
  14842. json_object *Reset = json_object_new_object();
  14843. DEBUG_INFO("handleResetRequest...\n");
  14844. Reset = json_tokener_parse(payload);
  14845. ShmOCPP20Data->Reset.evseId = 0;
  14846. if(!is_error(Reset))
  14847. {
  14848. // Required data
  14849. if(json_object_object_get(Reset, "type") != NULL)
  14850. {
  14851. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  14852. }
  14853. if(json_object_object_get(Reset, "evseId") != NULL)
  14854. {
  14855. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  14856. }
  14857. }
  14858. json_object_put(Reset);
  14859. if((ShmOCPP20Data->Reset.evseId == 0) && ((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0)))
  14860. {
  14861. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  14862. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  14863. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  14864. result = PASS;
  14865. }
  14866. else
  14867. {
  14868. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  14869. }
  14870. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  14871. sendResetConfirmation(uuid);
  14872. return result;
  14873. }
  14874. int handleSendLocalListRequest(char *uuid, char *payload)
  14875. {
  14876. mtrace();
  14877. int result = FAIL;
  14878. int checkState_Faulted = FALSE;
  14879. json_object *SendLocalList;
  14880. DEBUG_INFO("handleSendLocalListRequest...\n");
  14881. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  14882. {
  14883. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14884. goto end;
  14885. }
  14886. SendLocalList = json_tokener_parse(payload);
  14887. if(!is_error(SendLocalList))
  14888. {
  14889. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  14890. // Required data
  14891. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  14892. {
  14893. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  14894. }
  14895. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  14896. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  14897. // Optional data
  14898. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  14899. {
  14900. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  14901. {
  14902. // Required data
  14903. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  14904. {
  14905. 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")));
  14906. 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")));
  14907. }
  14908. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  14909. {
  14910. 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")));
  14911. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  14912. 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")));
  14913. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  14914. 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"));
  14915. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  14916. {
  14917. 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")));
  14918. 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")));
  14919. }
  14920. }
  14921. }
  14922. }
  14923. }
  14924. json_object_put(SendLocalList);
  14925. //check Charge Point state
  14926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14927. {
  14928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14929. {
  14930. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14931. }
  14932. }
  14933. for (int index = 0; index < CCS_QUANTITY; index++)
  14934. {
  14935. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14936. {
  14937. checkState_Faulted = TRUE; //OCPP Status
  14938. }
  14939. }
  14940. for (int index = 0; index < GB_QUANTITY; index++)
  14941. {
  14942. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14943. {
  14944. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14945. }
  14946. }
  14947. for (int index = 0; index < AC_QUANTITY; index++)
  14948. {
  14949. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14950. {
  14951. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14952. }
  14953. }
  14954. if(checkState_Faulted == TRUE)
  14955. {
  14956. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14957. goto end;
  14958. }
  14959. // Check update type
  14960. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  14961. {
  14962. //Local list full update
  14963. DEBUG_INFO("Local list full update.\n");
  14964. DB_getListVerion();
  14965. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  14966. {
  14967. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14968. goto end;
  14969. }*/
  14970. DB_cleanLocalList();
  14971. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  14972. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  14973. }
  14974. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  14975. {
  14976. //Local list different update
  14977. DEBUG_INFO("Local list different update.\n");
  14978. DB_getListVerion();
  14979. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  14980. {
  14981. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  14982. goto end;
  14983. }
  14984. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  14985. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  14986. }
  14987. else
  14988. {
  14989. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14990. goto end;
  14991. }
  14992. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  14993. end:
  14994. sendSendLocalListConfirmation(uuid);
  14995. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14996. return result;
  14997. }
  14998. int handleSetChargingProfileRequest(char *uuid, char *payload)
  14999. {
  15000. mtrace();
  15001. int result = FAIL;
  15002. struct SetChargingProfile_20 SetProfileReq = {0};
  15003. uint8_t isLostConnectorId = FALSE;
  15004. uint8_t isPeriodOverMax = FALSE;
  15005. uint8_t isStackOverMax = FALSE;
  15006. uint8_t isProfileOverMax = FALSE;
  15007. uint8_t isConnectorMismatch = FALSE;
  15008. uint8_t isTransactiodIdMismatch = FALSE;
  15009. uint8_t isInvalidLimit = FALSE;
  15010. uint8_t isWrongFormat = FALSE;
  15011. uint8_t replaceableProfileCnt = 0;
  15012. uint8_t existProfileQuantity = 0;
  15013. uint8_t filename[128]={0};
  15014. uint8_t dataLine[4096]={0};
  15015. FILE *filePtr;
  15016. json_object *SetChargingProfile;
  15017. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  15018. SetChargingProfile = json_tokener_parse(payload);
  15019. if(!is_error(SetChargingProfile))
  15020. {
  15021. // Required data
  15022. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  15023. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  15024. else
  15025. isLostConnectorId = TRUE;
  15026. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  15027. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  15028. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  15029. {
  15030. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15031. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15032. {
  15033. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  15034. }
  15035. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  15036. {
  15037. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15038. }
  15039. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  15040. {
  15041. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  15042. }
  15043. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  15044. {
  15045. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  15046. }
  15047. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  15048. {
  15049. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  15050. }
  15051. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  15052. {
  15053. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  15054. }
  15055. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  15056. {
  15057. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  15058. }
  15059. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  15060. {
  15061. int chargingScheduleCount = 0;
  15062. int chargingSchedulePeriodCount = 0;
  15063. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  15064. {
  15065. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  15066. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  15067. {
  15068. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  15069. {
  15070. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit, json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit")));
  15071. }
  15072. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  15073. {
  15074. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration"));
  15075. }
  15076. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  15077. {
  15078. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate"));
  15079. }
  15080. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  15081. {
  15082. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].startSchedule, json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule")));
  15083. }
  15084. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  15085. {
  15086. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"));
  15087. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  15088. {
  15089. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  15090. {
  15091. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  15092. {
  15093. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  15094. }
  15095. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  15096. {
  15097. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "limit"));
  15098. }
  15099. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  15100. {
  15101. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  15102. }
  15103. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "phaseToUse") != NULL)
  15104. {
  15105. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod"), idxPeriod), "phaseToUse"));
  15106. }
  15107. // Check invalid limit
  15108. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  15109. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  15110. {
  15111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  15112. {
  15113. if(((0 < SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit) && (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit < (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases)))) ||
  15114. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  15115. {
  15116. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  15117. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  15118. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  15119. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  15120. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  15121. isInvalidLimit = TRUE;
  15122. }
  15123. }
  15124. else
  15125. {
  15126. if((SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?1:220*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases)) > modelnameInfo.ratedPower) ||
  15127. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?1:220*(SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases)) < (modelnameInfo.ratedPower*0.01)))
  15128. {
  15129. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  15130. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  15131. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  15132. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  15133. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  15134. isInvalidLimit = TRUE;
  15135. }
  15136. }
  15137. }
  15138. }
  15139. }
  15140. else
  15141. {
  15142. isPeriodOverMax = TRUE;
  15143. }
  15144. }
  15145. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff") != NULL)
  15146. {
  15147. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "id") != NULL)
  15148. {
  15149. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "id"));
  15150. }
  15151. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffDescription") != NULL)
  15152. {
  15153. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffDescription, json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffDescription")));
  15154. }
  15155. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "numEPriceLevels") != NULL)
  15156. {
  15157. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.numEPriceLevels = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "numEPriceLevels"));
  15158. }
  15159. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry") != NULL)
  15160. {
  15161. int cntEntry = json_object_array_length(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"));
  15162. if(cntEntry<=1024)
  15163. {
  15164. for(int idxEntry=0; idxEntry<cntEntry; idxEntry++)
  15165. {
  15166. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel") != NULL)
  15167. {
  15168. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].ePriceLevel = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel"));
  15169. }
  15170. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval") != NULL)
  15171. {
  15172. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "start") != NULL)
  15173. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].relativeTimeInterval.start = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "start"));
  15174. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "duration") != NULL)
  15175. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].relativeTimeInterval.duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "relativeTimeInterval"), "duration"));
  15176. }
  15177. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost") != NULL)
  15178. {
  15179. uint8_t cntConCost = json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"));
  15180. if(cntConCost<=3)
  15181. {
  15182. for(uint8_t idxConCost=0; idxConCost<cntConCost; idxConCost++)
  15183. {
  15184. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "startValue") != NULL)
  15185. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].startValue = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"));
  15186. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost") != NULL)
  15187. {
  15188. uint8_t cntCost = json_object_array_length(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"));
  15189. if(cntConCost<=3)
  15190. {
  15191. for(uint8_t idxCost=0; idxCost<cntCost; idxCost++)
  15192. {
  15193. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "costKind") != NULL)
  15194. strcpy((char*)SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].costKind, json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "costKind")));
  15195. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amount") != NULL)
  15196. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].amount = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amount"));
  15197. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amountMultiplier") != NULL)
  15198. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].consumptionCost[idxConCost].cost[idxCost].amountMultiplier = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "consumptionCost"),idxConCost), "cost"), idxCost), "amountMultiplier"));
  15199. }
  15200. }
  15201. }
  15202. }
  15203. }
  15204. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].salesTariff.salesTariffEntry[idxEntry].ePriceLevel = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff"), "salesTariffEntry"),idxEntry), "ePriceLevel"));
  15205. }
  15206. }
  15207. }
  15208. }
  15209. }
  15210. }
  15211. }
  15212. else
  15213. {
  15214. isWrongFormat = TRUE;
  15215. }
  15216. }
  15217. // Check periods is over max configuration
  15218. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  15219. {
  15220. if(SetProfileReq.evseId == 0)
  15221. {
  15222. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  15223. filePtr = fopen((char*)filename, "r");
  15224. if (!filePtr)
  15225. {
  15226. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  15227. filePtr = fopen((char*)filename, "w+");
  15228. }
  15229. else
  15230. {
  15231. //Check Charging Profile Count
  15232. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15233. char *line = NULL;
  15234. size_t len = 0;
  15235. while(getline(&line, &len, filePtr) != -1)
  15236. {
  15237. json_object *obj = NULL;
  15238. obj = json_tokener_parse(line);
  15239. if(is_error(obj))
  15240. {
  15241. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  15242. }
  15243. else
  15244. {
  15245. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15246. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15247. {
  15248. existProfileQuantity += 1;
  15249. }
  15250. else
  15251. replaceableProfileCnt += 1;
  15252. }
  15253. //DEBUG_INFO("word=%s\n",word);
  15254. /*if(strstr((char*)dataLine, "id")!= NULL)
  15255. {
  15256. existProfileQuantity += 1;
  15257. }*/
  15258. }
  15259. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15260. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15261. {
  15262. isStackOverMax = TRUE;
  15263. }
  15264. }
  15265. fclose(filePtr);
  15266. }
  15267. else
  15268. isConnectorMismatch = TRUE;
  15269. }
  15270. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  15271. {
  15272. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  15273. isConnectorMismatch = TRUE;
  15274. if(!isConnectorMismatch)
  15275. {
  15276. if(SetProfileReq.evseId == 0)
  15277. {
  15278. int tmpExistProfileQuantity;
  15279. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  15280. {
  15281. tmpExistProfileQuantity = 0;
  15282. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15283. filePtr = fopen((char*)filename, "r");
  15284. if (!filePtr)
  15285. {
  15286. DEBUG_INFO("%s not exist, create it.\n", filename);
  15287. filePtr = fopen((char*)filename, "w+");
  15288. }
  15289. else
  15290. {
  15291. //Check Charging Profile Count
  15292. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15293. char *line = NULL;
  15294. size_t len = 0;
  15295. while(getline(&line, &len, filePtr) != -1)
  15296. {
  15297. json_object *obj = NULL;
  15298. obj = json_tokener_parse(line);
  15299. if(is_error(obj))
  15300. {
  15301. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  15302. }
  15303. else
  15304. {
  15305. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15306. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15307. {
  15308. tmpExistProfileQuantity += 1;
  15309. }
  15310. else
  15311. replaceableProfileCnt += 1;
  15312. }
  15313. //DEBUG_INFO("word=%s\n",word);
  15314. /*if(strstr((char*)dataLine, "id")!= NULL)
  15315. {
  15316. tmpExistProfileQuantity += 1;
  15317. }*/
  15318. }
  15319. }
  15320. fclose(filePtr);
  15321. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15322. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15323. {
  15324. isStackOverMax = TRUE;
  15325. }
  15326. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  15327. }
  15328. }
  15329. else
  15330. {
  15331. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15332. filePtr = fopen((char*)filename, "r");
  15333. if (!filePtr)
  15334. {
  15335. DEBUG_INFO("%s not exist, create it.\n", filename);
  15336. filePtr = fopen((char*)filename, "w+");
  15337. }
  15338. else
  15339. {
  15340. //Check Charging Profile Count
  15341. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15342. char *line = NULL;
  15343. size_t len = 0;
  15344. while(getline(&line, &len, filePtr) != -1)
  15345. {
  15346. json_object *obj = NULL;
  15347. obj = json_tokener_parse(line);
  15348. if(is_error(obj))
  15349. {
  15350. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  15351. }
  15352. else
  15353. {
  15354. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15355. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15356. {
  15357. existProfileQuantity += 1;
  15358. }
  15359. else
  15360. replaceableProfileCnt += 1;
  15361. }
  15362. //DEBUG_INFO("word=%s\n",word);
  15363. /*if(strstr((char*)dataLine, "id")!= NULL)
  15364. {
  15365. existProfileQuantity += 1;
  15366. }*/
  15367. }
  15368. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15369. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15370. {
  15371. isStackOverMax = TRUE;
  15372. }
  15373. }
  15374. fclose(filePtr);
  15375. }
  15376. }
  15377. }
  15378. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15379. {
  15380. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  15381. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15382. else
  15383. isConnectorMismatch = TRUE;
  15384. if(!isConnectorMismatch)
  15385. {
  15386. filePtr = fopen((char*)filename, "r");
  15387. if (!filePtr)
  15388. {
  15389. DEBUG_INFO("%s not exist, create it.\n", filename);
  15390. filePtr = fopen((char*)filename, "w+");
  15391. }
  15392. else
  15393. {
  15394. //Check Charging Profile Count
  15395. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15396. char *line = NULL;
  15397. size_t len = 0;
  15398. while(getline(&line, &len, filePtr) != -1)
  15399. {
  15400. json_object *obj = NULL;
  15401. obj = json_tokener_parse(line);
  15402. if(is_error(obj))
  15403. {
  15404. DEBUG_ERROR("Parse TxProfile from file error.\n");
  15405. }
  15406. else
  15407. {
  15408. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15409. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15410. {
  15411. existProfileQuantity += 1;
  15412. }
  15413. else
  15414. replaceableProfileCnt += 1;
  15415. }
  15416. //DEBUG_INFO("word=%s\n",word);
  15417. /*if(strstr((char*)dataLine, "id")!= NULL)
  15418. {
  15419. existProfileQuantity += 1;
  15420. }*/
  15421. }
  15422. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15423. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15424. {
  15425. isStackOverMax = TRUE;
  15426. }
  15427. }
  15428. fclose(filePtr);
  15429. if(SetProfileReq.chargingProfile.transactionId != ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId)
  15430. isTransactiodIdMismatch = TRUE;
  15431. }
  15432. }
  15433. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  15434. {
  15435. /*
  15436. * TODO:
  15437. *
  15438. */
  15439. }
  15440. else
  15441. {}
  15442. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  15443. {
  15444. FILE *fp;
  15445. char dataLine[4096]={0};
  15446. char fnametemp[128]={0};
  15447. int tmpProfileQuantity;
  15448. //Check ChargePointMaxProfile.json exit
  15449. existProfileQuantity = 0;
  15450. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  15451. {
  15452. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  15453. //Check Charging Profile Count
  15454. tmpProfileQuantity = 0;
  15455. while(fscanf(fp, "%s", dataLine) != EOF)
  15456. {
  15457. if(strstr(dataLine, "id")!= NULL)
  15458. {
  15459. existProfileQuantity += 1;
  15460. tmpProfileQuantity += 1;
  15461. }
  15462. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15463. }
  15464. fclose(fp);
  15465. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  15466. }
  15467. //Check TxDefaultProfile_%d.json
  15468. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  15469. {
  15470. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  15471. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15472. if((access(fnametemp,F_OK))!=-1)
  15473. {
  15474. fp = fopen(fnametemp, "r");
  15475. //Check Charging Profile Count
  15476. tmpProfileQuantity = 0;
  15477. while(fscanf(fp, "%s", dataLine) != EOF)
  15478. {
  15479. //DEBUG_INFO("word=%s\n",word);
  15480. if(strstr(dataLine, "id")!= NULL)
  15481. {
  15482. existProfileQuantity += 1;
  15483. tmpProfileQuantity += 1;
  15484. }
  15485. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15486. }
  15487. fclose(fp);
  15488. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  15489. }
  15490. }
  15491. //Check TxProfile_%d.json
  15492. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  15493. {
  15494. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  15495. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  15496. if((access(fnametemp,F_OK))!=-1)
  15497. {
  15498. fp = fopen(fnametemp, "r");
  15499. //Check Charging Profile Count
  15500. tmpProfileQuantity = 0;
  15501. while(fscanf(fp, "%s", dataLine) != EOF)
  15502. {
  15503. if(strstr(dataLine, "id")!= NULL)
  15504. {
  15505. existProfileQuantity += 1;
  15506. tmpProfileQuantity += 1;
  15507. }
  15508. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15509. }
  15510. fclose(fp);
  15511. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  15512. }
  15513. }
  15514. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  15515. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  15516. // To check total Profile quantity
  15517. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  15518. {
  15519. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  15520. isProfileOverMax = TRUE;
  15521. }
  15522. else
  15523. {
  15524. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  15525. isProfileOverMax = TRUE;
  15526. }
  15527. }
  15528. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  15529. }
  15530. // Profile replace or add info
  15531. if(!isLostConnectorId && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  15532. {
  15533. FILE *infile;
  15534. FILE *outfile;
  15535. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  15536. char rmFileCmd[128];
  15537. int tempchargingProfileIdInt;
  15538. int tempchargingProfileStackLevelInt;
  15539. int chkChar;
  15540. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  15541. {
  15542. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  15543. {
  15544. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  15545. }
  15546. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  15547. {
  15548. if(SetProfileReq.evseId==0)
  15549. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15550. else
  15551. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15552. }
  15553. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  15554. {
  15555. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15556. }
  15557. else
  15558. {
  15559. /*
  15560. * TODO:
  15561. *
  15562. */
  15563. }
  15564. infile = fopen ((char*)filename, "r");
  15565. outfile = fopen ((char*)tmpProfileName, "w");
  15566. chkChar = fgetc(infile);
  15567. rewind(infile);
  15568. if(chkChar == EOF)
  15569. {
  15570. // Profile is empty
  15571. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15572. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15573. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15574. fclose(infile);
  15575. fclose(outfile);
  15576. sprintf(rmFileCmd,"rm -f %s",filename);
  15577. system(rmFileCmd);
  15578. rename((char*)tmpProfileName, (char*)filename);
  15579. }
  15580. else
  15581. {
  15582. // Profile is not empty
  15583. int ChargingProfileAdded = FALSE;
  15584. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  15585. {
  15586. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  15587. json_object *tmpChargingProfile;
  15588. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  15589. if(!is_error(tmpChargingProfile))
  15590. {
  15591. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  15592. {
  15593. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  15594. {
  15595. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  15596. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  15597. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  15598. }
  15599. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15600. {
  15601. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  15602. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  15603. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  15604. }
  15605. }
  15606. }
  15607. json_object_put(tmpChargingProfile);
  15608. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  15609. {
  15610. if(ChargingProfileAdded == FALSE)
  15611. {
  15612. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15613. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15614. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15615. ChargingProfileAdded = TRUE;
  15616. }
  15617. }
  15618. else
  15619. {
  15620. fprintf(outfile,"%s\n",dataLine);
  15621. if(ChargingProfileAdded == FALSE)
  15622. {
  15623. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15624. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15625. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15626. ChargingProfileAdded = TRUE;
  15627. }
  15628. }
  15629. } // end of while loop
  15630. fclose(infile);
  15631. fclose(outfile);
  15632. sprintf(rmFileCmd,"rm -f %s",filename);
  15633. system(rmFileCmd);
  15634. rename((char*)tmpProfileName, (char*)filename);
  15635. }
  15636. }
  15637. sleep(1);
  15638. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  15639. result = PASS;
  15640. }
  15641. else
  15642. {
  15643. if(isLostConnectorId)
  15644. DEBUG_WARN("Connector id is wrong.\n");
  15645. if(isConnectorMismatch)
  15646. DEBUG_WARN("Connector id is mismatch.\n");
  15647. if(isPeriodOverMax)
  15648. DEBUG_WARN("Profile periods quantity is over spec.\n");
  15649. if(isProfileOverMax)
  15650. DEBUG_WARN("Profile quantity is over spec.\n");
  15651. if(isTransactiodIdMismatch)
  15652. DEBUG_WARN("Transaction id is mismatch.\n");
  15653. if(isInvalidLimit)
  15654. DEBUG_WARN("Limit value is invalid.\n");
  15655. if(isStackOverMax)
  15656. DEBUG_WARN("Profile stack is over spec.\n");
  15657. if(isWrongFormat)
  15658. DEBUG_WARN("Profile format is wrong.\n");
  15659. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  15660. }
  15661. }
  15662. json_object_put(SetChargingProfile);
  15663. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  15664. {
  15665. if(SetProfileReq.evseId == 0)
  15666. {
  15667. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15668. {
  15669. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  15670. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  15671. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  15672. }
  15673. }
  15674. else
  15675. {
  15676. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  15677. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  15678. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  15679. }
  15680. }
  15681. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  15682. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15683. return result;
  15684. }
  15685. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  15686. {
  15687. mtrace();
  15688. int result = FAIL;
  15689. json_object *SetDisplayMessage;
  15690. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  15691. SetDisplayMessage = json_tokener_parse(payload);
  15692. if(!is_error(SetDisplayMessage))
  15693. {
  15694. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  15695. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  15696. // Required data
  15697. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  15698. {
  15699. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  15700. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  15701. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  15702. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  15703. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  15704. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  15705. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  15706. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  15707. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  15708. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  15709. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  15710. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  15711. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  15712. {
  15713. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  15714. 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")));
  15715. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  15716. 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")));
  15717. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  15718. 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")));
  15719. }
  15720. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  15721. {
  15722. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  15723. 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")));
  15724. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  15725. 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")));
  15726. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  15727. {
  15728. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  15729. 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"));
  15730. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  15731. 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"));
  15732. }
  15733. }
  15734. }
  15735. }
  15736. json_object_put(SetDisplayMessage);
  15737. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  15738. sendSetDisplayMessagesConfirmation(uuid);
  15739. // Announce CSU there is display request come from server
  15740. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  15741. return result;
  15742. }
  15743. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  15744. {
  15745. mtrace();
  15746. int result = FAIL;
  15747. json_object *SetMonitoringBase;
  15748. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  15749. SetMonitoringBase = json_tokener_parse(payload);
  15750. if(!is_error(SetMonitoringBase))
  15751. {
  15752. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  15753. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  15754. // Required data
  15755. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  15756. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  15757. }
  15758. json_object_put(SetMonitoringBase);
  15759. /*
  15760. * TODO:
  15761. * 1. Configure monitor base and response
  15762. */
  15763. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  15764. sendSetMonitoringBaseConfirmation(uuid);
  15765. return result;
  15766. }
  15767. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  15768. {
  15769. mtrace();
  15770. int result = FAIL;
  15771. json_object *SetMonitoringLevel;
  15772. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  15773. SetMonitoringLevel = json_tokener_parse(payload);
  15774. if(!is_error(SetMonitoringLevel))
  15775. {
  15776. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  15777. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  15778. // Required data
  15779. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  15780. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  15781. }
  15782. json_object_put(SetMonitoringLevel);
  15783. /*
  15784. * TODO:
  15785. * Configure monitor status and response
  15786. */
  15787. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  15788. sendSetMonitoringLevelConfirmation(uuid);
  15789. return result;
  15790. }
  15791. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  15792. {
  15793. mtrace();
  15794. int result = FAIL;
  15795. json_object *SetNetworkProfile;
  15796. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  15797. SetNetworkProfile = json_tokener_parse(payload);
  15798. if(!is_error(SetNetworkProfile))
  15799. {
  15800. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  15801. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  15802. // Required data
  15803. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  15804. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  15805. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  15806. {
  15807. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  15808. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  15809. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  15810. {
  15811. if(strcmp(json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")), "JSON") == 0)
  15812. {
  15813. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  15814. }
  15815. else
  15816. {
  15817. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  15818. goto end;
  15819. }
  15820. }
  15821. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  15822. {
  15823. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  15824. if((strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"wss", 3) == 0) || (strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"ws", 2) == 0))
  15825. {
  15826. char protocol[10], host[128], path[512], port[10];
  15827. int check = sscanf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"%[^:]:%*2[/]%[^:]:%[^/]/%199[^\n]", protocol, host, port, path);
  15828. if(check >= 3)
  15829. {
  15830. DEBUG_INFO("URL: %s\n", ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl);
  15831. DEBUG_INFO("protocol: %s\n",protocol);
  15832. DEBUG_INFO("host: %s\n",host);
  15833. DEBUG_INFO("port: %s\n",port);
  15834. DEBUG_INFO("path: %s\n",path);
  15835. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  15836. }
  15837. else
  15838. {
  15839. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  15840. goto end;
  15841. }
  15842. }
  15843. else
  15844. {
  15845. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  15846. goto end;
  15847. }
  15848. }
  15849. else
  15850. {
  15851. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  15852. goto end;
  15853. }
  15854. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  15855. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  15856. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  15857. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  15858. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  15859. {
  15860. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  15861. 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")));
  15862. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  15863. 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")));
  15864. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  15865. 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")));
  15866. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  15867. 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")));
  15868. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  15869. 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")));
  15870. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  15871. 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")));
  15872. }
  15873. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  15874. {
  15875. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  15876. {
  15877. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  15878. 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")));
  15879. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  15880. }
  15881. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  15882. {
  15883. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  15884. 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")));
  15885. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  15886. }
  15887. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  15888. {
  15889. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  15890. 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")));
  15891. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  15892. }
  15893. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  15894. 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"));
  15895. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  15896. 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")));
  15897. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  15898. 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"));
  15899. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  15900. 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")));
  15901. }
  15902. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  15903. }
  15904. }
  15905. json_object_put(SetNetworkProfile);
  15906. /*
  15907. * TODO:
  15908. * 1. Process network configuration and response
  15909. */
  15910. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  15911. {
  15912. }
  15913. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  15914. {
  15915. }
  15916. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  15917. {
  15918. }
  15919. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  15920. {
  15921. }
  15922. else
  15923. {
  15924. }
  15925. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  15926. {
  15927. }
  15928. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  15929. {
  15930. }
  15931. else
  15932. {
  15933. }
  15934. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  15935. {
  15936. }
  15937. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  15938. {
  15939. }
  15940. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  15941. {
  15942. }
  15943. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  15944. {
  15945. }
  15946. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  15947. {
  15948. }
  15949. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  15950. {
  15951. }
  15952. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  15953. {
  15954. }
  15955. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  15956. {
  15957. }
  15958. else
  15959. {
  15960. }
  15961. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  15962. {
  15963. }
  15964. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  15965. {
  15966. }
  15967. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  15968. {
  15969. }
  15970. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  15971. {
  15972. }
  15973. else
  15974. {
  15975. }
  15976. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  15977. {
  15978. }
  15979. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  15980. {
  15981. }
  15982. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  15983. {
  15984. }
  15985. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  15986. {
  15987. }
  15988. else
  15989. {
  15990. }
  15991. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  15992. end:
  15993. sendSetNetworkProfileConfirmation(uuid);
  15994. return result;
  15995. }
  15996. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  15997. {
  15998. mtrace();
  15999. int result = FAIL;
  16000. json_object *SetVariableMonitoring;
  16001. uint8_t variableQuantity = 0;
  16002. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  16003. SetVariableMonitoring = json_tokener_parse(payload);
  16004. if(!is_error(SetVariableMonitoring))
  16005. {
  16006. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  16007. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  16008. // Required data
  16009. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  16010. {
  16011. variableQuantity++;
  16012. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  16013. {
  16014. 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"));
  16015. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  16016. }
  16017. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  16018. {
  16019. 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"));
  16020. }
  16021. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  16022. {
  16023. 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")));
  16024. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16025. }
  16026. else
  16027. {
  16028. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  16029. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16030. }
  16031. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  16032. {
  16033. 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"));
  16034. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  16035. }
  16036. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  16037. {
  16038. 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"));
  16039. }
  16040. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  16041. {
  16042. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  16043. {
  16044. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name")));
  16045. }
  16046. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  16047. {
  16048. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance")));
  16049. }
  16050. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  16051. {
  16052. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse"), "id") != NULL)
  16053. {
  16054. ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance"), "id"));
  16055. }
  16056. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse"), "connectorId") != NULL)
  16057. {
  16058. ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance"), "connectorId"));
  16059. }
  16060. }
  16061. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  16062. }
  16063. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  16064. {
  16065. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  16066. {
  16067. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name")));
  16068. }
  16069. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  16070. {
  16071. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance")));
  16072. }
  16073. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  16074. }
  16075. /*
  16076. * TODO
  16077. * Set Variables and save to DB
  16078. */
  16079. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  16080. }
  16081. }
  16082. json_object_put(SetVariableMonitoring);
  16083. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  16084. return result;
  16085. }
  16086. int handleSetVariablesRequest(char *uuid, char *payload)
  16087. {
  16088. mtrace();
  16089. uint8_t result = FAIL;
  16090. uint8_t isUnknownComponent = TRUE;
  16091. uint8_t isNeedReconnect = FALSE;
  16092. json_object *SetVariables;
  16093. DEBUG_INFO("handleSetVariablesRequest...\n");
  16094. SetVariables = json_tokener_parse(payload);
  16095. if(!is_error(SetVariables))
  16096. {
  16097. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  16098. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  16099. // Required data
  16100. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  16101. {
  16102. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  16103. {
  16104. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  16105. {
  16106. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  16107. {
  16108. 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")));
  16109. }
  16110. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  16111. {
  16112. 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")));
  16113. }
  16114. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  16115. {
  16116. 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)
  16117. {
  16118. ShmOCPP20Data->SetVariables.setVariableData[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse"), "id"));
  16119. }
  16120. 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)
  16121. {
  16122. ShmOCPP20Data->SetVariables.setVariableData[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse"), "connectorId"));
  16123. }
  16124. }
  16125. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  16126. }
  16127. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  16128. {
  16129. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  16130. {
  16131. 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")));
  16132. }
  16133. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  16134. {
  16135. 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")));
  16136. }
  16137. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  16138. }
  16139. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  16140. {
  16141. 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")));
  16142. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  16143. }
  16144. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  16145. {
  16146. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  16147. }
  16148. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  16149. {
  16150. 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")));
  16151. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  16152. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  16153. {
  16154. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  16155. (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) &&
  16156. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  16157. (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))
  16158. {
  16159. isUnknownComponent = FALSE;
  16160. //DEBUG_INFO("Checking variable...[%s][%s], dataType: %s\n",ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType);
  16161. if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_decimal]) == 0)
  16162. {
  16163. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,TRUE)!=YES)
  16164. {
  16165. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16166. break;
  16167. }
  16168. }
  16169. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_integer]) == 0)
  16170. {
  16171. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, FALSE)!=YES)
  16172. {
  16173. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16174. break;
  16175. }
  16176. }
  16177. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_dateTime]) == 0)
  16178. {
  16179. if(isMatchTimeFormat(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)!=YES)
  16180. {
  16181. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16182. break;
  16183. }
  16184. }
  16185. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_boolean]) == 0)
  16186. {
  16187. // To make sure all boolean value is in uppercase
  16188. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true") != NULL) ||
  16189. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"True") != NULL) ||
  16190. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"TRUE") != NULL))
  16191. {
  16192. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true");
  16193. }
  16194. else if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false") != NULL) ||
  16195. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"False") != NULL) ||
  16196. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"FALSE") != NULL))
  16197. {
  16198. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false");
  16199. }
  16200. else
  16201. {
  16202. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16203. break;
  16204. }
  16205. }
  16206. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  16207. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  16208. {
  16209. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  16210. break;
  16211. }
  16212. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  16213. {
  16214. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16215. break;
  16216. }
  16217. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AuthCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Enabled") != NULL))
  16218. {
  16219. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16220. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16221. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16222. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16223. {
  16224. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16225. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16226. if(strstr((char*)tmp, "true") != NULL)
  16227. {
  16228. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
  16229. }
  16230. else
  16231. {
  16232. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
  16233. }
  16234. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16235. }
  16236. else
  16237. {
  16238. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16239. break;
  16240. }
  16241. }
  16242. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  16243. {
  16244. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  16245. }
  16246. else
  16247. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16248. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  16249. {
  16250. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  16251. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16252. else
  16253. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16254. }
  16255. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  16256. {
  16257. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16258. {
  16259. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16260. }
  16261. else
  16262. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  16263. }
  16264. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  16265. {
  16266. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16267. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16268. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16269. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16270. {
  16271. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16272. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16273. }
  16274. else
  16275. {
  16276. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16277. break;
  16278. }
  16279. }
  16280. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  16281. {
  16282. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16283. {
  16284. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16285. }
  16286. else
  16287. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16288. }
  16289. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  16290. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  16291. {
  16292. isNeedReconnect = TRUE;
  16293. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16294. //SetOcppConnStatus(FALSE);
  16295. }
  16296. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  16297. {
  16298. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16299. {
  16300. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16301. }
  16302. else
  16303. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16304. }
  16305. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  16306. {
  16307. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16308. {
  16309. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16310. }
  16311. else
  16312. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16313. }
  16314. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  16315. {
  16316. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16317. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16318. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16319. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16320. {
  16321. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16322. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  16323. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16324. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16325. }
  16326. }
  16327. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  16328. {
  16329. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  16330. {
  16331. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16332. }
  16333. else
  16334. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16335. }
  16336. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "OffLineMaxChargingPower") != NULL))
  16337. {
  16338. if(atoi((const char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > modelnameInfo.ratedPower)
  16339. {
  16340. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16341. }
  16342. else
  16343. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16344. }
  16345. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  16346. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  16347. {
  16348. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  16349. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  16350. }
  16351. break;
  16352. }
  16353. else
  16354. {
  16355. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  16356. {
  16357. isUnknownComponent = FALSE;
  16358. }
  16359. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  16360. }
  16361. }
  16362. if(isUnknownComponent == TRUE)
  16363. {
  16364. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  16365. }
  16366. }
  16367. }
  16368. }
  16369. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  16370. if(isNeedReconnect)
  16371. {
  16372. SetOcppConnStatus(FALSE);
  16373. }
  16374. }
  16375. json_object_put(SetVariables);
  16376. return result;
  16377. }
  16378. int handleTriggerMessageRequest(char *uuid, char *payload)
  16379. {
  16380. mtrace();
  16381. int result = FAIL;
  16382. int connectorIdIsNULL = FALSE;
  16383. int connectorIdInt =0;
  16384. json_object *TriggerMessage;
  16385. DEBUG_INFO("handleTriggerMessageRequest\n");
  16386. TriggerMessage = json_tokener_parse(payload);
  16387. if(!is_error(TriggerMessage))
  16388. {
  16389. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  16390. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  16391. // Required data
  16392. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  16393. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  16394. // Optional data
  16395. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  16396. {
  16397. // Required data
  16398. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  16399. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  16400. // Optional data
  16401. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  16402. {
  16403. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  16404. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  16405. }
  16406. else
  16407. connectorIdIsNULL = TRUE;
  16408. }
  16409. else
  16410. connectorIdIsNULL = TRUE;
  16411. }
  16412. json_object_put(TriggerMessage);
  16413. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  16414. {
  16415. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  16416. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  16417. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  16418. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  16419. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  16420. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  16421. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  16422. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  16423. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  16424. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  16425. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  16426. {
  16427. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  16428. sendTriggerMessageConfirmation(uuid);
  16429. return TRUE;
  16430. }
  16431. else
  16432. {
  16433. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  16434. sendTriggerMessageConfirmation(uuid);
  16435. }
  16436. }
  16437. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  16438. {
  16439. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  16440. sendTriggerMessageConfirmation(uuid);
  16441. return TRUE;
  16442. }
  16443. //==========================
  16444. // Trigger message
  16445. //==========================
  16446. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  16447. {
  16448. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  16449. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  16450. {
  16451. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  16452. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16453. }
  16454. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16455. }
  16456. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  16457. {
  16458. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  16459. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  16460. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  16461. }
  16462. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  16463. {
  16464. if(server_sign)
  16465. {
  16466. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  16467. sendTriggerMessageConfirmation(uuid);
  16468. return TRUE;
  16469. }
  16470. else
  16471. {
  16472. if(DB_updateBootType(BootReasonEnumType_Triggered))
  16473. server_sign = FALSE;
  16474. }
  16475. }
  16476. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  16477. {
  16478. refreshStartTimer(&clientTime.Heartbeat);
  16479. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  16480. }
  16481. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  16482. {
  16483. if(connectorIdIsNULL == FALSE)
  16484. {
  16485. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  16486. {
  16487. cpinitateMsg.bits[connectorIdInt-1].TriggerMeterValueReq = ON;
  16488. }
  16489. }
  16490. else
  16491. {
  16492. for(int idx=0;idx< gunTotalNumber;idx++)
  16493. {
  16494. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  16495. }
  16496. }
  16497. }
  16498. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  16499. {
  16500. if(connectorIdIsNULL == FALSE)
  16501. {
  16502. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  16503. {
  16504. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = ON;
  16505. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  16506. }
  16507. }
  16508. else
  16509. {
  16510. for(int idx=0;idx< gunTotalNumber;idx++)
  16511. {
  16512. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  16513. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  16514. }
  16515. }
  16516. }
  16517. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  16518. {
  16519. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16520. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  16521. {
  16522. 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\" &");
  16523. }
  16524. }
  16525. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  16526. {
  16527. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16528. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  16529. {
  16530. 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\" &");
  16531. }
  16532. }
  16533. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  16534. {
  16535. if(connectorIdIsNULL == FALSE)
  16536. {
  16537. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  16538. {
  16539. //ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  16540. cpinitateMsg.bits[connectorIdInt -1].TriggerTransactionEventReq = ON;
  16541. }
  16542. }
  16543. else
  16544. {
  16545. for(int idx=0;idx< gunTotalNumber;idx++)
  16546. {
  16547. //ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  16548. cpinitateMsg.bits[idx].TriggerTransactionEventReq = ON;
  16549. }
  16550. }
  16551. }
  16552. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  16553. {
  16554. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16555. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  16556. {
  16557. 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\" &");
  16558. }
  16559. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  16560. {
  16561. 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\" &");
  16562. }
  16563. }
  16564. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  16565. {
  16566. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  16567. }
  16568. return result;
  16569. }
  16570. int handleUnlockConnectorRequest(char *uuid, char *payload)
  16571. {
  16572. mtrace();
  16573. int result = FAIL;
  16574. int connectorIdInt =0;
  16575. int tempIndex = 0;
  16576. json_object *UnlockConnector;
  16577. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  16578. UnlockConnector = json_tokener_parse(payload);
  16579. if(!is_error(UnlockConnector))
  16580. {
  16581. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  16582. {
  16583. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  16584. }
  16585. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  16586. {
  16587. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  16588. }
  16589. }
  16590. json_object_put(UnlockConnector);
  16591. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  16592. if(gunTotalNumber == 0)
  16593. {
  16594. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  16595. goto end;
  16596. }
  16597. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  16598. {
  16599. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  16600. goto end;
  16601. }
  16602. else
  16603. {
  16604. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  16605. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  16606. //check Transaction active
  16607. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  16608. {
  16609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16610. {
  16611. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16612. }
  16613. else
  16614. {
  16615. tempIndex = connectorIdInt -1;
  16616. }
  16617. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16618. {
  16619. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  16620. {
  16621. //stop Transaction
  16622. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16623. }
  16624. }
  16625. }
  16626. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  16627. {
  16628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16629. {
  16630. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16631. }
  16632. else
  16633. {
  16634. tempIndex = connectorIdInt -1;
  16635. }
  16636. for (int index = 0; index < CCS_QUANTITY; index++)
  16637. {
  16638. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  16639. {
  16640. //stop Transaction
  16641. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16642. }
  16643. }
  16644. }
  16645. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  16646. {
  16647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16648. {
  16649. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16650. }
  16651. else
  16652. {
  16653. tempIndex = connectorIdInt -1;
  16654. }
  16655. for (int index = 0; index < GB_QUANTITY; index++)
  16656. {
  16657. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  16658. {
  16659. //stop Transaction
  16660. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16661. }
  16662. }
  16663. }
  16664. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  16665. {
  16666. tempIndex = connectorIdInt -1;
  16667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16668. {
  16669. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  16670. {
  16671. //stop Transaction
  16672. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16673. }
  16674. }
  16675. }
  16676. else
  16677. {
  16678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16679. {
  16680. tempIndex = 2;
  16681. }
  16682. else
  16683. {
  16684. tempIndex = connectorIdInt-1;
  16685. }
  16686. for (int index = 0; index < AC_QUANTITY; index++)
  16687. {
  16688. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  16689. {
  16690. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16691. }
  16692. }
  16693. }
  16694. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  16695. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  16696. result = TRUE;
  16697. return result;
  16698. }
  16699. end:
  16700. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorConf = ON;
  16701. return result;
  16702. }
  16703. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  16704. {
  16705. mtrace();
  16706. int result = FAIL;
  16707. json_object *UnpublishFirmware;
  16708. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  16709. UnpublishFirmware = json_tokener_parse(payload);
  16710. if(!is_error(UnpublishFirmware))
  16711. {
  16712. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  16713. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  16714. // Required data
  16715. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  16716. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  16717. }
  16718. json_object_put(UnpublishFirmware);
  16719. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  16720. /*
  16721. * TODO:
  16722. * 1. Check unpublished status
  16723. */
  16724. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  16725. sendUnpublishFirmwareConfirmation(uuid);
  16726. return result;
  16727. }
  16728. static char UpdateFirmwarepayloadData[512]={0};
  16729. void *UpdateFirmwareProcess(void *data)
  16730. {
  16731. pthread_detach(pthread_self());
  16732. mtrace();
  16733. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  16734. int port=0;
  16735. int isSuccess = 0;
  16736. char ftpbuf[1024];
  16737. char temp[1024];
  16738. char * pch;
  16739. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  16740. json_object *UpdateFirmware;
  16741. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  16742. if(!is_error(UpdateFirmware))
  16743. {
  16744. // Required data
  16745. if(json_object_object_get(UpdateFirmware, "requestId"))
  16746. {
  16747. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  16748. }
  16749. if(json_object_object_get(UpdateFirmware, "firmware"))
  16750. {
  16751. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  16752. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  16753. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  16754. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  16755. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  16756. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  16757. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  16758. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  16759. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  16760. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  16761. }
  16762. // Optional data
  16763. if(json_object_object_get(UpdateFirmware, "retries"))
  16764. {
  16765. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  16766. }
  16767. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  16768. {
  16769. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  16770. }
  16771. }
  16772. json_object_put(UpdateFirmware);
  16773. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  16774. memset(path, 0, ARRAY_SIZE(path));
  16775. // Wait retrieveData
  16776. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  16777. {
  16778. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16779. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  16780. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16781. do
  16782. {
  16783. sleep(1);
  16784. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  16785. }
  16786. system("rm -f /mnt/*");
  16787. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  16788. {
  16789. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  16790. sprintf(ftppath,"/%s", path);
  16791. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  16792. DEBUG_INFO("protocol: %s\n",protocol);
  16793. DEBUG_INFO("host: %s\n",host);
  16794. DEBUG_INFO("path: %s\n",path);
  16795. DEBUG_INFO("ftppath: %s\n",ftppath);
  16796. int ftppathlen=strlen(ftppath);
  16797. int i=1;
  16798. char filenametemp[50];
  16799. while(i < ftppathlen)
  16800. {
  16801. int len=ftppathlen-i;
  16802. if(ftppath[len]== 47) // '/' ascll code: 47
  16803. {
  16804. DEBUG_INFO("compare '/' all right\n");
  16805. break;
  16806. }
  16807. i=i+1;
  16808. }
  16809. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  16810. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  16811. filenametemp[i+1] = 0;
  16812. do
  16813. {
  16814. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16815. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  16816. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16817. sleep(3);
  16818. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16819. if(!isSuccess)
  16820. {
  16821. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16822. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16823. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16824. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  16825. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16826. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16827. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16828. }
  16829. else
  16830. {
  16831. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16832. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  16833. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16834. }
  16835. ShmOCPP20Data->UpdateFirmware.retries--;
  16836. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  16837. }
  16838. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  16839. {
  16840. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16841. memset(temp, 0, ARRAY_SIZE(temp));
  16842. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16843. int ftppathlen=strlen(ftpbuf);
  16844. int i=1;
  16845. char filenametemp[50];
  16846. while(i < ftppathlen)
  16847. {
  16848. int len=ftppathlen-i;
  16849. if(ftpbuf[len]== 47) // '/' ascll code: 47
  16850. {
  16851. DEBUG_INFO(" compare '/' all right\n");
  16852. break;
  16853. }
  16854. i=i+1;
  16855. }
  16856. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  16857. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  16858. filenametemp[i+1] = 0;
  16859. strncpy(temp, ftpbuf, ftppathlen-i+1);
  16860. pch=strchr(temp,'@');
  16861. if(pch==NULL)
  16862. {
  16863. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16864. protocol, host, &port, path);
  16865. strcpy(user,"anonymous");
  16866. strcpy(password,"");
  16867. }
  16868. else
  16869. {
  16870. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  16871. protocol, user, password, host, &port, path);
  16872. }
  16873. sscanf(host,"%[^/]%s",host1, path1);
  16874. sprintf(ftppath,"%s", path1);
  16875. if(port == 0)
  16876. {
  16877. port = 21;
  16878. }
  16879. do
  16880. {
  16881. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16882. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  16883. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16884. sleep(3);
  16885. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16886. if(!isSuccess)
  16887. {
  16888. //BulldogUtil.sleepMs(interval*1000);
  16889. DEBUG_INFO("Update firmware request and download file fail.\n");
  16890. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16891. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16892. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16893. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  16894. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16895. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16896. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16897. }
  16898. else
  16899. {
  16900. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16901. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  16902. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16903. }
  16904. ShmOCPP20Data->UpdateFirmware.retries--;
  16905. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  16906. }
  16907. else
  16908. {
  16909. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16910. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16911. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16912. sleep(1);
  16913. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16914. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16915. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16916. }
  16917. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  16918. interLock.isUpdateFirmwareGoing = OFF;
  16919. pthread_exit(NULL);
  16920. }
  16921. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  16922. {
  16923. mtrace();
  16924. int result = FAIL;
  16925. pthread_t t;
  16926. sendUpdateFirmwareConfirmation(uuid);
  16927. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  16928. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  16929. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  16930. if(!interLock.isUpdateFirmwareGoing)
  16931. {
  16932. interLock.isUpdateFirmwareGoing = ON;
  16933. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  16934. sleep(1);
  16935. }
  16936. else
  16937. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  16938. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  16939. return result;
  16940. }
  16941. int handleUnknownRequest(char *uuid, char *payload)
  16942. {
  16943. mtrace();
  16944. int result = FAIL;
  16945. DEBUG_INFO("handleUnknownRequest...\n");
  16946. sendUnknownConfirmation(uuid);
  16947. result = PASS;
  16948. return result;
  16949. }
  16950. //==========================================
  16951. // Handle server response routine
  16952. //==========================================
  16953. void handleAuthorizeResponse(char *payload, int gun_index)
  16954. {
  16955. mtrace();
  16956. DEBUG_INFO("handleAuthorizeResponse...\n");
  16957. json_object *Authorize;
  16958. Authorize = json_tokener_parse(payload);
  16959. if(!is_error(Authorize))
  16960. {
  16961. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  16962. {
  16963. // Required data
  16964. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  16965. // Optional data
  16966. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  16967. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  16968. else
  16969. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  16970. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority") != NULL)
  16971. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  16972. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1") != NULL)
  16973. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  16974. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "evseId") != NULL)
  16975. {
  16976. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTokenInfo"), "evseId"));idx++)
  16977. {
  16978. 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));
  16979. }
  16980. }
  16981. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2") != NULL)
  16982. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  16983. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken") != NULL)
  16984. {
  16985. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  16986. 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")));
  16987. else
  16988. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  16989. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  16990. 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")));
  16991. }
  16992. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage") != NULL)
  16993. {
  16994. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  16995. 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")));
  16996. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  16997. 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")));
  16998. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  16999. 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")));
  17000. }
  17001. }
  17002. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  17003. {
  17004. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  17005. }
  17006. }
  17007. json_object_put(Authorize);
  17008. //Update idTag information to authorization cache if supported
  17009. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  17010. /*(strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  17011. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&*/
  17012. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  17013. {
  17014. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  17015. }
  17016. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  17017. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  17018. authorizeRetryTimes = 0;
  17019. }
  17020. void handleBootNotificationResponse(char *payload, int gun_index)
  17021. {
  17022. mtrace();
  17023. char statusStr[12]={0};
  17024. char currentTimeStr[30]={0};
  17025. int intervalInt = 0;
  17026. DEBUG_INFO("handleBootNotificationResponse...\n");
  17027. json_object *BootNotification;
  17028. BootNotification = json_tokener_parse(payload);
  17029. if(!is_error(BootNotification))
  17030. {
  17031. // Required data
  17032. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  17033. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  17034. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  17035. }
  17036. json_object_put(BootNotification);
  17037. DEBUG_INFO("statusStr: %s\n", statusStr);
  17038. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  17039. BootNotificationInterval = intervalInt;
  17040. //write back to ShmOCPP20Data->BootNotification
  17041. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  17042. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  17043. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  17044. {
  17045. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  17046. {
  17047. //Do nothing because the value is out of range.
  17048. }
  17049. else
  17050. {
  17051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  17052. HeartBeatWaitTime = intervalInt;
  17053. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  17054. }
  17055. server_sign = TRUE;
  17056. server_pending =FALSE;
  17057. DB_updateBootType(BootReasonEnumType_PowerUp);
  17058. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  17059. }
  17060. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  17061. {
  17062. server_pending = TRUE;
  17063. }
  17064. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  17065. srand(time(NULL));
  17066. refreshStartTimer(&clientTime.Heartbeat);
  17067. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  17068. SetOcppConnStatus(TRUE);
  17069. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  17070. }
  17071. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  17072. {
  17073. mtrace();
  17074. json_object *ClearedChargingLimit;
  17075. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  17076. ClearedChargingLimit = json_tokener_parse(payload);
  17077. if(!is_error(ClearedChargingLimit))
  17078. {
  17079. // Required data
  17080. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  17081. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  17082. }
  17083. json_object_put(ClearedChargingLimit);
  17084. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  17085. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  17086. }
  17087. void handleDataTransferResponse(char *payload, int gun_index)
  17088. {
  17089. mtrace();
  17090. json_object *DataTrans;
  17091. DEBUG_INFO("handleDataTransferResponse...\n");
  17092. DataTrans = json_tokener_parse(payload);
  17093. if(!is_error(DataTrans))
  17094. {
  17095. // Required data
  17096. if(json_object_object_get(DataTrans,"status") != NULL)
  17097. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  17098. // Optional data
  17099. if(json_object_object_get(DataTrans,"data") != NULL)
  17100. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  17101. }
  17102. json_object_put(DataTrans);
  17103. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  17104. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  17105. }
  17106. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  17107. {
  17108. mtrace();
  17109. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  17110. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  17111. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  17112. }
  17113. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  17114. {
  17115. mtrace();
  17116. json_object *Get15118EVCertificate;
  17117. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  17118. Get15118EVCertificate = json_tokener_parse(payload);
  17119. if(!is_error(Get15118EVCertificate))
  17120. {
  17121. // Required data
  17122. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  17123. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  17124. // Optional data
  17125. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  17126. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  17127. }
  17128. json_object_put(Get15118EVCertificate);
  17129. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  17130. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  17131. }
  17132. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  17133. {
  17134. mtrace();
  17135. json_object *GetCertificateStatus;
  17136. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  17137. GetCertificateStatus = json_tokener_parse(payload);
  17138. if(!is_error(GetCertificateStatus))
  17139. {
  17140. // Required data
  17141. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  17142. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  17143. // Optional data
  17144. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  17145. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  17146. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  17147. {
  17148. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  17149. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  17150. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  17151. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  17152. }
  17153. }
  17154. json_object_put(GetCertificateStatus);
  17155. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  17156. {
  17157. /*
  17158. * TODO:
  17159. * 1. If get certificate response accepted process something here
  17160. */
  17161. }
  17162. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  17163. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  17164. }
  17165. void handleHeartbeatResponse(char *payload, int gun_index)
  17166. {
  17167. mtrace();
  17168. DEBUG_INFO("handleHeartbeatResponse...\n");
  17169. json_object *Heartbeat;
  17170. Heartbeat = json_tokener_parse(payload);
  17171. if(!is_error(Heartbeat))
  17172. {
  17173. // Required data
  17174. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  17175. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  17176. }
  17177. json_object_put(Heartbeat);
  17178. if(FirstHeartBeat == OFF)
  17179. {
  17180. FirstHeartBeat = ON;
  17181. DEBUG_INFO("FirstHeartBeat \n");
  17182. }
  17183. HeartBeatWithNOResponse = 0;
  17184. refreshStartTimer(&clientTime.Heartbeat);
  17185. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  17186. }
  17187. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  17188. {
  17189. mtrace();
  17190. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  17191. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  17192. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  17193. }
  17194. void handleMeterValuesResponse(char *payload, int gun_index)
  17195. {
  17196. mtrace();
  17197. DEBUG_INFO("handleMeterValuesResponse...\n");
  17198. isQueueSendable = ON;
  17199. }
  17200. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  17201. {
  17202. mtrace();
  17203. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  17204. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  17205. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  17206. }
  17207. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  17208. {
  17209. mtrace();
  17210. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  17211. }
  17212. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  17213. {
  17214. mtrace();
  17215. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  17216. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  17217. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  17218. }
  17219. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  17220. {
  17221. mtrace();
  17222. json_object *NotifyEVChargingNeeds;
  17223. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  17224. NotifyEVChargingNeeds = json_tokener_parse(payload);
  17225. if(!is_error(NotifyEVChargingNeeds))
  17226. {
  17227. // Required data
  17228. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  17229. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  17230. }
  17231. json_object_put(NotifyEVChargingNeeds);
  17232. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  17233. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  17234. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  17235. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsConf = ON;
  17236. }
  17237. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  17238. {
  17239. mtrace();
  17240. json_object *NotifyEVChargingSchedule;
  17241. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  17242. NotifyEVChargingSchedule = json_tokener_parse(payload);
  17243. if(!is_error(NotifyEVChargingSchedule))
  17244. {
  17245. // Required data
  17246. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  17247. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  17248. }
  17249. json_object_put(NotifyEVChargingSchedule);
  17250. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  17251. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleConf = ON;
  17252. }
  17253. void handleNotifyEventResponse(char *payload, int gun_index)
  17254. {
  17255. mtrace();
  17256. DEBUG_INFO("handleNotifyEventResponse...\n");
  17257. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  17258. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  17259. }
  17260. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  17261. {
  17262. mtrace();
  17263. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  17264. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  17265. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  17266. }
  17267. void handleNotifyReportResponse(char *payload, int gun_index)
  17268. {
  17269. mtrace();
  17270. DEBUG_INFO("handleNotifyReportResponse...\n");
  17271. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  17272. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  17273. }
  17274. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  17275. {
  17276. mtrace();
  17277. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  17278. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  17279. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  17280. }
  17281. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  17282. {
  17283. mtrace();
  17284. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  17285. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  17286. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  17287. }
  17288. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  17289. {
  17290. mtrace();
  17291. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  17292. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  17293. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  17294. }
  17295. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  17296. {
  17297. mtrace();
  17298. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  17299. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  17300. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  17301. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  17302. }
  17303. void handleSignCertificateResponse(char *payload, int gun_index)
  17304. {
  17305. mtrace();
  17306. json_object *SignCertificate;
  17307. DEBUG_INFO("handleSignCertificateResponse...\n");
  17308. SignCertificate = json_tokener_parse(payload);
  17309. if(!is_error(SignCertificate))
  17310. {
  17311. // Required data
  17312. if(json_object_object_get(SignCertificate,"status") != NULL)
  17313. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  17314. // Optional data
  17315. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  17316. {
  17317. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  17318. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  17319. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  17320. }
  17321. }
  17322. json_object_put(SignCertificate);
  17323. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  17324. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  17325. }
  17326. void handleStatusNotificationResponse(char *payload, int gun_index)
  17327. {
  17328. mtrace();
  17329. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  17330. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  17331. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  17332. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  17333. }
  17334. void handleTransactionEventResponse(char *payload, int gun_index)
  17335. {
  17336. mtrace();
  17337. json_object *TransactionEven;
  17338. DEBUG_INFO("handleTransactionEventResponse...\n");
  17339. TransactionEven = json_tokener_parse(payload);
  17340. if(!is_error(TransactionEven))
  17341. {
  17342. // Required data
  17343. // Optional data
  17344. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  17345. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  17346. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  17347. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  17348. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  17349. {
  17350. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  17351. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  17352. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  17353. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  17354. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  17355. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  17356. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  17357. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  17358. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  17359. {
  17360. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  17361. 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")));
  17362. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  17363. 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")));
  17364. }
  17365. }
  17366. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  17367. {
  17368. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  17369. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  17370. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  17371. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  17372. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  17373. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  17374. }
  17375. }
  17376. json_object_put(TransactionEven);
  17377. isQueueSendable = ON;
  17378. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  17379. }
  17380. //==========================================
  17381. // Handle Error routine
  17382. //==========================================
  17383. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  17384. {
  17385. mtrace();
  17386. #ifdef SystemLogMessage
  17387. DEBUG_INFO("errorCode: %s\n", errorCode);
  17388. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  17389. DEBUG_INFO("errorDetails: %s\n", payload);
  17390. #endif
  17391. }
  17392. //===============================================
  17393. // Common routine
  17394. //===============================================
  17395. int initialConfigurationTable(void)
  17396. {
  17397. DEBUG_INFO("initialConfigurationTable...\n");
  17398. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  17399. DB_variableIsCreate();
  17400. DB_variableLoadFromDb();
  17401. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  17402. {
  17403. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  17404. DB_variableClear();
  17405. DB_variableIsCreate();
  17406. DB_variableLoadFromDb();
  17407. }
  17408. DB_getNetworkProfileFromDb();
  17409. return 0;
  17410. }
  17411. int TransactionMessageAttemptsGet(void)
  17412. {
  17413. return TransactionMessageAttemptsValue;
  17414. }
  17415. int FirstHeartBeatResponse(void)
  17416. {
  17417. return FirstHeartBeat;
  17418. }
  17419. int TransactionMessageRetryIntervalGet(void)
  17420. {
  17421. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17422. }
  17423. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17424. {
  17425. int result = TRUE;
  17426. char rmFileCmd[100]={0};
  17427. char FilePath[100]={0};
  17428. char ftpbuf[200];
  17429. int systemresult;
  17430. sprintf(FilePath,"/mnt/%s",filename);
  17431. system("ping 8.8.8.8 &");
  17432. if((access(FilePath,F_OK))!=-1)
  17433. {
  17434. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17435. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17436. system(rmFileCmd);
  17437. }
  17438. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17439. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17440. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17441. systemresult = system(ftpbuf);
  17442. if(systemresult != 0)
  17443. {
  17444. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  17445. result = FALSE;
  17446. }
  17447. system("pkill ping");
  17448. return result;
  17449. }
  17450. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17451. {
  17452. int result = TRUE;
  17453. char rmFileCmd[100]={0};
  17454. char FilePath[100]={0};
  17455. char ftpbuf[200];
  17456. int systemresult;
  17457. sprintf(FilePath,"/mnt/%s",filename);
  17458. system("ping 8.8.8.8 &");
  17459. if((access(FilePath,F_OK))!=-1)
  17460. {
  17461. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17462. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17463. system(rmFileCmd);
  17464. }
  17465. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17466. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17467. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17468. systemresult = system(ftpbuf);
  17469. if(systemresult != 0)
  17470. {
  17471. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17472. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17473. systemresult = system(ftpbuf);
  17474. if(systemresult != 0)
  17475. {
  17476. DEBUG_WARN("FTP download fail!\n");
  17477. result = FALSE;
  17478. }
  17479. }
  17480. system("pkill ping");
  17481. return result;
  17482. }
  17483. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17484. {
  17485. char rmFileCmd[100]={0};
  17486. char FilePath[100]={0};
  17487. char buf[512];
  17488. int systemresult = 0;
  17489. //DEBUG_INFO("filename=%s\n",filename);
  17490. //DEBUG_INFO("url=%s\n",url);
  17491. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17492. if((access(FilePath,F_OK))!=-1)
  17493. {
  17494. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17495. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17496. system(rmFileCmd);
  17497. }
  17498. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17499. if(fp == NULL)
  17500. {
  17501. DEBUG_INFO("log is NULL\n");
  17502. return FALSE;
  17503. }
  17504. else
  17505. {
  17506. fprintf(fp, "%s\n", url);
  17507. fprintf(fp, "%s\n", filename);
  17508. fclose(fp);
  17509. }
  17510. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17511. if(phpFP == NULL)
  17512. {
  17513. DEBUG_INFO("PHP upload fail.\n");
  17514. return FALSE;
  17515. }
  17516. else
  17517. {
  17518. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17519. {
  17520. if(strstr(buf, "result") != NULL)
  17521. {
  17522. sscanf(buf, "result: %d", &systemresult);
  17523. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17524. }
  17525. }
  17526. pclose(phpFP);
  17527. }
  17528. if(systemresult != 1)
  17529. {
  17530. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17531. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17532. if(phpFP == NULL)
  17533. {
  17534. DEBUG_WARN("PHP PUT upload fail.\n");
  17535. return FALSE;
  17536. }
  17537. else
  17538. {
  17539. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17540. {
  17541. if(strstr(buf, "result") != NULL)
  17542. {
  17543. sscanf(buf, "result: %d", &systemresult);
  17544. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17545. }
  17546. }
  17547. pclose(phpFP);
  17548. }
  17549. }
  17550. if(systemresult != 1)
  17551. {
  17552. DEBUG_WARN("PHP PUT upload fail.\n");
  17553. return FALSE;
  17554. }
  17555. return TRUE;
  17556. }
  17557. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17558. {
  17559. int result = FALSE;
  17560. char ftpbuf[200];
  17561. int systemresult;
  17562. /*
  17563. // Domaind name transfer to IP address
  17564. struct hostent* server;
  17565. char *IPbuffer;
  17566. server = gethostbyname(location);
  17567. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17568. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17569. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17570. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17571. systemresult = system(ftpbuf);
  17572. if(systemresult != 0)
  17573. {
  17574. DEBUG_INFO("ftpput error!\n");
  17575. }
  17576. else
  17577. {
  17578. result = TRUE;
  17579. DEBUG_INFO("ftpput OK!\n");
  17580. }
  17581. return result;
  17582. }
  17583. //=========================================
  17584. // Routine
  17585. //=========================================
  17586. int GetOcppServerURL()
  17587. {
  17588. int result = FALSE;
  17589. struct yuarel url;
  17590. char urlStr[512];
  17591. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17592. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17593. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17594. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  17595. {
  17596. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  17597. if(yuarel_parse(&url, urlStr) != -1)
  17598. {
  17599. sprintf(OcppProtocol, "%s", url.scheme);
  17600. sprintf(OcppHost, "%s", url.host);
  17601. if(url.path == NULL)
  17602. OcppTempPath[0] = '\0';
  17603. else
  17604. sprintf(OcppTempPath, "%s", url.path);
  17605. if(url.port == 0)
  17606. {
  17607. if(strcmp(OcppProtocol, "wss") == 0)
  17608. OcppPort = 443;
  17609. else
  17610. OcppPort = 80;
  17611. }
  17612. else
  17613. OcppPort = url.port;
  17614. result = TRUE;
  17615. }
  17616. }
  17617. else
  17618. {
  17619. strcpy(OcppHost,"");
  17620. }
  17621. return result;
  17622. }
  17623. int GetOcppPath()
  17624. {
  17625. int result = FALSE;
  17626. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17627. {
  17628. if(OcppTempPath == NULL)
  17629. {
  17630. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17631. }
  17632. else
  17633. {
  17634. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17635. }
  17636. result = TRUE;
  17637. }
  17638. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  17639. {
  17640. if(OcppTempPath == NULL)
  17641. {
  17642. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  17643. }
  17644. else
  17645. {
  17646. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  17647. }
  17648. result = TRUE;
  17649. }
  17650. else
  17651. {
  17652. strcpy(OcppPath,"");
  17653. }
  17654. return result;
  17655. }
  17656. int GetOcppPort()
  17657. {
  17658. return OcppPort;
  17659. }
  17660. int GetOcppConnStatus(void)
  17661. {
  17662. return ShmOCPP20Data->OcppConnStatus;
  17663. }
  17664. void SetOcppConnStatus(uint8_t status)
  17665. {
  17666. ShmOCPP20Data->OcppConnStatus = status;
  17667. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17668. }
  17669. int GetHeartBeatWithNOResponse(void)
  17670. {
  17671. return HeartBeatWithNOResponse;
  17672. }
  17673. void SetHeartBeatWithNOResponse(void)
  17674. {
  17675. HeartBeatWithNOResponse = 0;
  17676. }
  17677. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17678. void storeTempStopTransaction(int gun_index)
  17679. {
  17680. char TempStopTransaction[256];
  17681. char message[1024*20]={0};
  17682. char guid[37]={0};
  17683. json_object *TransactionEvent = json_object_new_object();
  17684. json_object *transactionInfo = json_object_new_object();
  17685. json_object *idToken = json_object_new_object();
  17686. json_object *evse = json_object_new_object();
  17687. json_object *meterValues = json_object_new_array();
  17688. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  17689. DEBUG_INFO("storeTempStopTransaction...\n");
  17690. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  17691. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  17692. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  17693. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  17694. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  17695. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  17696. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  17697. // Message
  17698. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  17699. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  17700. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  17701. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  17702. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  17703. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  17704. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  17705. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  17706. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  17707. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  17708. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  17709. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  17710. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  17711. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  17712. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  17713. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  17714. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  17715. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  17716. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  17717. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  17718. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  17719. {
  17720. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  17721. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  17722. json_object_object_add(TransactionEvent, "idToken", idToken);
  17723. }
  17724. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  17725. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  17726. json_object_object_add(TransactionEvent, "evse", evse);
  17727. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  17728. {
  17729. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  17730. {
  17731. json_object *meterValue = json_object_new_object();
  17732. json_object *sampledValues = json_object_new_array();
  17733. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  17734. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  17735. {
  17736. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  17737. ((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) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  17738. {
  17739. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)
  17740. {
  17741. json_object *sampledValue = json_object_new_object();
  17742. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  17743. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  17744. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  17745. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  17746. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  17747. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  17748. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  17749. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  17750. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  17751. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  17752. {
  17753. json_object *unitOfMeasure = json_object_new_object();
  17754. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  17755. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  17756. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  17757. }
  17758. json_object_array_add(sampledValues, sampledValue);
  17759. }
  17760. }
  17761. }
  17762. json_object_object_add(meterValue, "sampledValue", sampledValues);
  17763. json_object_array_add(meterValues, meterValue);
  17764. }
  17765. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  17766. }
  17767. random_uuid(guid);
  17768. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  17769. , guid
  17770. , "TransactionEvent"
  17771. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  17772. json_object_put(TransactionEvent);
  17773. // open file for writing
  17774. FILE *outfile;
  17775. outfile = fopen (TempStopTransaction, "w+");
  17776. //DEBUG_INFO("data = %s\n", queuedata);
  17777. fputs(message, outfile);
  17778. fputs("\n", outfile);
  17779. fclose (outfile);
  17780. }
  17781. void checkTempStopTransaction(int gun_index)
  17782. {
  17783. FILE *fptr1;
  17784. char ch;
  17785. char str[QUEUE_MESSAGE_LENGTH]={0};
  17786. char guid[37]={0};
  17787. char tempdata[65]={0};
  17788. char TempStopTransaction[256];
  17789. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  17790. fptr1 = fopen(TempStopTransaction, "r");
  17791. if (!fptr1)
  17792. {
  17793. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  17794. return ;
  17795. }
  17796. ch=fgetc(fptr1);
  17797. rewind(fptr1);
  17798. if(ch!=EOF)
  17799. {
  17800. // copy all contents to the temporary file except the specific line
  17801. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17802. {
  17803. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17804. if(str[0]=='\0')
  17805. {
  17806. break;
  17807. }
  17808. strncpy(guid, str+4, 36); //copy guid
  17809. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  17810. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17811. {
  17812. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17813. }
  17814. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17815. memset(str,0,ARRAY_SIZE(str));
  17816. }
  17817. }
  17818. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17819. fclose(fptr1);
  17820. remove(TempStopTransaction); // remove the original file
  17821. }
  17822. int GetWebSocketPingInterval(void)
  17823. {
  17824. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  17825. }
  17826. int GetServerSign(void)
  17827. {
  17828. return server_sign;
  17829. }
  17830. uint8_t GetOcppSecurityProfile()
  17831. {
  17832. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  17833. }
  17834. void GetOcppChargerBoxId(uint8_t *data)
  17835. {
  17836. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17837. }
  17838. void GetOcppSecurityPassword(uint8_t *data)
  17839. {
  17840. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  17841. }
  17842. void SetServerSign(int value)
  17843. {
  17844. server_sign = value;
  17845. }
  17846. int GetBootNotificationInterval(void)
  17847. {
  17848. return BootNotificationInterval;
  17849. }
  17850. int GetInternetConn(void)
  17851. {
  17852. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17853. }
  17854. int GetBackendConnectionTimeout(void)
  17855. {
  17856. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17857. }
  17858. int isConnectorInitMode(int gun_index)
  17859. {
  17860. int tempIndex = 0;
  17861. int result = TRUE;
  17862. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17863. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17864. {
  17865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17866. {
  17867. tempIndex = ((gun_index==2) ? 1: 0);
  17868. }
  17869. else
  17870. {
  17871. tempIndex = gun_index;
  17872. }
  17873. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17874. {
  17875. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17876. {
  17877. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17878. } //end of the same index
  17879. }//end of for CHAdeMO_QUANTITY
  17880. }
  17881. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17882. {
  17883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17884. {
  17885. tempIndex = ((gun_index==2) ? 1: 0);
  17886. }
  17887. else
  17888. {
  17889. tempIndex = gun_index;
  17890. }
  17891. for (int index = 0; index < CCS_QUANTITY; index++)
  17892. {
  17893. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17894. {
  17895. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17896. } //end of the same index
  17897. } // end of for CCS_QUANTITY
  17898. }
  17899. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17900. {
  17901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17902. {
  17903. tempIndex = ((gun_index==2) ? 1: 0);
  17904. }
  17905. else
  17906. {
  17907. tempIndex = gun_index;
  17908. }
  17909. for (int index = 0; index < GB_QUANTITY; index++)
  17910. {
  17911. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17912. {
  17913. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17914. } //end of the same index
  17915. } // end of for GB_QUANTITY
  17916. }
  17917. else if(gunType[gun_index] == GUN_TYPE_DO)
  17918. {
  17919. tempIndex = gun_index;
  17920. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17921. {
  17922. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17923. {
  17924. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17925. } //end of the same index
  17926. }
  17927. }
  17928. else
  17929. {
  17930. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17931. {
  17932. tempIndex = 2;
  17933. }
  17934. else
  17935. {
  17936. tempIndex = gun_index;
  17937. }
  17938. for (int index = 0; index < AC_QUANTITY; index++)
  17939. {
  17940. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17941. {
  17942. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17943. }//end of the same index
  17944. }//end of for AC_QUANTITY
  17945. }
  17946. return result;
  17947. }
  17948. void refreshProcDogTimer()
  17949. {
  17950. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  17951. }
  17952. void InitialSystemValue(void)
  17953. {
  17954. localversion=0;
  17955. BootNotificationInterval = 10;
  17956. authorizeRetryTimes = 0;
  17957. GunStatusInterval = 10;
  17958. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  17959. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  17960. //Hear Beat
  17961. HeartBeatWithNOResponse = 0;
  17962. HeartBeatCountPerHour = 0;
  17963. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  17964. FirstHeartBeat = 0;
  17965. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  17966. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  17967. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17968. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17969. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17970. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17971. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17972. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17973. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17974. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17975. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17976. //Status && ConnectorPlugIn Setting
  17977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17978. {
  17979. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17980. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17981. }
  17982. for (int index = 0; index < CCS_QUANTITY; index++)
  17983. {
  17984. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17985. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17986. }
  17987. for (int index = 0; index < GB_QUANTITY; index++)
  17988. {
  17989. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17990. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17991. }
  17992. for (int index = 0; index < AC_QUANTITY; index++)
  17993. {
  17994. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17995. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17996. }
  17997. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17998. {
  17999. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18000. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18001. }
  18002. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18003. {
  18004. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  18005. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  18006. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  18007. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18008. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  18009. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  18010. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  18011. }
  18012. refreshStartTimer(&clientTime.Heartbeat);
  18013. sleep(1);
  18014. }
  18015. void LWS_Send(char *str)
  18016. {
  18017. //=====================================================
  18018. // Check InternetConn 0: disconnected, 1: connected
  18019. //====================================================
  18020. if(GetOcppConnStatus() == 0)
  18021. {
  18022. DEBUG_INFO("offline now !!!\n");
  18023. return;
  18024. }
  18025. // Only disable isWebsocketSendable operation initiated by charger
  18026. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18027. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18028. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  18029. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18030. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18031. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  18032. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  18033. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18034. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18035. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18036. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  18037. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  18038. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  18039. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  18040. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  18041. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  18042. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  18043. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  18044. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  18045. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  18046. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  18047. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18048. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18049. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18050. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  18051. {
  18052. isWebsocketSendable = OFF;
  18053. }
  18054. pthread_mutex_lock(&lock_send);
  18055. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18056. sprintf((char *)SendBuffer, "%s", str);
  18057. SendBufLen = strlen(str);
  18058. pthread_mutex_unlock(&lock_send);
  18059. lws_callback_on_writable(wsi_client);
  18060. //lws_service(context, 0);
  18061. //sleep(1);
  18062. }
  18063. void LWS_SendNow(char *str)
  18064. {
  18065. //=====================================================
  18066. // Check InternetConn 0: disconnected, 1: connected
  18067. //====================================================
  18068. if(GetOcppConnStatus() == 0)
  18069. {
  18070. DEBUG_INFO("offline now !!!\n");
  18071. return;
  18072. }
  18073. // Only disable isWebsocketSendable operation initiated by charger
  18074. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18075. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18076. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  18077. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18078. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18079. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  18080. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  18081. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18082. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18083. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18084. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  18085. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  18086. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  18087. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  18088. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  18089. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  18090. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  18091. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  18092. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  18093. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  18094. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  18095. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18096. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18097. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18098. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  18099. {
  18100. isWebsocketSendable = OFF;
  18101. }
  18102. pthread_mutex_lock(&lock_send);
  18103. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18104. sprintf((char *)SendBuffer, "%s", str);
  18105. SendBufLen = strlen(str);
  18106. pthread_mutex_unlock(&lock_send);
  18107. lws_callback_on_writable(wsi_client);
  18108. lws_service(context, 0);
  18109. //sleep(1);
  18110. }