MessageHandler.c 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *SecurityEventEnumTypeStr[] = {
  50. MACROSTR(FirmwareUpdated),
  51. MACROSTR(FailedToAuthenticateAtCsms),
  52. MACROSTR(CsmsFailedToAuthenticate),
  53. MACROSTR(SettingSystemTime),
  54. MACROSTR(StartupOfTheDevice),
  55. MACROSTR(ResetOrReboot),
  56. MACROSTR(SecurityLogWasCleared),
  57. MACROSTR(ReconfigurationOfSecurityParameters),
  58. MACROSTR(MemoryExhaustion),
  59. MACROSTR(InvalidMessages),
  60. MACROSTR(AttemptedReplayAttacks),
  61. MACROSTR(TamperDetectionActivated),
  62. MACROSTR(InvalidFirmwareSignature),
  63. MACROSTR(InvalidFirmwareSigningCertificate),
  64. MACROSTR(InvalidCsmsCertificate),
  65. MACROSTR(InvalidChargingStationCertificate),
  66. MACROSTR(InvalidTLSVersion),
  67. MACROSTR(InvalidTLSCipherSuite)
  68. };
  69. static char *CancelReservationStatusEnumTypeStr[] = {
  70. MACROSTR(Accepted),
  71. MACROSTR(Rejected)
  72. };
  73. static char *CertificateActionEnumTypeStr[] = {
  74. MACROSTR(Install),
  75. MACROSTR(Update)
  76. };
  77. static char *CertificateSignedStatusEnumTypeStr[] = {
  78. MACROSTR(Accepted),
  79. MACROSTR(Rejected)
  80. };
  81. static char *CertificateSigningUseEnumTypeStr[] = {
  82. MACROSTR(ChargingStationCertificate),
  83. MACROSTR(V2GCertificate)
  84. };
  85. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  86. MACROSTR(Accepted),
  87. MACROSTR(Rejected),
  88. MACROSTR(Scheduled)
  89. };
  90. #if 0
  91. static char *ChargingLimitSourceEnumTypeStr[] = {
  92. MACROSTR(EMS),
  93. MACROSTR(Other),
  94. MACROSTR(SO),
  95. MACROSTR(CSO)
  96. };
  97. #endif
  98. static char *ChargingProfileKindEnumTypeStr[] = {
  99. MACROSTR(Absolute),
  100. MACROSTR(Recurring),
  101. MACROSTR(Relative)
  102. };
  103. static char *ChargingProfilePurposeEnumTypeStr[] = {
  104. MACROSTR(ChargingStationExternalConstraints),
  105. MACROSTR(ChargingStationMaxProfile),
  106. MACROSTR(TxDefaultProfile),
  107. MACROSTR(TxProfile)
  108. };
  109. static char *ChargingProfileStatusEnumTypeStr[] = {
  110. MACROSTR(Accepted),
  111. MACROSTR(Rejected)
  112. };
  113. static char *ChargingRateUnitEnumTypeStr[] = {
  114. MACROSTR(W),
  115. MACROSTR(A)
  116. };
  117. static char *ChargingStateEnumTypeStr[] = {
  118. MACROSTR(Charging),
  119. MACROSTR(EVConnected),
  120. MACROSTR(SuspendedEV),
  121. MACROSTR(SuspendedEVSE),
  122. MACROSTR(Idle)
  123. };
  124. static char *ClearCacheStatusEnumTypeStr[] = {
  125. MACROSTR(Accepted),
  126. MACROSTR(Rejected)
  127. };
  128. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  129. MACROSTR(Accepted),
  130. MACROSTR(Unknown)
  131. };
  132. static char *ClearMessageStatusEnumTypeStr[] = {
  133. MACROSTR(Accepted),
  134. MACROSTR(Unknown)
  135. };
  136. static char *ClearMonitoringStatusEnumTypeStr[] = {
  137. MACROSTR(Accepted),
  138. MACROSTR(Rejected),
  139. MACROSTR(NotFound)
  140. };
  141. static char *ComponentCriterionEnumTypeStr[] = {
  142. MACROSTR(Active),
  143. MACROSTR(Available),
  144. MACROSTR(Enabled),
  145. MACROSTR(Problem)
  146. };
  147. #if 0
  148. static char *ConnectorEnumTypeStr[] = {
  149. MACROSTR(cCCS1),
  150. MACROSTR(cCCS2),
  151. MACROSTR(cG105),
  152. MACROSTR(cTesla),
  153. MACROSTR(cType1),
  154. MACROSTR(cType2),
  155. MACROSTR(s309-1P-16A),
  156. MACROSTR(s309-1P-32A),
  157. MACROSTR(s309-3P-16A),
  158. MACROSTR(s309-3P-32A),
  159. MACROSTR(sBS1361),
  160. MACROSTR(sCEE-7-7),
  161. MACROSTR(sType2),
  162. MACROSTR(sType3),
  163. MACROSTR(Other1PhMax16A),
  164. MACROSTR(Other1PhOver16A),
  165. MACROSTR(Other3Ph),
  166. MACROSTR(Pan),
  167. MACROSTR(wInductive),
  168. MACROSTR(wResonant),
  169. MACROSTR(Undetermined),
  170. MACROSTR(Unknown)
  171. };
  172. #endif
  173. static char *ConnectorStatusEnumTypeStr[] = {
  174. MACROSTR(Available),
  175. MACROSTR(Occupied),
  176. MACROSTR(Reserved),
  177. MACROSTR(Unavailable),
  178. MACROSTR(Faulted)
  179. };
  180. #if 0
  181. static char *CostKindEnumTypeStr[] = {
  182. MACROSTR(CarbonDioxideEmission),
  183. MACROSTR(RelativePricePercentage),
  184. MACROSTR(RenewableGenerationPercentage)
  185. };
  186. #endif
  187. static char *CustomerInformationStatusEnumTypeStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(Invalid)
  191. };
  192. static char *DataEnumTypeStr[] = {
  193. MACROSTR(string),
  194. MACROSTR(decimal),
  195. MACROSTR(integer),
  196. MACROSTR(dateTime),
  197. MACROSTR(boolean),
  198. MACROSTR(OptionList),
  199. MACROSTR(SequenceList),
  200. MACROSTR(MemberList)
  201. };
  202. static char *DataTransferStatusEnumTypeStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected),
  205. MACROSTR(UnknownMessageId),
  206. MACROSTR(UnknownVendorId)
  207. };
  208. static char *DeleteCertificateStatusEnumTypeStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Failed),
  211. MACROSTR(NotFound)
  212. };
  213. static char *DisplayMessageStatusEnumTypeStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(NotSupportedMessageFormat),
  216. MACROSTR(Rejected),
  217. MACROSTR(NotSupportedPriority),
  218. MACROSTR(NotSupportedState),
  219. MACROSTR(UnknownTransaction)
  220. };
  221. #if 0
  222. static char *EnergyTransferModeEnumTypeStr[] = {
  223. MACROSTR(DC),
  224. MACROSTR(AC_single_phase),
  225. MACROSTR(AC_two_phase),
  226. MACROSTR(AC_three_phase)
  227. };
  228. #endif
  229. static char *EventNotificationEnumTypeStr[] = {
  230. MACROSTR(HardWiredNotification),
  231. MACROSTR(HardWiredMonitor),
  232. MACROSTR(PreconfiguredMonitor),
  233. MACROSTR(CustomMonitor)
  234. };
  235. static char *EventTriggerEnumTypeStr[] = {
  236. MACROSTR(Alerting),
  237. MACROSTR(Delta),
  238. MACROSTR(Periodic)
  239. };
  240. static char *FirmwareStatusEnumTypeStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(DownloadScheduled),
  245. MACROSTR(DownloadPaused),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed),
  250. MACROSTR(InstallRebooting),
  251. MACROSTR(InstallScheduled),
  252. MACROSTR(InstallVerificationFailed),
  253. MACROSTR(InvalidSignature),
  254. MACROSTR(SignatureVerified)
  255. };
  256. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected),
  259. MACROSTR(NotSupported),
  260. MACROSTR(EmptyResultSet)
  261. };
  262. static char *GenericStatusEnumTypeStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected)
  265. };
  266. static char *GetCertificateIdUseEnumTypeStr[] = {
  267. MACROSTR(V2GRootCertificate),
  268. MACROSTR(MORootCertificate),
  269. MACROSTR(CSMSRootCertificate),
  270. MACROSTR(V2GCertificateChain),
  271. MACROSTR(ManufacturerRootCertificate)
  272. };
  273. static char *GetCertificateStatusEnumTypeStr[] = {
  274. MACROSTR(Accepted),
  275. MACROSTR(Failed)
  276. };
  277. static char *GetChargingProfileStatusEnumTypeStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(NoProfiles)
  280. };
  281. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Unknown)
  284. };
  285. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(NotFound)
  288. };
  289. static char *GetVariableStatusEnumTypeStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected),
  292. MACROSTR(UnknownComponent),
  293. MACROSTR(UnknownVariable),
  294. MACROSTR(NotSupportedAttributeType)
  295. };
  296. static char *HashAlgorithmEnumTypeStr[] = {
  297. MACROSTR(SHA256),
  298. MACROSTR(SHA384),
  299. MACROSTR(SHA512)
  300. };
  301. static char *IdTokenEnumTypeStr[] = {
  302. MACROSTR(Central),
  303. MACROSTR(eMAID),
  304. MACROSTR(ISO14443),
  305. MACROSTR(ISO15693),
  306. MACROSTR(KeyCode),
  307. MACROSTR(Local),
  308. MACROSTR(MacAddress),
  309. MACROSTR(NoAuthorization),
  310. };
  311. static char *InstallCertificateUseEnumTypeStr[] = {
  312. MACROSTR(V2GRootCertificate),
  313. MACROSTR(MORootCertificate),
  314. MACROSTR(CSMSRootCertificate),
  315. MACROSTR(ManufacturerRootCertificate)
  316. };
  317. static char *InstallCertificateStatusEnumTypeStr[]={
  318. MACROSTR(Accepted),
  319. MACROSTR(Failed),
  320. MACROSTR(Rejected)
  321. };
  322. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  323. MACROSTR(Accepted),
  324. MACROSTR(Failed)
  325. };
  326. static char *LocationEnumTypeStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char *LogEnumTypeStr[] = {
  334. MACROSTR(DiagnosticsLog),
  335. MACROSTR(SecurityLog)
  336. };
  337. static char *LogStatusEnumTypeStr[] = {
  338. MACROSTR(Accepted),
  339. MACROSTR(Rejected),
  340. MACROSTR(AcceptedCanceled)
  341. };
  342. static char *MeasurandEnumTypeStr[] = {
  343. MACROSTR(Current.Export),
  344. MACROSTR(Current.Import),
  345. MACROSTR(Current.Offered),
  346. MACROSTR(Energy.Active.Export.Register),
  347. MACROSTR(Energy.Active.Import.Register),
  348. MACROSTR(Energy.Reactive.Export.Register),
  349. MACROSTR(Energy.Reactive.Import.Register),
  350. MACROSTR(Energy.Active.Export.Interval),
  351. MACROSTR(Energy.Active.Import.Interval),
  352. MACROSTR(Energy.Active.Net),
  353. MACROSTR(Energy.Reactive.Export.Interval),
  354. MACROSTR(Energy.Reactive.Import.Interval),
  355. MACROSTR(Energy.Reactive.Net),
  356. MACROSTR(Energy.Apparent.Net),
  357. MACROSTR(Energy.Apparent.Import),
  358. MACROSTR(Energy.Apparent.Export),
  359. MACROSTR(Frequency),
  360. MACROSTR(Power.Active.Export),
  361. MACROSTR(Power.Active.Import),
  362. MACROSTR(Power.Factor),
  363. MACROSTR(Power.Offered),
  364. MACROSTR(Power.Reactive.Export),
  365. MACROSTR(Power.Reactive.Import),
  366. MACROSTR(SoC),
  367. MACROSTR(Voltage)
  368. };
  369. static char *MessageFormatEnumTypeStr[] = {
  370. MACROSTR(ASCII),
  371. MACROSTR(HTML),
  372. MACROSTR(URI),
  373. MACROSTR(UTF8)
  374. };
  375. static char *MessagePriorityEnumTypeStr[] = {
  376. MACROSTR(AlwaysFront),
  377. MACROSTR(InFront),
  378. MACROSTR(NormalCycle)
  379. };
  380. static char *MessageStateEnumTypeStr[] = {
  381. MACROSTR(Charging),
  382. MACROSTR(Faulted),
  383. MACROSTR(Idle),
  384. MACROSTR(Unavailable)
  385. };
  386. static char *MessageTriggerEnumTypeStr[] = {
  387. MACROSTR(BootNotification),
  388. MACROSTR(LogStatusNotification),
  389. MACROSTR(FirmwareStatusNotification),
  390. MACROSTR(Heartbeat),
  391. MACROSTR(MeterValues),
  392. MACROSTR(SignChargingStationCertificate),
  393. MACROSTR(SignV2GCertificate),
  394. MACROSTR(StatusNotification),
  395. MACROSTR(TransactionEvent),
  396. MACROSTR(SignCombinedCertificate),
  397. MACROSTR(PublishFirmwareStatusNotification)
  398. };
  399. static char *MonitorEnumTypeStr[] = {
  400. MACROSTR(UpperThreshold),
  401. MACROSTR(LowerThreshold),
  402. MACROSTR(Delta),
  403. MACROSTR(Periodic),
  404. MACROSTR(PeriodicClockAligned)
  405. };
  406. static char *MonitoringBaseEnumTypeStr[] = {
  407. MACROSTR(All),
  408. MACROSTR(FactoryDefault),
  409. MACROSTR(HardWiredOnly)
  410. };
  411. static char *MonitoringCriterionEnumTypeStr[] = {
  412. MACROSTR(ThresholdMonitoring),
  413. MACROSTR(DeltaMonitoring),
  414. MACROSTR(PeriodicMonitoring)
  415. };
  416. static char *MutabilityEnumTypeStr[] = {
  417. MACROSTR(ReadOnly),
  418. MACROSTR(WriteOnly),
  419. MACROSTR(ReadWrite)
  420. };
  421. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Rejected),
  424. MACROSTR(Processing)
  425. };
  426. static char *OCPPInterfaceEnumTypeStr[] = {
  427. MACROSTR(Wired0),
  428. MACROSTR(Wired1),
  429. MACROSTR(Wired2),
  430. MACROSTR(Wired3),
  431. MACROSTR(Wireless0),
  432. MACROSTR(Wireless1),
  433. MACROSTR(Wireless2),
  434. MACROSTR(Wireless3)
  435. };
  436. static char *OCPPTransportEnumTypeStr[] = {
  437. MACROSTR(JSON),
  438. MACROSTR(SOAP)
  439. };
  440. static char *OCPPVersionEnumTypeStr[] = {
  441. MACROSTR(OCPP12),
  442. MACROSTR(OCPP15),
  443. MACROSTR(OCPP16),
  444. MACROSTR(OCPP20)
  445. };
  446. static char *OperationalStatusEnumTypeStr[] = {
  447. MACROSTR(Inoperative),
  448. MACROSTR(Operative)
  449. };
  450. static char *PhaseEnumTypeStr[] = {
  451. MACROSTR(L1),
  452. MACROSTR(L2),
  453. MACROSTR(L3),
  454. MACROSTR(N),
  455. MACROSTR(L1-N),
  456. MACROSTR(L2-N),
  457. MACROSTR(L3-N),
  458. MACROSTR(L1-L2),
  459. MACROSTR(L2-L3),
  460. MACROSTR(L3-L1)
  461. };
  462. static char *PublishFirmwareStatusEnumTypeStr[] = {
  463. MACROSTR(Downloaded),
  464. MACROSTR(DownloadFailed),
  465. MACROSTR(Downloading),
  466. MACROSTR(DownloadScheduled),
  467. MACROSTR(DownloadPaused),
  468. MACROSTR(PublishFailed),
  469. MACROSTR(Published),
  470. MACROSTR(InvalidChecksum),
  471. MACROSTR(ChecksumVerified)
  472. };
  473. static char *ReadingContextEnumTypeStr[] = {
  474. MACROSTR(Interruption.Begin),
  475. MACROSTR(Interruption.End),
  476. MACROSTR(Other),
  477. MACROSTR(Sample.Clock),
  478. MACROSTR(Sample.Periodic),
  479. MACROSTR(Transaction.Begin),
  480. MACROSTR(Transaction.End),
  481. MACROSTR(Trigger)
  482. };
  483. #if 0
  484. static char *ReasonEnumTypeStr[] = {
  485. MACROSTR(DeAuthorized),
  486. MACROSTR(EmergencyStop),
  487. MACROSTR(EnergyLimitReached),
  488. MACROSTR(EVDisconnected),
  489. MACROSTR(GroundFault),
  490. MACROSTR(ImmediateReset),
  491. MACROSTR(Local),
  492. MACROSTR(LocalOutOfCredit),
  493. MACROSTR(MasterPass),
  494. MACROSTR(Other),
  495. MACROSTR(OvercurrentFault),
  496. MACROSTR(PowerLoss),
  497. MACROSTR(PowerQuality),
  498. MACROSTR(Reboot),
  499. MACROSTR(Remote),
  500. MACROSTR(SOCLimitReached),
  501. MACROSTR(StoppedByEV),
  502. MACROSTR(TimeLimitReached),
  503. MACROSTR(TimeLimitReached)
  504. };
  505. #endif
  506. static char *RecurrencyKindEnumTypeStr[] = {
  507. MACROSTR(Daily),
  508. MACROSTR(Weekly)
  509. };
  510. static char *RegistrationStatusEnumTypeStr[] = {
  511. MACROSTR(Accepted),
  512. MACROSTR(Pending),
  513. MACROSTR(Rejected)
  514. };
  515. static char *ReportBaseEnumTypeStr[] = {
  516. MACROSTR(ConfigurationInventory),
  517. MACROSTR(FullInventory),
  518. MACROSTR(SummaryInventory)
  519. };
  520. static char *RequestStartStopStatusEnumTypeStr[] = {
  521. MACROSTR(Accepted),
  522. MACROSTR(Rejected)
  523. };
  524. static char *ReservationUpdateStatusEnumTypeStr[] = {
  525. MACROSTR(Expired),
  526. MACROSTR(Removed)
  527. };
  528. static char *ReserveNowStatusEnumTypeStr[] = {
  529. MACROSTR(Accepted),
  530. MACROSTR(Faulted),
  531. MACROSTR(Occupied),
  532. MACROSTR(Rejected),
  533. MACROSTR(Unavailable)
  534. };
  535. static char *ResetEnumTypeStr[] = {
  536. MACROSTR(Immediate),
  537. MACROSTR(OnIdle)
  538. };
  539. static char *ResetStatusEnumTypeStr[] = {
  540. MACROSTR(Accepted),
  541. MACROSTR(Rejected),
  542. MACROSTR(Scheduled)
  543. };
  544. static char *SetMonitoringStatusEnumTypeStr[] = {
  545. MACROSTR(Accepted),
  546. MACROSTR(UnknownComponent),
  547. MACROSTR(UnknownVariable),
  548. MACROSTR(UnsupportedMonitorType),
  549. MACROSTR(Rejected),
  550. MACROSTR(OutOfRange),
  551. MACROSTR(Duplicate)
  552. };
  553. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  554. MACROSTR(Accepted),
  555. MACROSTR(Rejected),
  556. MACROSTR(Failed)
  557. };
  558. static char *SetVariableStatusEnumTypeStr[] = {
  559. MACROSTR(Accepted),
  560. MACROSTR(Rejected),
  561. MACROSTR(InvalidValue),
  562. MACROSTR(UnknownComponent),
  563. MACROSTR(UnknownVariable),
  564. MACROSTR(NotSupportedAttributeType),
  565. MACROSTR(OutOfRange),
  566. MACROSTR(RebootRequired)
  567. };
  568. static char *TransactionEventEnumTypeStr[] = {
  569. MACROSTR(Ended),
  570. MACROSTR(Started),
  571. MACROSTR(Updated)
  572. };
  573. static char *TriggerMessageStatusEnumTypeStr[] = {
  574. MACROSTR(Accepted),
  575. MACROSTR(Rejected),
  576. MACROSTR(NotImplemented)
  577. };
  578. static char *TriggerReasonEnumTypeStr[] = {
  579. MACROSTR(Authorized),
  580. MACROSTR(CablePluggedIn),
  581. MACROSTR(ChargingRateChanged),
  582. MACROSTR(ChargingStateChanged),
  583. MACROSTR(Deauthorized),
  584. MACROSTR(EnergyLimitReached),
  585. MACROSTR(EVCommunicationLost),
  586. MACROSTR(EVConnectTimeout),
  587. MACROSTR(MeterValueClock),
  588. MACROSTR(MeterValuePeriodic),
  589. MACROSTR(TimeLimitReached),
  590. MACROSTR(Trigger),
  591. MACROSTR(UnlockCommand),
  592. MACROSTR(StopAuthorized),
  593. MACROSTR(EVDeparted),
  594. MACROSTR(EVDetected),
  595. MACROSTR(RemoteStop),
  596. MACROSTR(RemoteStart),
  597. MACROSTR(AbnormalCondition),
  598. MACROSTR(SignedDataReceived),
  599. MACROSTR(ResetCommand)
  600. };
  601. static char *UnlockStatusEnumTypeStr[] = {
  602. MACROSTR(Unlocked),
  603. MACROSTR(UnlockFailed),
  604. MACROSTR(OngoingAuthorizedTransaction),
  605. MACROSTR(UnknownConnector)
  606. };
  607. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  608. MACROSTR(DownloadOngoing),
  609. MACROSTR(NoFirmware),
  610. MACROSTR(Unpublished)
  611. };
  612. static char *UpdateEnumTypeStr[] = {
  613. MACROSTR(Differential),
  614. MACROSTR(Full)
  615. };
  616. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  617. MACROSTR(Accepted),
  618. MACROSTR(Rejected),
  619. MACROSTR(AcceptedCanceled),
  620. MACROSTR(InvalidCertificate),
  621. MACROSTR(RevokedCertificate)
  622. };
  623. static char *UpdateStatusEnumTypeStr[] = {
  624. MACROSTR(Accepted),
  625. MACROSTR(Failed),
  626. MACROSTR(VersionMismatch)
  627. };
  628. static char *UploadLogStatusEnumTypeStr[] = {
  629. MACROSTR(BadMessage),
  630. MACROSTR(Idle),
  631. MACROSTR(NotSupportedOperation),
  632. MACROSTR(PermissionDenied),
  633. MACROSTR(Uploaded),
  634. MACROSTR(UploadFailure),
  635. MACROSTR(Uploading),
  636. MACROSTR(AcceptedCanceled)
  637. };
  638. static char *VPNEnumTypeStr[] = {
  639. MACROSTR(IKEv2),
  640. MACROSTR(IPSec),
  641. MACROSTR(L2TP),
  642. MACROSTR(PPTP)
  643. };
  644. #if 0
  645. static char *ChargePointErrorCodeEnumTypeStr[] = {
  646. MACROSTR(ConnectorLockFailure),
  647. MACROSTR(EVCommunicationError),
  648. MACROSTR(GroundFailure),
  649. MACROSTR(HighTemperature),
  650. MACROSTR(InternalError),
  651. MACROSTR(LocalListConflict),
  652. MACROSTR(NoError),
  653. MACROSTR(OtherError),
  654. MACROSTR(OverCurrentFailure),
  655. MACROSTR(OverVoltage),
  656. MACROSTR(PowerMeterFailure),
  657. MACROSTR(PowerSwitchFailure),
  658. MACROSTR(ReaderFailure),
  659. MACROSTR(ResetFailure),
  660. MACROSTR(UnderVoltage),
  661. MACROSTR(WeakSignal)
  662. };
  663. #endif
  664. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  665. MACROSTR(Accepted),
  666. MACROSTR(Rejected)
  667. };
  668. static char *RemoteStartStopStatusEnumTypeStr[] = {
  669. MACROSTR(Accepted),
  670. MACROSTR(Rejected)
  671. };
  672. #if 0
  673. static char * StopTransactionReasonEnumTypeStr[] = {
  674. MACROSTR(EmergencyStop),
  675. MACROSTR(EVDisconnected),
  676. MACROSTR(HardReset),
  677. MACROSTR(Local),
  678. MACROSTR(Other),
  679. MACROSTR(PowerLoss),
  680. MACROSTR(Reboot),
  681. MACROSTR(Remote),
  682. MACROSTR(SoftReset),
  683. MACROSTR(UnlockCommand),
  684. MACROSTR(DeAuthorized)
  685. };
  686. #endif
  687. //ChargePointMaxProfile
  688. #define ChargingStationMaxProfile_JSON "/Storage/OCPP/ChargingStationMaxProfile_OCPP20.json"
  689. //TxDefaultProfile
  690. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  691. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  692. struct StatusCodeData *ShmStatusCodeData;
  693. struct PsuData *ShmPsuData ;
  694. struct OCPP20Data *ShmOCPP20Data;
  695. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  696. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  697. //===============================
  698. // Gun Total Numbers
  699. //===============================
  700. static ParsingRatedCur modelnameInfo = {0};
  701. static int gunTotalNumber = 0;
  702. static uint8_t gunType[4] = {0};
  703. //===============================
  704. // Local List Version
  705. //===============================
  706. static int localversion=0;
  707. //===============================
  708. // Variable Version
  709. //===============================
  710. static int variableVersion=8;
  711. //===============================
  712. // OCPP sign variable
  713. //===============================
  714. static int server_sign = FALSE;
  715. int server_pending = FALSE;
  716. static int BootNotificationInterval = 10;
  717. //===============================
  718. // OCPP auth variable
  719. //===============================
  720. static int authorizeRetryTimes = 0; //number of Retry times
  721. //===============================
  722. // OCPP other variables
  723. //===============================
  724. static int HeartBeatWaitTime = 10;
  725. static int FirstHeartBeat = 0;
  726. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  727. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  728. static char CurrentChargingProfileScheduleStr[30] = {0};
  729. static int isCancelUploadLog = FALSE;
  730. pthread_t th_GetLog;
  731. //========================================
  732. // OCPP status/previous related variables
  733. //========================================
  734. static int GunStatusInterval = 10;
  735. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  736. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  737. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  738. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  739. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  740. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  741. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  742. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  743. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  744. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  745. static int TransactionMessageAttemptsValue = 0;
  746. static int TransactionMessageRetryIntervalValue = 0;
  747. static struct AuthorizationData idTagQuery;
  748. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  749. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  750. //=============================================
  751. // OCPP HeartBeat Response Not Receive Counts
  752. //============================================
  753. static int HeartBeatWithNOResponse = 0;
  754. static int HeartBeatCountPerHour = 0;
  755. sqlite3 *db;
  756. int TransactionMessageAttemptsGet(void);
  757. int TransactionMessageRetryIntervalGet(void);
  758. int GetOcppConnStatus(void);
  759. void SetOcppConnStatus(uint8_t status);
  760. int setKeyValue(char *key, char *value);
  761. void OCPP_get_TableAuthlocalAllData(void);
  762. void processUnkownKey(void);
  763. struct InterLock
  764. {
  765. unsigned char isGetLogGoing:1;
  766. unsigned char isUpdateFirmwareGoing:1;
  767. }interLock;
  768. struct ClientTime
  769. {
  770. struct timespec Heartbeat;
  771. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  772. struct timespec StartTransaction;
  773. struct timespec StopTransaction;
  774. struct timespec MeterValues[CONNECTOR_QUANTITY];
  775. struct timespec RemoteStartWait;
  776. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  777. }clientTime;
  778. typedef union
  779. {
  780. //Operations Initiated by Central System
  781. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  782. struct
  783. {
  784. //CsMsgValue[0]
  785. unsigned char StatusNotificationReq:1; //bit 0,
  786. unsigned char StatusNotificationConf:1; //bit 1,
  787. unsigned char TriggerMeterValueReq:1; //bit 2,
  788. unsigned char SampleMeterReq:1; //bit 3,
  789. unsigned char ClockAlignMeterReq:1; //bit 4,
  790. unsigned char TriggerStatusNotificationReq:1; //bit 5,
  791. unsigned char isOnCharging:1; //bit 6,
  792. unsigned char TriggerTransactionEventReq:1; //bit 7
  793. }bits[CONNECTOR_QUANTITY];
  794. }CpinitiateMsg;
  795. CpinitiateMsg cpinitateMsg;
  796. //=========================================
  797. // Save configuration
  798. //=========================================
  799. int runShellCmd(const char*cmd)
  800. {
  801. int result = FAIL;
  802. char buf[256];
  803. FILE *fp;
  804. fp = popen(cmd, "r");
  805. if(fp != NULL)
  806. {
  807. while(fgets(buf, sizeof(buf), fp) != NULL)
  808. {
  809. DEBUG_INFO("%s\n", buf);
  810. }
  811. result = PASS;
  812. }
  813. pclose(fp);
  814. return result;
  815. }
  816. int StoreUsrConfigData(struct SysConfigData *UsrData)
  817. {
  818. int result = PASS;
  819. int fd,wrd;
  820. unsigned int i,Chk;
  821. unsigned char *ptr, *BufTmp;
  822. int MtdBlockSize = 0x300000;
  823. Chk=0;
  824. ptr=(unsigned char *)UsrData;
  825. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  826. {
  827. memset(BufTmp,0,MtdBlockSize);
  828. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  829. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  830. Chk+=*(BufTmp+i);
  831. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  832. // Output configuration to file.
  833. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  834. if (fd < 0)
  835. {
  836. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  837. free(BufTmp);
  838. return 0;
  839. }
  840. wrd=write(fd, BufTmp, MtdBlockSize);
  841. close(fd);
  842. if(wrd<MtdBlockSize)
  843. {
  844. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  845. free(BufTmp);
  846. return 0;
  847. }
  848. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  849. DEBUG_INFO("Erase /dev/mtd10.\n");
  850. runShellCmd("flash_erase /dev/mtd10 0 0");
  851. DEBUG_INFO("Write /dev/mtd10.\n");
  852. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  853. DEBUG_INFO("Erase /dev/mtd11.\n");
  854. runShellCmd("flash_erase /dev/mtd11 0 0");
  855. DEBUG_INFO("Write /dev/mtd11.\n");
  856. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  857. system("rm -f /mnt/EvseConfig.bin");
  858. DEBUG_INFO("EvseConfig write to flash OK\n");
  859. }
  860. else
  861. {
  862. DEBUG_ERROR("alloc BlockSize NG\r\n");
  863. result = FAIL;
  864. }
  865. if(BufTmp!=NULL)
  866. free(BufTmp);
  867. return result;
  868. }
  869. //=========================================
  870. // Date time related function
  871. //=========================================
  872. void getNowDatetime(uint8_t *data)
  873. {
  874. time_t t = time(NULL);
  875. struct tm tm = *localtime(&t);
  876. 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);
  877. }
  878. //=========================================
  879. // Sqlite3 related function
  880. //=========================================
  881. int DB_Initial()
  882. {
  883. int result = PASS;
  884. char* errMsg = NULL;
  885. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  886. "idToken text UNIQUE,"
  887. "type text,"
  888. "status text,"
  889. "cacheExpiryDateTime text,"
  890. "chargingPriority integer,"
  891. "language1 text,"
  892. "evseId text,"
  893. "language2 text,"
  894. "groupIdToken_idToken text,"
  895. "groupIdToken_type text,"
  896. "personalMessage text);";
  897. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  898. "idToken text UNIQUE,"
  899. "type text,"
  900. "status text,"
  901. "cacheExpiryDateTime text,"
  902. "chargingPriority integer,"
  903. "language1 text,"
  904. "evseId text,"
  905. "language2 text,"
  906. "groupIdToken_idToken text,"
  907. "groupIdToken_type text,"
  908. "personalMessage text,"
  909. "version text);";
  910. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  911. "componentName text NOT NULL ,"
  912. "componentInstance text, "
  913. "variableName text NOT NULL, "
  914. "variableInstance text, "
  915. "variableCharacteristicsDataType integer, "
  916. "variableCharacteristicsUnit text, "
  917. "variableCharacteristicsMaxLimit real,"
  918. "variableAttributesType text, "
  919. "variableAttributesTypeMutability text, "
  920. "variableAttributesTypeValue text, "
  921. "variableCharacteristicsMinLimit real,"
  922. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  923. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  924. "type text);";
  925. char *sqlSecurityEventType = "create table if not exists ocpp20_securityevent_type (idx integer primary key,"
  926. "type text);";
  927. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  928. "slot integer UNIQUE, connectionData text);";
  929. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  930. "occurDatetime text,"
  931. "message_type text,"
  932. "message_content text)";
  933. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  934. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  935. {
  936. result = FAIL;
  937. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  938. sqlite3_close(db);
  939. }
  940. else
  941. {
  942. DEBUG_INFO( "OCPP local database open successfully.\n");
  943. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  944. {
  945. result = FAIL;
  946. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  947. }
  948. else
  949. {
  950. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  951. }
  952. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  953. {
  954. result = FAIL;
  955. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  956. }
  957. else
  958. {
  959. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  960. }
  961. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  962. {
  963. result = FAIL;
  964. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  965. }
  966. else
  967. {
  968. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  969. }
  970. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  971. {
  972. result = FAIL;
  973. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  974. }
  975. else
  976. {
  977. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  978. }
  979. if (sqlite3_exec(db, sqlSecurityEventType, 0, 0, &errMsg) != SQLITE_OK)
  980. {
  981. result = FAIL;
  982. DEBUG_ERROR( "Create OCPP 2.0 securityevent_type table error message: %s\n", errMsg);
  983. }
  984. else
  985. {
  986. DEBUG_INFO( "Create OCPP 2.0 securityevent_type table successfully\n");
  987. }
  988. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  989. {
  990. result = FAIL;
  991. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  992. }
  993. else
  994. {
  995. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  996. }
  997. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  998. {
  999. result = FAIL;
  1000. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  1001. }
  1002. else
  1003. {
  1004. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  1005. }
  1006. //sqlite3_close(db);
  1007. }
  1008. return result;
  1009. }
  1010. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  1011. {
  1012. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  1013. return 0;
  1014. }
  1015. void DB_getListVerion()
  1016. {
  1017. char sql[256];
  1018. char* errMsg = NULL;
  1019. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  1020. /* Execute SQL statement */
  1021. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  1022. {
  1023. DEBUG_INFO("SQL error: %s", errMsg);
  1024. }
  1025. }
  1026. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  1027. {
  1028. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  1029. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  1030. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  1031. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  1032. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  1033. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  1034. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  1035. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  1036. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  1037. return 0;
  1038. }
  1039. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1040. {
  1041. char sql[256];
  1042. char* errMsg = NULL;
  1043. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1044. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1045. if(isQueryFromCache)
  1046. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1047. else
  1048. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1049. /* Execute SQL statement */
  1050. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1051. {
  1052. DEBUG_INFO("SQL error: %s", errMsg);
  1053. }
  1054. }
  1055. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1056. {
  1057. for (int i = 0; i < columnCount; i++)
  1058. {
  1059. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1060. }
  1061. return 0;
  1062. }
  1063. void DB_get_TableAuthlocalAllData(void)
  1064. {
  1065. char sql[256];
  1066. char* errMsg = NULL;
  1067. sprintf(sql,"select * from ocpp20_auth_local;");
  1068. /* Execute SQL statement */
  1069. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1070. {
  1071. DEBUG_INFO("SQL error: %s", errMsg);
  1072. }
  1073. }
  1074. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1075. {
  1076. for(int i = 0; i<columnCount; i++)
  1077. {
  1078. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1079. }
  1080. return 0;
  1081. }
  1082. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1083. {
  1084. int result = PASS;
  1085. char sql[512];
  1086. char* errMsg = NULL;
  1087. 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;",
  1088. data->idToken.idToken,
  1089. data->idToken.type,
  1090. data->idTokenInfo.status,
  1091. data->idTokenInfo.cacheExpiryDateTime,
  1092. data->idTokenInfo.chargingPriority,
  1093. data->idTokenInfo.language1,
  1094. data->idTokenInfo.language2,
  1095. data->idTokenInfo.groupIdToken.idToken,
  1096. data->idTokenInfo.groupIdToken.type,
  1097. listVersion);
  1098. //* Execute SQL statement */
  1099. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1100. {
  1101. DEBUG_INFO("SQL error: %s\n", errMsg);
  1102. result = FAIL;
  1103. }
  1104. else
  1105. {
  1106. memset(sql, 0, ARRAY_SIZE(sql));
  1107. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1108. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1109. {
  1110. DEBUG_INFO("SQL error: %s\n", errMsg);
  1111. result = FAIL;
  1112. }
  1113. }
  1114. return result;
  1115. }
  1116. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1117. {
  1118. int result = PASS;
  1119. char sql[512];
  1120. char* errMsg = NULL;
  1121. 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;",
  1122. idToken->idToken,
  1123. idToken->type,
  1124. idTokenInfo->status,
  1125. idTokenInfo->cacheExpiryDateTime,
  1126. idTokenInfo->chargingPriority,
  1127. idTokenInfo->language1,
  1128. idTokenInfo->language2,
  1129. idTokenInfo->groupIdToken.idToken,
  1130. idTokenInfo->groupIdToken.type);
  1131. //* Execute SQL statement */
  1132. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1133. {
  1134. DEBUG_INFO("SQL error: %s\n", errMsg);
  1135. result = FAIL;
  1136. }
  1137. return result;
  1138. }
  1139. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1140. {
  1141. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1142. // printf("localversion=%d\n", localversion);
  1143. return 0;
  1144. }
  1145. void DB_deleteIdTag(char idTag[])
  1146. {
  1147. char sql[512];
  1148. char* errMsg = NULL;
  1149. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1150. //* Execute SQL statement */
  1151. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1152. {
  1153. DEBUG_INFO("SQL error: %s", errMsg);
  1154. }
  1155. }
  1156. int DB_cleanLocalList()
  1157. {
  1158. int result = PASS;
  1159. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1160. char *errMsg = 0;
  1161. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1162. {
  1163. DEBUG_INFO("%s\n", errMsg);
  1164. result = FAIL;
  1165. }
  1166. return result;
  1167. }
  1168. int DB_cleanLocalCache()
  1169. {
  1170. int result = PASS;
  1171. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1172. char *errMsg = 0;
  1173. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1174. {
  1175. DEBUG_INFO("%s\n", errMsg);
  1176. result = FAIL;
  1177. }
  1178. return result;
  1179. }
  1180. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1181. {
  1182. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1183. return 0;
  1184. }
  1185. void DB_getBooType()
  1186. {
  1187. char sql[256];
  1188. char* errMsg = NULL;
  1189. sprintf(sql,"select * from ocpp20_boot_type;");
  1190. /* Execute SQL statement */
  1191. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1192. {
  1193. DEBUG_INFO("SQL error: %s\n", errMsg);
  1194. }
  1195. }
  1196. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1197. {
  1198. for(int i = 0; i<columnCount; i++)
  1199. {
  1200. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1201. }
  1202. return 0;
  1203. }
  1204. int DB_updateBootType(BootReasonEnumType reason)
  1205. {
  1206. int result = PASS;
  1207. char sql[512];
  1208. char* errMsg = NULL;
  1209. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1210. //* Execute SQL statement */
  1211. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1212. {
  1213. DEBUG_INFO("SQL error: %s\n", errMsg);
  1214. result = FAIL;
  1215. }
  1216. return result;
  1217. }
  1218. int SecurityEventTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1219. {
  1220. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", columnValue[1] ? columnValue[1] : SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  1221. return 0;
  1222. }
  1223. void DB_getSecurityEventType()
  1224. {
  1225. char sql[256];
  1226. char* errMsg = NULL;
  1227. sprintf(sql,"select * from ocpp20_securityevent_type;");
  1228. /* Execute SQL statement */
  1229. if(sqlite3_exec(db, sql, SecurityEventTypecallback, 0, &errMsg) != SQLITE_OK )
  1230. {
  1231. DEBUG_INFO("SQL error: %s\n", errMsg);
  1232. }
  1233. }
  1234. int DB_cbUpdateSecurityEventType(void *para, int columnCount, char **columnValue, char **columnName)
  1235. {
  1236. for(int i = 0; i<columnCount; i++)
  1237. {
  1238. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1239. }
  1240. return 0;
  1241. }
  1242. int DB_updateSecurityEventType(SecurityEventEnumType reason)
  1243. {
  1244. int result = PASS;
  1245. char sql[512];
  1246. char* errMsg = NULL;
  1247. sprintf(sql,"insert or replace into ocpp20_securityevent_type (idx, type) VALUES(1, '%s');", SecurityEventEnumTypeStr[reason]);
  1248. //* Execute SQL statement */
  1249. if(sqlite3_exec(db, sql, DB_cbUpdateSecurityEventType, 0, &errMsg) != SQLITE_OK)
  1250. {
  1251. DEBUG_INFO("SQL error: %s\n", errMsg);
  1252. result = FAIL;
  1253. }
  1254. return result;
  1255. }
  1256. int DB_variableClear()
  1257. {
  1258. int result = PASS;
  1259. char * sqlcleanLocalList = "delete from ocpp20_variable";
  1260. char *errMsg = 0;
  1261. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1262. {
  1263. DEBUG_INFO("%s\n", errMsg);
  1264. result = FAIL;
  1265. }
  1266. return result;
  1267. }
  1268. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1269. {
  1270. for(int i = 0; i<columnCount; i++)
  1271. {
  1272. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1273. }
  1274. return 0;
  1275. }
  1276. int DB_variableSaveToDb(struct ReportDataType *variable)
  1277. {
  1278. int result = FAIL;
  1279. char sql[4096];
  1280. char* errMsg = NULL;
  1281. 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;",
  1282. variable->component.name,
  1283. variable->component.instance,
  1284. variable->variable.name,
  1285. variable->variable.instance,
  1286. variable->variableCharacteristics.dataType,
  1287. variable->variableCharacteristics.unit,
  1288. variable->variableCharacteristics.maxLimit,
  1289. variable->variableAttribute[0].type,
  1290. variable->variableAttribute[0].mutability,
  1291. variable->variableAttribute[0].value,
  1292. variable->variableCharacteristics.minLimit);
  1293. //* Execute SQL statement */
  1294. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1295. {
  1296. DEBUG_INFO("SQL error: %s\n", errMsg);
  1297. result = FAIL;
  1298. }
  1299. return result;
  1300. }
  1301. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1302. {
  1303. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1304. if(atoi(columnValue[0]) == 0)
  1305. {
  1306. DB_updateBootType(BootReasonEnumType_PowerUp);
  1307. // Create variable table content
  1308. /* AlignedDataCtrlr Required item */
  1309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "false");
  1315. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "true");
  1322. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1326. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1331. "Energy.Active.Import.Register,"
  1332. "Energy.Active.Import.Interval,"
  1333. "Power.Active.Import,"
  1334. "Voltage,"
  1335. "SoC,"
  1336. "Current.Offered,"
  1337. "Power.Offered");
  1338. else
  1339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1340. "Energy.Active.Import.Register,"
  1341. "Energy.Active.Import.Interval,"
  1342. "Power.Active.Import,"
  1343. "Voltage,"
  1344. "Current.Offered");
  1345. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1350. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 5;
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1354. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "true");
  1361. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  1368. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1372. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1375. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1377. "Energy.Active.Import.Register,"
  1378. "Energy.Active.Import.Interval,"
  1379. "Power.Active.Import,"
  1380. "Voltage,"
  1381. "SoC");
  1382. else
  1383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1384. "Energy.Active.Import.Register,"
  1385. "Energy.Active.Import.Interval,"
  1386. "Power.Active.Import,"
  1387. "Voltage");
  1388. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1396. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1397. /* AuthCtrlrVariable Required item */
  1398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE?"true":"false");
  1404. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AuthCtrlr");
  1406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1411. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "false");
  1418. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "false");
  1425. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true");
  1432. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true");
  1439. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1443. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1447. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1448. /* AuthCacheCtrlr Variable Required item*/
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "false");
  1455. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "true");
  1462. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "true");
  1470. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1474. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "true");
  1478. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1485. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1486. /* ClockCtrlr Variable Required item */
  1487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1492. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1493. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1500. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1508. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1515. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1522. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1530. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1537. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1544. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1545. /* ChargingStation Required item */
  1546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "false");
  1552. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1559. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1566. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  1568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  1569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].value, "0");
  1573. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec]);
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  1575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  1576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  1580. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend]);
  1581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  1583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value, "FreeVendIdtag");
  1587. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag]);
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].value, "0");
  1594. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower]);
  1595. /* Connector Required item */
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "false");
  1602. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1609. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1616. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1617. /* CustomizationCtrlr Required item */
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "false");
  1624. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1625. /* DeviceDataCtrlr Required item */
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1633. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1641. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1649. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1657. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1660. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1665. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1668. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1673. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1681. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1689. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1690. /* DisplayMessageCtrlr Required item */
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "false");
  1697. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "false");
  1704. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1708. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1712. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1719. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1724. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1726. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1727. /* EVSE Required item */
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "false");
  1734. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1741. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1748. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1755. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1756. /* LocalAuthListCtrlr Required item */
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true");
  1763. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1767. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1771. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "true");
  1778. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1783. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  1786. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  1794. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1798. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  1802. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1803. /* MonitoringCtrlr Required item */
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "false");
  1810. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "false");
  1817. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1825. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1833. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1841. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1849. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1856. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1857. /* OCPPCommCtrlr Required item */
  1858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1864. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1873. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1880. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1884. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1889. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1896. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1903. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1911. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "false");
  1918. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1927. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  1936. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "true");
  1943. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1947. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  1948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1952. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1959. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1966. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  1973. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "false");
  1980. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  1984. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  1985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  1989. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.unit, "Seconds");
  1993. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.minLimit = 5;
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value, "30");
  1998. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval]);
  1999. /* ReservationCtrlr Required item */
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "true");
  2006. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "true");
  2013. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "false");
  2020. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  2021. /* SampledDataCtrlr Required item */
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "true");
  2028. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "true");
  2035. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  2042. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  2043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2046. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2051. "Energy.Active.Import.Register,"
  2052. "Energy.Active.Import.Interval,"
  2053. "Power.Active.Import,"
  2054. "Voltage,"
  2055. "SoC");
  2056. else
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2058. "Energy.Active.Import.Register,"
  2059. "Energy.Active.Import.Interval,"
  2060. "Power.Active.Import,"
  2061. "Voltage");
  2062. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  2070. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2074. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  2078. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2082. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2087. "Energy.Active.Import.Register,"
  2088. "Energy.Active.Import.Interval,"
  2089. "Power.Active.Import,"
  2090. "Voltage,"
  2091. "SoC,"
  2092. "Current.Offered,"
  2093. "Power.Offered");
  2094. else
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2096. "Energy.Active.Import.Register,"
  2097. "Energy.Active.Import.Interval,"
  2098. "Power.Active.Import,"
  2099. "Voltage,"
  2100. "Current.Offered");
  2101. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2106. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2110. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2111. /* SecurityCtrlr Required item */
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2115. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", (strlen((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword)>0?(char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword:"00000000"));
  2119. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2123. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2127. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2134. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2138. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2142. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2149. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "false");
  2156. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2160. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2164. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2165. /* SmartChargingCtrlr Required item */
  2166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "true");
  2172. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "true");
  2179. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "false");
  2186. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "3");
  2193. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2200. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2207. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "false");
  2214. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "false");
  2221. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "false");
  2228. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2232. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2236. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2243. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2244. /* TariffCostCtrlr Required item */
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "false");
  2252. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "false");
  2260. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2264. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2268. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "false");
  2276. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "false");
  2284. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2288. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2292. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2296. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2300. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2301. /* TxCtrlr Required item */
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2308. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2316. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "true");
  2323. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2330. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2337. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2344. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2352. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "false");
  2359. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2360. }
  2361. else
  2362. {
  2363. // Variable name init
  2364. /* AlignedDataCtrlr Required item */
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2381. /* AuthCtrlrVariable Required item */
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2396. /* AuthCacheCtrlr Variable Required item */
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2407. /* ClockCtrlr Variable Required item */
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2426. /* ChargingStation Required item */
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2441. /* Connector Required item */
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2448. /* CustomizationCtrlr Required item */
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2451. /* DeviceDataCtrlr Required item */
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2474. /* DisplayMessageCtrlr Required item */
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2485. /* EVSE Required item */
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2494. /* LocalAuthListCtrlr Required item */
  2495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2509. /* MonitoringCtrlr Required item */
  2510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2528. /* OCPPCommCtrlr Required item */
  2529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  2567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  2568. /* ReservationCtrlr Required item */
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2575. /* SampledDataCtrlr Required item */
  2576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2592. /* SecurityCtrlr Required item */
  2593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2607. /* SmartChargingCtrlr Required item */
  2608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2630. /* TariffCostCtrlr Required item */
  2631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2649. /* TxCtrlr Required item */
  2650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2666. }
  2667. return 0;
  2668. }
  2669. void DB_variableIsCreate()
  2670. {
  2671. char sql[512];
  2672. char* errMsg = NULL;
  2673. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2674. /* Execute SQL statement */
  2675. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2676. {
  2677. DEBUG_INFO("SQL error: %s\n", errMsg);
  2678. }
  2679. }
  2680. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2681. {
  2682. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2683. {
  2684. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2685. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2686. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2687. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2688. {
  2689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2691. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2695. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  2696. }
  2697. }
  2698. return 0;
  2699. }
  2700. void DB_variableLoadFromDb()
  2701. {
  2702. char sql[512];
  2703. char* errMsg = NULL;
  2704. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2705. /* Execute SQL statement */
  2706. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2707. {
  2708. DEBUG_INFO("SQL error: %s\n", errMsg);
  2709. }
  2710. }
  2711. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2712. {
  2713. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2714. if(columnCount > 0)
  2715. {
  2716. for(int idx=0;idx<columnCount;idx++)
  2717. {
  2718. json_object *SetNetworkProfile;
  2719. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2720. if(!is_error(SetNetworkProfile))
  2721. {
  2722. // Required data
  2723. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2724. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2725. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2726. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2727. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2728. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2729. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2730. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2731. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2732. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2733. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2734. {
  2735. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2736. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2737. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2738. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2739. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2740. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2741. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2742. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2743. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2744. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2745. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2746. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2747. }
  2748. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2749. {
  2750. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2751. {
  2752. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2753. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2754. }
  2755. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2756. {
  2757. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2758. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2759. }
  2760. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2761. {
  2762. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2763. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2764. }
  2765. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2766. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2767. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2768. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2769. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2770. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2771. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2772. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2773. }
  2774. }
  2775. json_object_put(SetNetworkProfile);
  2776. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2777. }
  2778. }
  2779. return 0;
  2780. }
  2781. void DB_getNetworkProfileFromDb()
  2782. {
  2783. char sql[512];
  2784. char* errMsg = NULL;
  2785. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2786. /* Execute SQL statement */
  2787. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2788. {
  2789. DEBUG_INFO("SQL error: %s\n", errMsg);
  2790. }
  2791. }
  2792. int DB_addNetworkProfile(int slot, char *data)
  2793. {
  2794. int result = PASS;
  2795. char sql[512];
  2796. char* errMsg = NULL;
  2797. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2798. slot,
  2799. data);
  2800. //* Execute SQL statement */
  2801. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2802. {
  2803. DEBUG_INFO("SQL error: %s\n", errMsg);
  2804. result = FAIL;
  2805. }
  2806. return result;
  2807. }
  2808. int DB_deleteNetworkProfile(int slot)
  2809. {
  2810. int result = PASS;
  2811. char sql[512];
  2812. char* errMsg = NULL;
  2813. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2814. //* Execute SQL statement */
  2815. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2816. {
  2817. DEBUG_INFO("SQL error: %s", errMsg);
  2818. result = FAIL;
  2819. }
  2820. return result;
  2821. }
  2822. int isNumber(uint8_t *string, uint8_t isFloat)
  2823. {
  2824. int result = NO;
  2825. int cntDecimal = 0;
  2826. float i;
  2827. for(int idx=0; idx<strlen((char*)string); idx++)
  2828. {
  2829. if((isdigit(string[idx])==0) && (string[idx] != '.'))
  2830. {
  2831. return result;
  2832. }
  2833. else if(string[idx] == '.')
  2834. cntDecimal++;
  2835. if(cntDecimal>1)
  2836. return result;
  2837. }
  2838. if((isFloat==FALSE) && (strstr((char*)string, ".") != NULL))
  2839. {
  2840. //DEBUG_INFO("%s is not pure integer!!\n", string);
  2841. }
  2842. else if((isFloat==TRUE) && (strstr((char*)string, ".") == NULL))
  2843. {
  2844. //DEBUG_INFO("%s is not float format!!\n", string);
  2845. }
  2846. else if(sscanf((char*)string, "%f", &i) != 0)
  2847. {
  2848. result = YES;
  2849. }
  2850. return result;
  2851. }
  2852. int isMatchTimeFormat(uint8_t *time)
  2853. {
  2854. int result = NO;
  2855. struct ParsingResult
  2856. {
  2857. int result;
  2858. int scanedElement;
  2859. int year;
  2860. int month;
  2861. int mday;
  2862. int hour;
  2863. int min;
  2864. int sec;
  2865. int tz_hour;
  2866. int tz_min;
  2867. float minSec;
  2868. }parsingResult;
  2869. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  2870. if(strstr((char*)time, ".") != NULL)
  2871. {
  2872. // Original data with mini second
  2873. if(strstr((char*)time, "Z") != NULL)
  2874. {
  2875. // Original data with Z
  2876. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%fZ",
  2877. &parsingResult.year,
  2878. &parsingResult.month,
  2879. &parsingResult.mday,
  2880. &parsingResult.hour,
  2881. &parsingResult.min,
  2882. &parsingResult.sec,
  2883. &parsingResult.minSec);
  2884. }
  2885. else
  2886. {
  2887. // Original data without Z
  2888. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2889. &parsingResult.year,
  2890. &parsingResult.month,
  2891. &parsingResult.mday,
  2892. &parsingResult.hour,
  2893. &parsingResult.min,
  2894. &parsingResult.sec,
  2895. &parsingResult.minSec,
  2896. &parsingResult.tz_hour,
  2897. &parsingResult.tz_min);
  2898. }
  2899. }
  2900. else
  2901. {
  2902. // Original data without mini second
  2903. if(strstr((char*)time, "Z") != NULL)
  2904. {
  2905. // Original data with Z
  2906. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%dZ",
  2907. &parsingResult.year,
  2908. &parsingResult.month,
  2909. &parsingResult.mday,
  2910. &parsingResult.hour,
  2911. &parsingResult.min,
  2912. &parsingResult.sec);
  2913. }
  2914. else
  2915. {
  2916. // Original data without Z
  2917. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d%d:%d",
  2918. &parsingResult.year,
  2919. &parsingResult.month,
  2920. &parsingResult.mday,
  2921. &parsingResult.hour,
  2922. &parsingResult.min,
  2923. &parsingResult.sec,
  2924. &parsingResult.tz_hour,
  2925. &parsingResult.tz_min);
  2926. }
  2927. }
  2928. if(parsingResult.scanedElement >= 6)
  2929. {
  2930. result = YES;
  2931. }
  2932. return result;
  2933. }
  2934. int getCurrentYear()
  2935. {
  2936. int result = 0;
  2937. time_t CurrentTime;
  2938. struct tm *tm;
  2939. CurrentTime = time(NULL);
  2940. tm=localtime(&CurrentTime);
  2941. result = (tm->tm_year + 1900);
  2942. return result;
  2943. }
  2944. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2945. {
  2946. int result = PASS;
  2947. char* errMsg = NULL;
  2948. char sqlStr[8192];
  2949. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2950. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2951. {
  2952. result = FAIL;
  2953. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  2954. }
  2955. 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));
  2956. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2957. {
  2958. result = FAIL;
  2959. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  2960. }
  2961. return result;
  2962. }
  2963. //==========================================
  2964. // Check time passed since today
  2965. //==========================================
  2966. long long DiffTimebWithNow(struct timeb ST)
  2967. {
  2968. //return milli-second
  2969. struct timeb ET;
  2970. long long StartTime,StopTime;
  2971. ftime(&ET);
  2972. StartTime=(long long)ST.time;
  2973. StopTime=(long long)ET.time;
  2974. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2975. }
  2976. int getTimePassSinceToday(uint8_t gun_index)
  2977. {
  2978. int result = -1;
  2979. static time_t lastTime[4];
  2980. time_t t;
  2981. struct tm *tmStartToday;
  2982. struct timeb tbStartToday;
  2983. t=time(NULL);
  2984. if(difftime(t, lastTime[gun_index])>0)
  2985. {
  2986. tmStartToday=localtime(&t);
  2987. tmStartToday->tm_hour = 0;
  2988. tmStartToday->tm_min = 0;
  2989. tmStartToday->tm_sec = 0;
  2990. tbStartToday.time = mktime(tmStartToday);
  2991. tbStartToday.millitm = 0;
  2992. result = DiffTimebWithNow(tbStartToday)/1000;
  2993. lastTime[gun_index] = t;
  2994. }
  2995. return result;
  2996. }
  2997. int syncDateTimeRTC(uint8_t *data)
  2998. {
  2999. struct ParsingResult
  3000. {
  3001. int result;
  3002. int scanedElement;
  3003. int year;
  3004. int month;
  3005. int mday;
  3006. int hour;
  3007. int min;
  3008. int sec;
  3009. int tz_hour;
  3010. int tz_min;
  3011. float minSec;
  3012. }result;
  3013. struct tm tmOrg;
  3014. struct tm *tmTarget;
  3015. struct timeb tbTarget;
  3016. char buf[128];
  3017. memset(&result, 0x00, sizeof(struct ParsingResult));
  3018. result.result = PASS;
  3019. if(strstr((char*)data, ".") != NULL)
  3020. {
  3021. // Original data with mini second
  3022. if(strstr((char*)data, "Z") != NULL)
  3023. {
  3024. // Original data with Z
  3025. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  3026. &result.year,
  3027. &result.month,
  3028. &result.mday,
  3029. &result.hour,
  3030. &result.min,
  3031. &result.sec,
  3032. &result.minSec);
  3033. }
  3034. else
  3035. {
  3036. // Original data without Z
  3037. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3038. &result.year,
  3039. &result.month,
  3040. &result.mday,
  3041. &result.hour,
  3042. &result.min,
  3043. &result.sec,
  3044. &result.minSec,
  3045. &result.tz_hour,
  3046. &result.tz_min);
  3047. }
  3048. }
  3049. else
  3050. {
  3051. // Original data without mini second
  3052. if(strstr((char*)data, "Z") != NULL)
  3053. {
  3054. // Original data with Z
  3055. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  3056. &result.year,
  3057. &result.month,
  3058. &result.mday,
  3059. &result.hour,
  3060. &result.min,
  3061. &result.sec);
  3062. }
  3063. else
  3064. {
  3065. // Original data without Z
  3066. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  3067. &result.year,
  3068. &result.month,
  3069. &result.mday,
  3070. &result.hour,
  3071. &result.min,
  3072. &result.sec,
  3073. &result.tz_hour,
  3074. &result.tz_min);
  3075. }
  3076. }
  3077. tmOrg.tm_year = result.year - 1900;
  3078. tmOrg.tm_mon = result.month - 1;
  3079. tmOrg.tm_mday = result.mday;
  3080. tmOrg.tm_hour = result.hour;
  3081. tmOrg.tm_min = result.min;
  3082. tmOrg.tm_sec = result.sec;
  3083. tmOrg.tm_gmtoff = 0;
  3084. tbTarget.time = mktime(&tmOrg);
  3085. tbTarget.timezone = 0;
  3086. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  3087. tmTarget = gmtime(&tbTarget.time);
  3088. 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);
  3089. //DEBUG_INFO(" org date time: %s\n", data);
  3090. //DEBUG_INFO("parse date time: %s\n", buf);
  3091. system(buf);
  3092. system("/sbin/hwclock -w --systohc");
  3093. if(result.scanedElement < 6)
  3094. result.result = FAIL;
  3095. return result.result;
  3096. }
  3097. //==========================================
  3098. // GetCompositeSchedule logic related function
  3099. //==========================================
  3100. int DiffTimebSec(struct timeb ST, struct timeb ET)
  3101. {
  3102. //return milli-second
  3103. unsigned int StartTime,StopTime;
  3104. StartTime=(unsigned int)ST.time;
  3105. StopTime=(unsigned int)ET.time;
  3106. return (StopTime-StartTime);
  3107. }
  3108. int DiffTimebWithNowSec(struct timeb ST)
  3109. {
  3110. //return milli-second
  3111. struct timeb ET;
  3112. unsigned int StartTime,StopTime;
  3113. ftime(&ET);
  3114. StartTime=(unsigned int)ST.time;
  3115. StopTime=(unsigned int)ET.time;
  3116. return (StopTime-StartTime);
  3117. }
  3118. int getStartStop(uint8_t *start, uint8_t *stop)
  3119. {
  3120. struct ParsingResult
  3121. {
  3122. int result;
  3123. int scanedElement;
  3124. int year;
  3125. int month;
  3126. int mday;
  3127. int hour;
  3128. int min;
  3129. int sec;
  3130. int tz_hour;
  3131. int tz_min;
  3132. float minSec;
  3133. };
  3134. struct ParsingResult parseStart;
  3135. struct ParsingResult parseStop;
  3136. int result = -1;
  3137. struct tm tmStart;
  3138. struct timeb tbStart;
  3139. struct tm tmStop;
  3140. struct timeb tbStop;
  3141. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3142. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3143. // Scan start & stop date time
  3144. if(strstr((char*)start, ".") != NULL)
  3145. {
  3146. // Original data with mini second
  3147. if(strstr((char*)start, "Z") != NULL)
  3148. {
  3149. // Original data with Z
  3150. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3151. &parseStart.year,
  3152. &parseStart.month,
  3153. &parseStart.mday,
  3154. &parseStart.hour,
  3155. &parseStart.min,
  3156. &parseStart.sec,
  3157. &parseStart.minSec);
  3158. }
  3159. else
  3160. {
  3161. // Original data without Z
  3162. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3163. &parseStart.year,
  3164. &parseStart.month,
  3165. &parseStart.mday,
  3166. &parseStart.hour,
  3167. &parseStart.min,
  3168. &parseStart.sec,
  3169. &parseStart.minSec,
  3170. &parseStart.tz_hour,
  3171. &parseStart.tz_min);
  3172. }
  3173. }
  3174. else
  3175. {
  3176. // Original data without mini second
  3177. if(strstr((char*)start, "Z") != NULL)
  3178. {
  3179. // Original data with Z
  3180. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3181. &parseStart.year,
  3182. &parseStart.month,
  3183. &parseStart.mday,
  3184. &parseStart.hour,
  3185. &parseStart.min,
  3186. &parseStart.sec);
  3187. }
  3188. else
  3189. {
  3190. // Original data without Z
  3191. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3192. &parseStart.year,
  3193. &parseStart.month,
  3194. &parseStart.mday,
  3195. &parseStart.hour,
  3196. &parseStart.min,
  3197. &parseStart.sec,
  3198. &parseStart.tz_hour,
  3199. &parseStart.tz_min);
  3200. }
  3201. }
  3202. if(strstr((char*)stop, ".") != NULL)
  3203. {
  3204. // Original data with mini second
  3205. if(strstr((char*)stop, "Z") != NULL)
  3206. {
  3207. // Original data with Z
  3208. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3209. &parseStop.year,
  3210. &parseStop.month,
  3211. &parseStop.mday,
  3212. &parseStop.hour,
  3213. &parseStop.min,
  3214. &parseStop.sec,
  3215. &parseStop.minSec);
  3216. }
  3217. else
  3218. {
  3219. // Original data without Z
  3220. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3221. &parseStop.year,
  3222. &parseStop.month,
  3223. &parseStop.mday,
  3224. &parseStop.hour,
  3225. &parseStop.min,
  3226. &parseStop.sec,
  3227. &parseStop.minSec,
  3228. &parseStop.tz_hour,
  3229. &parseStop.tz_min);
  3230. }
  3231. }
  3232. else
  3233. {
  3234. // Original data without mini second
  3235. if(strstr((char*)stop, "Z") != NULL)
  3236. {
  3237. // Original data with Z
  3238. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3239. &parseStop.year,
  3240. &parseStop.month,
  3241. &parseStop.mday,
  3242. &parseStop.hour,
  3243. &parseStop.min,
  3244. &parseStop.sec);
  3245. }
  3246. else
  3247. {
  3248. // Original data without Z
  3249. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3250. &parseStop.year,
  3251. &parseStop.month,
  3252. &parseStop.mday,
  3253. &parseStop.hour,
  3254. &parseStop.min,
  3255. &parseStop.sec,
  3256. &parseStop.tz_hour,
  3257. &parseStop.tz_min);
  3258. }
  3259. }
  3260. // Calculate date time difference
  3261. if((parseStart.scanedElement >=6) &&
  3262. (parseStop.scanedElement >=6))
  3263. {
  3264. //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);
  3265. //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);
  3266. tmStart.tm_year = parseStart.year - 1900;
  3267. tmStart.tm_mon = parseStart.month - 1;
  3268. tmStart.tm_mday = parseStart.mday;
  3269. tmStart.tm_hour = parseStart.hour;
  3270. tmStart.tm_min = parseStart.min;
  3271. tmStart.tm_sec = parseStart.sec;
  3272. tmStart.tm_gmtoff = 0;
  3273. tbStart.time = mktime(&tmStart);
  3274. tbStart.timezone = 0;
  3275. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3276. tmStop.tm_year = parseStop.year - 1900;
  3277. tmStop.tm_mon = parseStop.month - 1;
  3278. tmStop.tm_mday = parseStop.mday;
  3279. tmStop.tm_hour = parseStop.hour;
  3280. tmStop.tm_min = parseStop.min;
  3281. tmStop.tm_sec = parseStop.sec;
  3282. tmStop.tm_gmtoff = 0;
  3283. tbStop.time = mktime(&tmStop);
  3284. tbStop.timezone = 0;
  3285. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3286. result = DiffTimebSec(tbStart, tbStop);
  3287. //DEBUG_INFO("getStartStop(): %d\n", result);
  3288. }
  3289. else
  3290. {
  3291. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3292. }
  3293. return result;
  3294. }
  3295. int isOvertNow(uint8_t *start)
  3296. {
  3297. int result = NO;
  3298. struct ParsingResult
  3299. {
  3300. int result;
  3301. int scanedElement;
  3302. int year;
  3303. int month;
  3304. int mday;
  3305. int hour;
  3306. int min;
  3307. int sec;
  3308. int tz_hour;
  3309. int tz_min;
  3310. float minSec;
  3311. }parsingResult;
  3312. struct tm tmStart;
  3313. struct timeb tbStart;
  3314. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3315. if(strstr((char*)start, ".") != NULL)
  3316. {
  3317. // Original data with mini second
  3318. if(strstr((char*)start, "Z") != NULL)
  3319. {
  3320. // Original data with Z
  3321. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3322. &parsingResult.year,
  3323. &parsingResult.month,
  3324. &parsingResult.mday,
  3325. &parsingResult.hour,
  3326. &parsingResult.min,
  3327. &parsingResult.sec,
  3328. &parsingResult.minSec);
  3329. }
  3330. else
  3331. {
  3332. // Original data without Z
  3333. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3334. &parsingResult.year,
  3335. &parsingResult.month,
  3336. &parsingResult.mday,
  3337. &parsingResult.hour,
  3338. &parsingResult.min,
  3339. &parsingResult.sec,
  3340. &parsingResult.minSec,
  3341. &parsingResult.tz_hour,
  3342. &parsingResult.tz_min);
  3343. }
  3344. }
  3345. else
  3346. {
  3347. // Original data without mini second
  3348. if(strstr((char*)start, "Z") != NULL)
  3349. {
  3350. // Original data with Z
  3351. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3352. &parsingResult.year,
  3353. &parsingResult.month,
  3354. &parsingResult.mday,
  3355. &parsingResult.hour,
  3356. &parsingResult.min,
  3357. &parsingResult.sec);
  3358. }
  3359. else
  3360. {
  3361. // Original data without Z
  3362. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3363. &parsingResult.year,
  3364. &parsingResult.month,
  3365. &parsingResult.mday,
  3366. &parsingResult.hour,
  3367. &parsingResult.min,
  3368. &parsingResult.sec,
  3369. &parsingResult.tz_hour,
  3370. &parsingResult.tz_min);
  3371. }
  3372. }
  3373. if(parsingResult.scanedElement >= 6)
  3374. {
  3375. tmStart.tm_year = parsingResult.year - 1900;
  3376. tmStart.tm_mon = parsingResult.month - 1;
  3377. tmStart.tm_mday = parsingResult.mday;
  3378. tmStart.tm_hour = parsingResult.hour;
  3379. tmStart.tm_min = parsingResult.min;
  3380. tmStart.tm_sec = parsingResult.sec;
  3381. tmStart.tm_gmtoff = 0;
  3382. tbStart.time = mktime(&tmStart);
  3383. tbStart.timezone = 0;
  3384. tbStart.millitm = 0;
  3385. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3386. if(DiffTimebWithNowSec(tbStart) <= 0)
  3387. result = NO;
  3388. else
  3389. result = YES;
  3390. }
  3391. else
  3392. {
  3393. DEBUG_WARN("Start date parsing error.\n");
  3394. }
  3395. return result;
  3396. }
  3397. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3398. {
  3399. struct ParsingResult
  3400. {
  3401. int result;
  3402. int scanedElement;
  3403. int year;
  3404. int month;
  3405. int mday;
  3406. int hour;
  3407. int min;
  3408. int sec;
  3409. int tz_hour;
  3410. int tz_min;
  3411. float minSec;
  3412. };
  3413. struct ParsingResult parseStart;
  3414. struct ParsingResult parseStop;
  3415. int result = -1;
  3416. struct tm tmStart;
  3417. struct timeb tbStart;
  3418. struct tm tmStop;
  3419. struct timeb tbStop;
  3420. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3421. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3422. // Scan start & stop date time
  3423. if(strstr((char*)start, ".") != NULL)
  3424. {
  3425. // Original data with mini second
  3426. if(strstr((char*)start, "Z") != NULL)
  3427. {
  3428. // Original data with Z
  3429. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3430. &parseStart.year,
  3431. &parseStart.month,
  3432. &parseStart.mday,
  3433. &parseStart.hour,
  3434. &parseStart.min,
  3435. &parseStart.sec,
  3436. &parseStart.minSec);
  3437. }
  3438. else
  3439. {
  3440. // Original data without Z
  3441. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3442. &parseStart.year,
  3443. &parseStart.month,
  3444. &parseStart.mday,
  3445. &parseStart.hour,
  3446. &parseStart.min,
  3447. &parseStart.sec,
  3448. &parseStart.minSec,
  3449. &parseStart.tz_hour,
  3450. &parseStart.tz_min);
  3451. }
  3452. }
  3453. else
  3454. {
  3455. // Original data without mini second
  3456. if(strstr((char*)start, "Z") != NULL)
  3457. {
  3458. // Original data with Z
  3459. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3460. &parseStart.year,
  3461. &parseStart.month,
  3462. &parseStart.mday,
  3463. &parseStart.hour,
  3464. &parseStart.min,
  3465. &parseStart.sec);
  3466. }
  3467. else
  3468. {
  3469. // Original data without Z
  3470. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3471. &parseStart.year,
  3472. &parseStart.month,
  3473. &parseStart.mday,
  3474. &parseStart.hour,
  3475. &parseStart.min,
  3476. &parseStart.sec,
  3477. &parseStart.tz_hour,
  3478. &parseStart.tz_min);
  3479. }
  3480. }
  3481. if(strstr((char*)stop, ".") != NULL)
  3482. {
  3483. // Original data with mini second
  3484. if(strstr((char*)stop, "Z") != NULL)
  3485. {
  3486. // Original data with Z
  3487. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3488. &parseStop.year,
  3489. &parseStop.month,
  3490. &parseStop.mday,
  3491. &parseStop.hour,
  3492. &parseStop.min,
  3493. &parseStop.sec,
  3494. &parseStop.minSec);
  3495. }
  3496. else
  3497. {
  3498. // Original data without Z
  3499. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3500. &parseStop.year,
  3501. &parseStop.month,
  3502. &parseStop.mday,
  3503. &parseStop.hour,
  3504. &parseStop.min,
  3505. &parseStop.sec,
  3506. &parseStop.minSec,
  3507. &parseStop.tz_hour,
  3508. &parseStop.tz_min);
  3509. }
  3510. }
  3511. else
  3512. {
  3513. // Original data without mini second
  3514. if(strstr((char*)stop, "Z") != NULL)
  3515. {
  3516. // Original data with Z
  3517. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3518. &parseStop.year,
  3519. &parseStop.month,
  3520. &parseStop.mday,
  3521. &parseStop.hour,
  3522. &parseStop.min,
  3523. &parseStop.sec);
  3524. }
  3525. else
  3526. {
  3527. // Original data without Z
  3528. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3529. &parseStop.year,
  3530. &parseStop.month,
  3531. &parseStop.mday,
  3532. &parseStop.hour,
  3533. &parseStop.min,
  3534. &parseStop.sec,
  3535. &parseStop.tz_hour,
  3536. &parseStop.tz_min);
  3537. }
  3538. }
  3539. // Calculate date time difference
  3540. if((parseStart.scanedElement >=6) &&
  3541. (parseStop.scanedElement >=6))
  3542. {
  3543. //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);
  3544. //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);
  3545. tmStart.tm_year = parseStart.year - 1900;
  3546. tmStart.tm_mon = parseStart.month - 1;
  3547. tmStart.tm_mday = parseStart.mday;
  3548. tmStart.tm_hour = parseStart.hour;
  3549. tmStart.tm_min = parseStart.min;
  3550. tmStart.tm_sec = parseStart.sec;
  3551. tmStart.tm_gmtoff = 0;
  3552. tbStart.time = mktime(&tmStart);
  3553. tbStart.timezone = 0;
  3554. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3555. tmStop.tm_year = parseStop.year - 1900;
  3556. tmStop.tm_mon = parseStop.month - 1;
  3557. tmStop.tm_mday = parseStop.mday;
  3558. tmStop.tm_hour = parseStop.hour;
  3559. tmStop.tm_min = parseStop.min;
  3560. tmStop.tm_sec = parseStop.sec;
  3561. tmStop.tm_gmtoff = 0;
  3562. tbStop.time = mktime(&tmStop);
  3563. tbStop.timezone = 0;
  3564. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3565. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  3566. //DEBUG_INFO("getStartStop(): %d\n", result);
  3567. }
  3568. else
  3569. {
  3570. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3571. }
  3572. return result;
  3573. }
  3574. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3575. {
  3576. FILE *fp;
  3577. char profileFileName[128];
  3578. char *line = NULL;
  3579. size_t len = 0;
  3580. time_t CurrentTime;
  3581. struct tm *tmComposite;
  3582. struct ChargingProfileType maxProfile;
  3583. struct ChargingProfileType compositeProfile;
  3584. uint8_t limitMax=0;
  3585. int compositePeriodIdx = 0;
  3586. CurrentTime = time(NULL);
  3587. tmComposite=localtime(&CurrentTime);
  3588. 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);
  3589. if(isUnitA)
  3590. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3591. else
  3592. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3593. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  3594. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3595. {
  3596. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3597. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3598. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3599. }
  3600. compositeProfile.id = 0;
  3601. compositeProfile.stackLevel = 99 ;
  3602. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  3603. maxProfile.id = -1;
  3604. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3605. system("rm -f /tmp/*.json");
  3606. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3607. // Search max profile
  3608. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  3609. if((access(profileFileName, F_OK))!=-1)
  3610. {
  3611. fp = fopen(profileFileName, "r");
  3612. while(getline(&line, &len, fp) != -1)
  3613. {
  3614. json_object *obj = NULL;
  3615. obj = json_tokener_parse(line);
  3616. if(is_error(obj))
  3617. {
  3618. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3619. }
  3620. else
  3621. {
  3622. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  3623. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  3624. )
  3625. {
  3626. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3627. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3628. )
  3629. {
  3630. struct tm tmFrom, tmTo;
  3631. struct timeb tbFrom, tbTo;
  3632. 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) &&
  3633. (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))
  3634. {
  3635. tmFrom.tm_year -= 1900;
  3636. tmFrom.tm_mon -= 1;
  3637. tbFrom.time = mktime(&tmFrom);
  3638. tmTo.tm_year -= 1900;
  3639. tmTo.tm_mon -= 1;
  3640. tbTo.time = mktime(&tmTo);
  3641. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3642. {
  3643. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3644. {
  3645. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3646. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3647. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3648. }
  3649. if(maxProfile.id == -1)
  3650. DEBUG_INFO("MaxProfile found.\n");
  3651. else
  3652. DEBUG_INFO("MaxProfile updated.\n");
  3653. // Required item
  3654. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3655. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3656. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3657. if(isUnitA)
  3658. {
  3659. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3660. 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++)
  3661. {
  3662. 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"));
  3663. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  3664. {
  3665. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  3666. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  3667. else
  3668. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  3669. }
  3670. else
  3671. {
  3672. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  3673. }
  3674. 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")));
  3675. }
  3676. }
  3677. else
  3678. {
  3679. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3680. 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++)
  3681. {
  3682. 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"));
  3683. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  3684. {
  3685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  3686. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  3687. else
  3688. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  3689. }
  3690. else
  3691. {
  3692. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  3693. }
  3694. 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));
  3695. }
  3696. }
  3697. // Optional item
  3698. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3699. {
  3700. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3701. }
  3702. else
  3703. {
  3704. sprintf((char*)maxProfile.validFrom, " ");
  3705. }
  3706. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3707. {
  3708. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3709. }
  3710. else
  3711. {
  3712. sprintf((char*)maxProfile.validTo, " ");
  3713. }
  3714. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3715. {
  3716. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3717. }
  3718. else
  3719. {
  3720. sprintf((char*)maxProfile.recurrencyKind, " ");
  3721. }
  3722. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3723. {
  3724. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3725. }
  3726. else
  3727. {
  3728. sprintf((char*)maxProfile.transactionId, " ");
  3729. }
  3730. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  3731. {
  3732. 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"));
  3733. }
  3734. else
  3735. {
  3736. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3737. }
  3738. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  3739. {
  3740. 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")));
  3741. }
  3742. else
  3743. {
  3744. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3745. }
  3746. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  3747. {
  3748. 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"));
  3749. }
  3750. else
  3751. {
  3752. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3753. }
  3754. }
  3755. }
  3756. }
  3757. else
  3758. {
  3759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3760. {
  3761. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3762. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3763. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3764. }
  3765. if(maxProfile.id == -1)
  3766. DEBUG_INFO("MaxProfile found.\n");
  3767. else
  3768. DEBUG_INFO("MaxProfile updated.\n");
  3769. // Required item
  3770. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3771. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3772. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3773. if(isUnitA)
  3774. {
  3775. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3776. 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++)
  3777. {
  3778. 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"));
  3779. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  3780. {
  3781. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  3782. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  3783. else
  3784. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  3785. }
  3786. else
  3787. {
  3788. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  3789. }
  3790. 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")));
  3791. }
  3792. }
  3793. else
  3794. {
  3795. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3796. 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++)
  3797. {
  3798. 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"));
  3799. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  3800. {
  3801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  3802. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  3803. else
  3804. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  3805. }
  3806. else
  3807. {
  3808. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  3809. }
  3810. 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));
  3811. }
  3812. }
  3813. // Optional item
  3814. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3815. {
  3816. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3817. }
  3818. else
  3819. {
  3820. sprintf((char*)maxProfile.validFrom, " ");
  3821. }
  3822. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3823. {
  3824. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3825. }
  3826. else
  3827. {
  3828. sprintf((char*)maxProfile.validTo, " ");
  3829. }
  3830. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3831. {
  3832. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3833. }
  3834. else
  3835. {
  3836. sprintf((char*)maxProfile.recurrencyKind, " ");
  3837. }
  3838. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3839. {
  3840. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3841. }
  3842. else
  3843. {
  3844. sprintf((char*)maxProfile.transactionId, " ");
  3845. }
  3846. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  3847. {
  3848. 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"));
  3849. }
  3850. else
  3851. {
  3852. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3853. }
  3854. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  3855. {
  3856. 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")));
  3857. }
  3858. else
  3859. {
  3860. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  3861. }
  3862. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  3863. {
  3864. 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"));
  3865. }
  3866. else
  3867. {
  3868. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3869. }
  3870. }
  3871. }
  3872. }
  3873. json_object_put(obj);
  3874. }
  3875. fclose(fp);
  3876. /*
  3877. if(maxProfile.id !=-1)
  3878. {
  3879. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3880. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3881. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3882. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3883. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3884. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3885. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3886. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3887. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3888. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3889. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3890. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3891. {
  3892. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3893. {
  3894. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3895. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3896. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3897. }
  3898. }
  3899. }
  3900. else
  3901. DEBUG_INFO("MaxProfile not found.\n");
  3902. DEBUG_INFO("------------------------------------\n");*/
  3903. }
  3904. if(maxProfile.id != -1)
  3905. {
  3906. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3907. {
  3908. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3909. {
  3910. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  3911. 0:
  3912. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  3913. }
  3914. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3915. {
  3916. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3917. {
  3918. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  3919. 0:
  3920. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  3921. if(idxPeriod > 0)
  3922. {
  3923. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3924. {
  3925. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3926. }
  3927. }
  3928. }
  3929. }
  3930. }
  3931. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3932. {
  3933. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3934. {
  3935. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  3936. }
  3937. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3938. {
  3939. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3940. {
  3941. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  3942. if(idxPeriod > 0)
  3943. {
  3944. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3945. {
  3946. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3947. }
  3948. }
  3949. }
  3950. }
  3951. }
  3952. else
  3953. {
  3954. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3955. {
  3956. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3957. {
  3958. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3959. 0:
  3960. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3961. }
  3962. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3963. {
  3964. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3965. {
  3966. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3967. 0:
  3968. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3969. if(idxPeriod > 0)
  3970. {
  3971. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3972. {
  3973. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3974. }
  3975. }
  3976. }
  3977. }
  3978. }
  3979. else
  3980. {
  3981. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3982. {
  3983. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3984. 0:
  3985. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3986. }
  3987. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3988. {
  3989. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3990. {
  3991. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3992. 0:
  3993. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3994. if(idxPeriod > 0)
  3995. {
  3996. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3997. {
  3998. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3999. }
  4000. }
  4001. }
  4002. }
  4003. }
  4004. }
  4005. /*
  4006. DEBUG_INFO("MaxProfile after align.\n");
  4007. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4008. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4009. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4010. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4011. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4012. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4013. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4014. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4015. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4016. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4017. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4018. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4019. {
  4020. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4021. {
  4022. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4023. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4024. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4025. }
  4026. }
  4027. DEBUG_INFO("------------------------------------\n");*/
  4028. }
  4029. // Find each profile period quantity
  4030. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4031. {
  4032. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4033. limitMax = idx+1;
  4034. }
  4035. if(maxProfile.id != -1)
  4036. {
  4037. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4038. {
  4039. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4040. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4041. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4042. {
  4043. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4044. {
  4045. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4046. compositePeriodIdx++;
  4047. }
  4048. else
  4049. {
  4050. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4051. }
  4052. }
  4053. }
  4054. }
  4055. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  4056. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4057. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  4058. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  4059. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4060. {
  4061. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4062. {
  4063. compositeProfile.id = 1;
  4064. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4065. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4066. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4067. }
  4068. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4069. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4070. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4071. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4072. }
  4073. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4074. if(line)
  4075. free(line);
  4076. }
  4077. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4078. {
  4079. FILE *fp;
  4080. char profileFileName[128];
  4081. char *line = NULL;
  4082. size_t len = 0;
  4083. time_t CurrentTime;
  4084. struct tm *tmComposite;
  4085. struct ChargingProfileType maxProfile;
  4086. struct ChargingProfileType defaultTxProfile;
  4087. struct ChargingProfileType txProfile;
  4088. struct ChargingProfileType compositeProfile;
  4089. struct ChargingSchedulePeriodType tmpPeriod;
  4090. uint8_t limitMax=0;
  4091. uint8_t limitDef=0;
  4092. uint8_t limitTx=0;
  4093. int compositePeriodIdx = 0;
  4094. CurrentTime = time(NULL);
  4095. tmComposite=localtime(&CurrentTime);
  4096. 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);
  4097. if(isUnitA)
  4098. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4099. else
  4100. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4101. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4102. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4103. {
  4104. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4105. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4106. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4107. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4108. }
  4109. compositeProfile.id = 0;
  4110. compositeProfile.stackLevel = 99 ;
  4111. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  4112. maxProfile.id = -1;
  4113. defaultTxProfile.id = -1;
  4114. txProfile.id = -1;
  4115. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4116. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  4117. txProfile.chargingSchedule[idxSchedule].duration = -1;
  4118. system("rm -f /tmp/*.json");
  4119. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4120. /*
  4121. * Search valid charging profile
  4122. */
  4123. //DEBUG_INFO("====================================\n");
  4124. // Search tx profile
  4125. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", connectorId);
  4126. if((access(profileFileName, F_OK))!=-1)
  4127. {
  4128. fp = fopen(profileFileName, "r");
  4129. while(getline(&line, &len, fp) != -1)
  4130. {
  4131. json_object *obj = NULL;
  4132. obj = json_tokener_parse(line);
  4133. if(is_error(obj))
  4134. {
  4135. DEBUG_ERROR("Parse txProfile from file error.\n");
  4136. }
  4137. else
  4138. {
  4139. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  4140. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  4141. )
  4142. {
  4143. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4144. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4145. )
  4146. {
  4147. struct tm tmFrom, tmTo;
  4148. struct timeb tbFrom, tbTo;
  4149. 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) &&
  4150. (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))
  4151. {
  4152. tmFrom.tm_year -= 1900;
  4153. tmFrom.tm_mon -= 1;
  4154. tbFrom.time = mktime(&tmFrom);
  4155. tmTo.tm_year -= 1900;
  4156. tmTo.tm_mon -= 1;
  4157. tbTo.time = mktime(&tmTo);
  4158. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4159. {
  4160. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4161. {
  4162. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4163. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4164. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4165. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4166. }
  4167. if(txProfile.id == -1)
  4168. DEBUG_INFO("TxProfile found.\n");
  4169. else
  4170. DEBUG_INFO("TxProfile updated.\n");
  4171. // Required item
  4172. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4173. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4174. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4175. if(isUnitA)
  4176. {
  4177. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4178. 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++)
  4179. {
  4180. 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"));
  4181. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4182. {
  4183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4184. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4185. else
  4186. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4187. }
  4188. else
  4189. {
  4190. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4191. }
  4192. 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")));
  4193. }
  4194. }
  4195. else
  4196. {
  4197. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4198. 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++)
  4199. {
  4200. 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"));
  4201. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4202. {
  4203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4204. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4205. else
  4206. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4207. }
  4208. else
  4209. {
  4210. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4211. }
  4212. 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));
  4213. }
  4214. }
  4215. // Optional item
  4216. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4217. {
  4218. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4219. }
  4220. else
  4221. {
  4222. sprintf((char*)txProfile.validFrom, " ");
  4223. }
  4224. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4225. {
  4226. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4227. }
  4228. else
  4229. {
  4230. sprintf((char*)txProfile.validTo, " ");
  4231. }
  4232. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4233. {
  4234. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4235. }
  4236. else
  4237. {
  4238. sprintf((char*)txProfile.recurrencyKind, " ");
  4239. }
  4240. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4241. {
  4242. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4243. }
  4244. else
  4245. {
  4246. sprintf((char*)txProfile.transactionId, " ");
  4247. }
  4248. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4249. {
  4250. 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"));
  4251. }
  4252. else
  4253. {
  4254. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4255. }
  4256. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4257. {
  4258. 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")));
  4259. }
  4260. else
  4261. {
  4262. 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));
  4263. }
  4264. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4265. {
  4266. 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"));
  4267. }
  4268. else
  4269. {
  4270. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4271. }
  4272. }
  4273. }
  4274. }
  4275. else
  4276. {
  4277. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4278. {
  4279. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4280. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4281. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4282. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4283. }
  4284. if(txProfile.id == -1)
  4285. DEBUG_INFO("TxProfile found.\n");
  4286. else
  4287. DEBUG_INFO("TxProfile updated.\n");
  4288. // Required item
  4289. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4290. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4291. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4292. if(isUnitA)
  4293. {
  4294. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4295. 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++)
  4296. {
  4297. 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"));
  4298. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4299. {
  4300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4301. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4302. else
  4303. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4304. }
  4305. else
  4306. {
  4307. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4308. }
  4309. 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")));
  4310. }
  4311. }
  4312. else
  4313. {
  4314. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4315. 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++)
  4316. {
  4317. 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"));
  4318. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4319. {
  4320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4321. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4322. else
  4323. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4324. }
  4325. else
  4326. {
  4327. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4328. }
  4329. 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));
  4330. }
  4331. }
  4332. // Optional item
  4333. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4334. {
  4335. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4336. }
  4337. else
  4338. {
  4339. sprintf((char*)txProfile.validFrom, " ");
  4340. }
  4341. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4342. {
  4343. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4344. }
  4345. else
  4346. {
  4347. sprintf((char*)txProfile.validTo, " ");
  4348. }
  4349. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4350. {
  4351. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4352. }
  4353. else
  4354. {
  4355. sprintf((char*)txProfile.recurrencyKind, " ");
  4356. }
  4357. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4358. {
  4359. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4360. }
  4361. else
  4362. {
  4363. sprintf((char*)txProfile.transactionId, " ");
  4364. }
  4365. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4366. {
  4367. 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"));
  4368. }
  4369. else
  4370. {
  4371. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4372. }
  4373. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4374. {
  4375. 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")));
  4376. }
  4377. else
  4378. {
  4379. 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));
  4380. }
  4381. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4382. {
  4383. 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"));
  4384. }
  4385. else
  4386. {
  4387. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4388. }
  4389. }
  4390. }
  4391. }
  4392. json_object_put(obj);
  4393. }
  4394. fclose(fp);
  4395. /*
  4396. if(txProfile.id != -1)
  4397. {
  4398. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4399. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4400. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4401. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4402. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4403. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4404. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4405. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  4406. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4407. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4408. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4410. {
  4411. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4412. {
  4413. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4414. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4415. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4416. }
  4417. }
  4418. }
  4419. else
  4420. DEBUG_INFO("TxProfile not found.\n");*/
  4421. }
  4422. // Search default tx profile
  4423. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", connectorId);
  4424. if((access(profileFileName, F_OK))==-1)
  4425. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  4426. if((access(profileFileName, F_OK))!=-1)
  4427. {
  4428. fp = fopen(profileFileName, "r");
  4429. while(getline(&line, &len, fp) != -1)
  4430. {
  4431. json_object *obj = NULL;
  4432. obj = json_tokener_parse(line);
  4433. if(is_error(obj))
  4434. {
  4435. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  4436. }
  4437. else
  4438. {
  4439. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  4440. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  4441. )
  4442. {
  4443. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4444. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4445. )
  4446. {
  4447. struct tm tmFrom, tmTo;
  4448. struct timeb tbFrom, tbTo;
  4449. 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) &&
  4450. (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))
  4451. {
  4452. tmFrom.tm_year -= 1900;
  4453. tmFrom.tm_mon -= 1;
  4454. tbFrom.time = mktime(&tmFrom);
  4455. tmTo.tm_year -= 1900;
  4456. tmTo.tm_mon -= 1;
  4457. tbTo.time = mktime(&tmTo);
  4458. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4459. {
  4460. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4461. {
  4462. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4463. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4464. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4465. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4466. }
  4467. if(defaultTxProfile.id == -1)
  4468. DEBUG_INFO("TxDefaultProfile found.\n");
  4469. else
  4470. DEBUG_INFO("TxDefaultProfile updated.\n");
  4471. // Required item
  4472. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4473. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4474. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4475. if(isUnitA)
  4476. {
  4477. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4478. 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++)
  4479. {
  4480. 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"));
  4481. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4482. {
  4483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4484. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4485. else
  4486. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4487. }
  4488. else
  4489. {
  4490. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4491. }
  4492. 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")));
  4493. }
  4494. }
  4495. else
  4496. {
  4497. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4498. 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++)
  4499. {
  4500. 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"));
  4501. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4502. {
  4503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4504. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4505. else
  4506. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4507. }
  4508. else
  4509. {
  4510. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4511. }
  4512. 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));
  4513. }
  4514. }
  4515. // Optional item
  4516. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4517. {
  4518. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4519. }
  4520. else
  4521. {
  4522. sprintf((char*)defaultTxProfile.validFrom, " ");
  4523. }
  4524. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4525. {
  4526. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4527. }
  4528. else
  4529. {
  4530. sprintf((char*)defaultTxProfile.validTo, " ");
  4531. }
  4532. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4533. {
  4534. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4535. }
  4536. else
  4537. {
  4538. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4539. }
  4540. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4541. {
  4542. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4543. }
  4544. else
  4545. {
  4546. sprintf((char*)defaultTxProfile.transactionId, " ");
  4547. }
  4548. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4549. {
  4550. 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"));
  4551. }
  4552. else
  4553. {
  4554. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4555. }
  4556. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4557. {
  4558. 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")));
  4559. }
  4560. else
  4561. {
  4562. 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));
  4563. }
  4564. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4565. {
  4566. 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"));
  4567. }
  4568. else
  4569. {
  4570. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4571. }
  4572. }
  4573. }
  4574. }
  4575. else
  4576. {
  4577. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4578. {
  4579. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4580. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4581. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4582. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4583. }
  4584. if(defaultTxProfile.id == -1)
  4585. DEBUG_INFO("TxDefaultProfile found.\n");
  4586. else
  4587. DEBUG_INFO("TxDefaultProfile updated.\n");
  4588. // Required item
  4589. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4590. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4591. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4592. if(isUnitA)
  4593. {
  4594. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4595. 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++)
  4596. {
  4597. 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"));
  4598. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4599. {
  4600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4601. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4602. else
  4603. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4604. }
  4605. else
  4606. {
  4607. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4608. }
  4609. 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")));
  4610. }
  4611. }
  4612. else
  4613. {
  4614. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4615. 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++)
  4616. {
  4617. 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"));
  4618. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4619. {
  4620. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4621. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4622. else
  4623. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4624. }
  4625. else
  4626. {
  4627. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4628. }
  4629. 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));
  4630. }
  4631. }
  4632. // Optional item
  4633. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4634. {
  4635. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4636. }
  4637. else
  4638. {
  4639. sprintf((char*)defaultTxProfile.validFrom, " ");
  4640. }
  4641. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4642. {
  4643. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4644. }
  4645. else
  4646. {
  4647. sprintf((char*)defaultTxProfile.validTo, " ");
  4648. }
  4649. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4650. {
  4651. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4652. }
  4653. else
  4654. {
  4655. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4656. }
  4657. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4658. {
  4659. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4660. }
  4661. else
  4662. {
  4663. sprintf((char*)defaultTxProfile.transactionId, " ");
  4664. }
  4665. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4666. {
  4667. 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"));
  4668. }
  4669. else
  4670. {
  4671. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4672. }
  4673. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4674. {
  4675. 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")));
  4676. }
  4677. else
  4678. {
  4679. 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));
  4680. }
  4681. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4682. {
  4683. 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"));
  4684. }
  4685. else
  4686. {
  4687. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4688. }
  4689. }
  4690. }
  4691. }
  4692. json_object_put(obj);
  4693. }
  4694. fclose(fp);
  4695. /*
  4696. if(defaultTxProfile.id != -1)
  4697. {
  4698. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  4699. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  4700. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  4701. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  4702. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  4703. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  4704. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  4705. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4706. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  4707. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4708. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4709. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4710. {
  4711. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4712. {
  4713. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4714. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4715. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4716. }
  4717. }
  4718. }
  4719. else
  4720. DEBUG_INFO("TxDefaultProfile not found.\n");
  4721. DEBUG_INFO("------------------------------------\n");*/
  4722. }
  4723. // Search max profile
  4724. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4725. if((access(profileFileName, F_OK))!=-1)
  4726. {
  4727. fp = fopen(profileFileName, "r");
  4728. while(getline(&line, &len, fp) != -1)
  4729. {
  4730. json_object *obj = NULL;
  4731. obj = json_tokener_parse(line);
  4732. if(is_error(obj))
  4733. {
  4734. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4735. }
  4736. else
  4737. {
  4738. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4739. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4740. )
  4741. {
  4742. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4743. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4744. )
  4745. {
  4746. struct tm tmFrom, tmTo;
  4747. struct timeb tbFrom, tbTo;
  4748. 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) &&
  4749. (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))
  4750. {
  4751. tmFrom.tm_year -= 1900;
  4752. tmFrom.tm_mon -= 1;
  4753. tbFrom.time = mktime(&tmFrom);
  4754. tmTo.tm_year -= 1900;
  4755. tmTo.tm_mon -= 1;
  4756. tbTo.time = mktime(&tmTo);
  4757. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4758. {
  4759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4760. {
  4761. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4762. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4763. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4764. }
  4765. if(maxProfile.id == -1)
  4766. DEBUG_INFO("MaxProfile found.\n");
  4767. else
  4768. DEBUG_INFO("MaxProfile updated.\n");
  4769. // Required item
  4770. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4771. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4772. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4773. if(isUnitA)
  4774. {
  4775. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4776. 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++)
  4777. {
  4778. 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"));
  4779. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4780. {
  4781. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4782. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4783. else
  4784. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4785. }
  4786. else
  4787. {
  4788. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4789. }
  4790. 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")));
  4791. }
  4792. }
  4793. else
  4794. {
  4795. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4796. 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++)
  4797. {
  4798. 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"));
  4799. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4800. {
  4801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4802. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4803. else
  4804. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4805. }
  4806. else
  4807. {
  4808. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4809. }
  4810. 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));
  4811. }
  4812. }
  4813. // Optional item
  4814. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4815. {
  4816. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4817. }
  4818. else
  4819. {
  4820. sprintf((char*)maxProfile.validFrom, " ");
  4821. }
  4822. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4823. {
  4824. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4825. }
  4826. else
  4827. {
  4828. sprintf((char*)maxProfile.validTo, " ");
  4829. }
  4830. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4831. {
  4832. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4833. }
  4834. else
  4835. {
  4836. sprintf((char*)maxProfile.recurrencyKind, " ");
  4837. }
  4838. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4839. {
  4840. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4841. }
  4842. else
  4843. {
  4844. sprintf((char*)maxProfile.transactionId, " ");
  4845. }
  4846. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4847. {
  4848. 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"));
  4849. }
  4850. else
  4851. {
  4852. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4853. }
  4854. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4855. {
  4856. 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")));
  4857. }
  4858. else
  4859. {
  4860. 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));
  4861. }
  4862. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4863. {
  4864. 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"));
  4865. }
  4866. else
  4867. {
  4868. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4869. }
  4870. }
  4871. }
  4872. }
  4873. else
  4874. {
  4875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4876. {
  4877. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4878. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4879. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4880. }
  4881. if(maxProfile.id == -1)
  4882. DEBUG_INFO("MaxProfile found.\n");
  4883. else
  4884. DEBUG_INFO("MaxProfile updated.\n");
  4885. // Required item
  4886. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4887. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4888. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4889. if(isUnitA)
  4890. {
  4891. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4892. 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++)
  4893. {
  4894. 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"));
  4895. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4896. {
  4897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4898. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4899. else
  4900. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4901. }
  4902. else
  4903. {
  4904. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4905. }
  4906. 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")));
  4907. }
  4908. }
  4909. else
  4910. {
  4911. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4912. 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++)
  4913. {
  4914. 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"));
  4915. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL)
  4916. {
  4917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4918. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4919. else
  4920. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4921. }
  4922. else
  4923. {
  4924. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  4925. }
  4926. 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));
  4927. }
  4928. }
  4929. // Optional item
  4930. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4931. {
  4932. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4933. }
  4934. else
  4935. {
  4936. sprintf((char*)maxProfile.validFrom, " ");
  4937. }
  4938. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4939. {
  4940. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4941. }
  4942. else
  4943. {
  4944. sprintf((char*)maxProfile.validTo, " ");
  4945. }
  4946. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4947. {
  4948. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4949. }
  4950. else
  4951. {
  4952. sprintf((char*)maxProfile.recurrencyKind, " ");
  4953. }
  4954. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4955. {
  4956. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4957. }
  4958. else
  4959. {
  4960. sprintf((char*)maxProfile.transactionId, " ");
  4961. }
  4962. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4963. {
  4964. 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"));
  4965. }
  4966. else
  4967. {
  4968. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4969. }
  4970. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4971. {
  4972. 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")));
  4973. }
  4974. else
  4975. {
  4976. 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));
  4977. }
  4978. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4979. {
  4980. 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"));
  4981. }
  4982. else
  4983. {
  4984. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4985. }
  4986. }
  4987. }
  4988. }
  4989. json_object_put(obj);
  4990. }
  4991. fclose(fp);
  4992. /*
  4993. if(maxProfile.id !=-1)
  4994. {
  4995. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4996. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4997. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4998. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4999. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5000. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5001. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5002. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5003. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5004. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5005. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5006. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5007. {
  5008. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5009. {
  5010. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5011. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5012. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5013. }
  5014. }
  5015. }
  5016. else
  5017. DEBUG_INFO("MaxProfile not found.\n");
  5018. DEBUG_INFO("------------------------------------\n");*/
  5019. }
  5020. /*
  5021. * Align found profile start schedule & periods
  5022. */
  5023. //DEBUG_INFO("====================================\n");
  5024. /*
  5025. // For local test usage, force modify found profile start schedule info
  5026. 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);
  5027. 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);
  5028. 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);
  5029. */
  5030. if(txProfile.id != -1)
  5031. {
  5032. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5033. {
  5034. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5035. {
  5036. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5037. 0:
  5038. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5039. }
  5040. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5041. {
  5042. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5043. {
  5044. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5045. 0:
  5046. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5047. if(idxPeriod > 0)
  5048. {
  5049. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5050. {
  5051. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5052. }
  5053. }
  5054. }
  5055. }
  5056. }
  5057. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5058. {
  5059. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5060. {
  5061. 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?
  5062. 0:
  5063. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5064. }
  5065. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5066. {
  5067. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5068. {
  5069. 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?
  5070. 0:
  5071. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5072. if(idxPeriod > 0)
  5073. {
  5074. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5075. {
  5076. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5077. }
  5078. }
  5079. }
  5080. }
  5081. }
  5082. else
  5083. {
  5084. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5085. {
  5086. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5087. {
  5088. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5089. 0:
  5090. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5091. }
  5092. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5093. {
  5094. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5095. {
  5096. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5097. 0:
  5098. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5099. if(idxPeriod > 0)
  5100. {
  5101. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5102. {
  5103. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5104. }
  5105. }
  5106. }
  5107. }
  5108. }
  5109. else
  5110. {
  5111. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5112. {
  5113. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5114. 0:
  5115. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5116. }
  5117. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5118. {
  5119. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5120. {
  5121. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5122. 0:
  5123. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5124. if(idxPeriod > 0)
  5125. {
  5126. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5127. {
  5128. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5129. }
  5130. }
  5131. }
  5132. }
  5133. }
  5134. }
  5135. /*
  5136. DEBUG_INFO("txProfile after align.\n");
  5137. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  5138. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  5139. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  5140. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  5141. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  5142. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  5143. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  5144. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5145. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  5146. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5147. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5148. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5149. {
  5150. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5151. {
  5152. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5153. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5154. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5155. }
  5156. }*/
  5157. }
  5158. if(defaultTxProfile.id != -1)
  5159. {
  5160. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5161. {
  5162. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5163. {
  5164. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5165. 0:
  5166. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5167. }
  5168. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5169. {
  5170. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5171. {
  5172. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5173. 0:
  5174. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5175. if(idxPeriod > 0)
  5176. {
  5177. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5178. {
  5179. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5180. }
  5181. }
  5182. }
  5183. }
  5184. }
  5185. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5186. {
  5187. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5188. {
  5189. 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?
  5190. 0:
  5191. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5192. }
  5193. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5194. {
  5195. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5196. {
  5197. 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?
  5198. 0:
  5199. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5200. if(idxPeriod > 0)
  5201. {
  5202. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5203. {
  5204. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5205. }
  5206. }
  5207. }
  5208. }
  5209. }
  5210. else
  5211. {
  5212. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5213. {
  5214. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5215. {
  5216. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5217. 0:
  5218. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5219. }
  5220. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5221. {
  5222. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5223. {
  5224. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5225. 0:
  5226. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5227. if(idxPeriod > 0)
  5228. {
  5229. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5230. {
  5231. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5232. }
  5233. }
  5234. }
  5235. }
  5236. }
  5237. else
  5238. {
  5239. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5240. {
  5241. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5242. 0:
  5243. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5244. }
  5245. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5246. {
  5247. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5248. {
  5249. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5250. 0:
  5251. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5252. if(idxPeriod > 0)
  5253. {
  5254. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5255. {
  5256. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5257. }
  5258. }
  5259. }
  5260. }
  5261. }
  5262. }
  5263. /*
  5264. DEBUG_INFO("defaultTxProfile after align.\n");
  5265. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5266. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5267. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5268. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5269. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5270. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5271. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5272. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5273. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5274. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5275. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5276. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5277. {
  5278. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5279. {
  5280. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5281. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5282. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5283. }
  5284. }
  5285. DEBUG_INFO("------------------------------------\n");*/
  5286. }
  5287. if(maxProfile.id != -1)
  5288. {
  5289. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5290. {
  5291. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5292. {
  5293. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5294. 0:
  5295. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5296. }
  5297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5298. {
  5299. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5300. {
  5301. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5302. 0:
  5303. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5304. if(idxPeriod > 0)
  5305. {
  5306. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5307. {
  5308. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5309. }
  5310. }
  5311. }
  5312. }
  5313. }
  5314. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5315. {
  5316. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5317. {
  5318. 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?
  5319. 0:
  5320. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5321. }
  5322. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5323. {
  5324. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5325. {
  5326. 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?
  5327. 0:
  5328. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5329. if(idxPeriod > 0)
  5330. {
  5331. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5332. {
  5333. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5334. }
  5335. }
  5336. }
  5337. }
  5338. }
  5339. else
  5340. {
  5341. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5342. {
  5343. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5344. {
  5345. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5346. 0:
  5347. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5348. }
  5349. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5350. {
  5351. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5352. {
  5353. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5354. 0:
  5355. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5356. if(idxPeriod > 0)
  5357. {
  5358. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5359. {
  5360. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5361. }
  5362. }
  5363. }
  5364. }
  5365. }
  5366. else
  5367. {
  5368. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5369. {
  5370. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5371. 0:
  5372. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5373. }
  5374. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5375. {
  5376. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5377. {
  5378. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5379. 0:
  5380. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5381. if(idxPeriod > 0)
  5382. {
  5383. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5384. {
  5385. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5386. }
  5387. }
  5388. }
  5389. }
  5390. }
  5391. }
  5392. /*
  5393. DEBUG_INFO("MaxProfile after align.\n");
  5394. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5395. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5396. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5397. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5398. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5399. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5400. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5401. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5402. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5403. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5404. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5405. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5406. {
  5407. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5408. {
  5409. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5410. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5411. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5412. }
  5413. }
  5414. DEBUG_INFO("------------------------------------\n");*/
  5415. }
  5416. /*
  5417. * Merge to conposite schedule
  5418. */
  5419. //DEBUG_INFO("====================================\n");
  5420. // Find each profile period quantity
  5421. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5422. {
  5423. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5424. limitMax = idx+1;
  5425. }
  5426. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5427. {
  5428. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5429. limitDef = idx+1;
  5430. }
  5431. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5432. {
  5433. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5434. limitTx = idx+1;
  5435. }
  5436. // TxProfile found, composite schedule based on it
  5437. if(txProfile.id != -1)
  5438. {
  5439. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  5440. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  5441. {
  5442. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  5443. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  5444. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  5445. {
  5446. if(maxProfile.id != -1)
  5447. {
  5448. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5449. {
  5450. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  5451. {
  5452. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5453. {
  5454. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5455. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5456. 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);
  5457. }
  5458. else
  5459. {
  5460. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  5461. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  5462. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  5463. }
  5464. }
  5465. if(idxMaxPeriod == (limitMax-1))
  5466. {
  5467. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5468. {
  5469. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5470. {
  5471. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5472. compositePeriodIdx++;
  5473. }
  5474. else
  5475. {
  5476. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5477. }
  5478. }
  5479. }
  5480. }
  5481. }
  5482. else
  5483. {
  5484. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5485. {
  5486. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5487. compositePeriodIdx++;
  5488. }
  5489. else
  5490. {
  5491. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  5492. }
  5493. }
  5494. }
  5495. if(idxTxPeriod == (limitTx-1))
  5496. {
  5497. if(defaultTxProfile.id != -1)
  5498. {
  5499. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  5500. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5501. {
  5502. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  5503. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5504. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  5505. {
  5506. if(maxProfile.id != -1)
  5507. {
  5508. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5509. {
  5510. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5511. {
  5512. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5513. {
  5514. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5515. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5516. 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);
  5517. }
  5518. else
  5519. {
  5520. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5521. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5522. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5523. }
  5524. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5525. {
  5526. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5527. {
  5528. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5529. compositePeriodIdx++;
  5530. }
  5531. else
  5532. {
  5533. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5534. }
  5535. }
  5536. // Delete duplicate period
  5537. if(compositePeriodIdx > 1)
  5538. {
  5539. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5540. {
  5541. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5542. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5543. compositePeriodIdx -= 1;
  5544. }
  5545. }
  5546. }
  5547. else
  5548. {
  5549. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5550. {
  5551. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5552. compositePeriodIdx++;
  5553. }
  5554. else
  5555. {
  5556. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5557. }
  5558. break;
  5559. }
  5560. }
  5561. }
  5562. else
  5563. {
  5564. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5565. {
  5566. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5567. compositePeriodIdx++;
  5568. }
  5569. else
  5570. {
  5571. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5572. }
  5573. }
  5574. }
  5575. }
  5576. }
  5577. }
  5578. }
  5579. }
  5580. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  5581. else if(defaultTxProfile.id != -1)
  5582. {
  5583. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  5584. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  5585. {
  5586. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  5587. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  5588. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  5589. {
  5590. if(maxProfile.id != -1)
  5591. {
  5592. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5593. {
  5594. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  5595. {
  5596. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  5597. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  5598. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5599. {
  5600. 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);
  5601. }
  5602. else
  5603. {
  5604. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  5605. }
  5606. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  5607. {
  5608. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5609. {
  5610. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5611. compositePeriodIdx++;
  5612. }
  5613. else
  5614. {
  5615. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5616. }
  5617. }
  5618. // Delete duplicate period
  5619. if(compositePeriodIdx > 1)
  5620. {
  5621. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5622. {
  5623. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5624. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5625. compositePeriodIdx -= 1;
  5626. }
  5627. }
  5628. }
  5629. else
  5630. {
  5631. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5632. {
  5633. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5634. compositePeriodIdx++;
  5635. }
  5636. else
  5637. {
  5638. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5639. }
  5640. break;
  5641. }
  5642. }
  5643. }
  5644. else
  5645. {
  5646. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5647. {
  5648. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5649. compositePeriodIdx++;
  5650. }
  5651. else
  5652. {
  5653. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5654. }
  5655. }
  5656. }
  5657. }
  5658. }
  5659. // Fill other period by MaxProfile
  5660. if(maxProfile.id != -1)
  5661. {
  5662. if(compositePeriodIdx==0)
  5663. {
  5664. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  5665. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  5666. {
  5667. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5668. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5669. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5670. {
  5671. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5672. {
  5673. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5674. compositePeriodIdx++;
  5675. }
  5676. else
  5677. {
  5678. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5679. }
  5680. }
  5681. }
  5682. }
  5683. else
  5684. {
  5685. int lastCompositePeriodIdx = compositePeriodIdx;
  5686. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5687. {
  5688. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5689. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5690. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5691. {
  5692. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  5693. {
  5694. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  5695. {
  5696. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5697. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5698. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  5699. }
  5700. else
  5701. {
  5702. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5703. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5704. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  5705. }
  5706. }
  5707. if(tmpPeriod.limit != -1)
  5708. {
  5709. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  5710. {
  5711. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  5712. {
  5713. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5714. compositePeriodIdx++;
  5715. }
  5716. else
  5717. {
  5718. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5719. }
  5720. }
  5721. // Delete duplicate period
  5722. if(compositePeriodIdx > 1)
  5723. {
  5724. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5725. {
  5726. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5727. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5728. compositePeriodIdx -= 1;
  5729. }
  5730. }
  5731. }
  5732. }
  5733. }
  5734. }
  5735. }
  5736. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  5737. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  5738. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  5739. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  5740. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  5741. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5742. {
  5743. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  5744. {
  5745. compositeProfile.id = 1;
  5746. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  5747. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  5748. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  5749. }
  5750. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  5751. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  5752. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  5753. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  5754. }
  5755. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  5756. if(line)
  5757. free(line);
  5758. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  5759. }
  5760. //==========================================
  5761. // Init all share memory
  5762. //==========================================
  5763. int InitShareMemory()
  5764. {
  5765. int result = PASS;
  5766. int MeterSMId;
  5767. //creat ShmSysConfigAndInfo
  5768. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  5769. {
  5770. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  5771. result = FAIL;
  5772. }
  5773. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5774. {
  5775. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  5776. result = FAIL;
  5777. }
  5778. else
  5779. {}
  5780. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  5781. {
  5782. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  5783. result = FAIL;
  5784. }
  5785. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5786. {
  5787. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  5788. result = FAIL;
  5789. }
  5790. else
  5791. {}
  5792. //creat ShmPsuData
  5793. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  5794. {
  5795. DEBUG_ERROR("shmget ShmPsuData NG\n");
  5796. result = FAIL;
  5797. }
  5798. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5799. {
  5800. DEBUG_ERROR("shmat ShmPsuData NG\n");
  5801. result = FAIL;
  5802. }
  5803. else
  5804. {}
  5805. //creat ShmOCPP20Data
  5806. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  5807. {
  5808. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  5809. result = FAIL;
  5810. }
  5811. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5812. {
  5813. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  5814. result = FAIL;
  5815. }
  5816. else
  5817. {}
  5818. /****************************** For Initial Settings************************************************/
  5819. /*
  5820. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  5821. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  5822. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  5823. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  5824. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  5825. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  5826. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  5827. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  5828. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  5829. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  5830. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  5831. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  5832. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  5833. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  5834. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  5835. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  5836. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  5837. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  5838. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  5839. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  5840. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  5841. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  5842. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  5843. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  5844. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  5845. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  5846. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  5847. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  5848. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  5849. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  5850. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  5851. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  5852. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  5853. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  5854. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  5855. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  5856. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  5857. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  5858. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  5859. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  5860. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  5861. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  5862. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  5863. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  5864. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  5865. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  5866. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  5867. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  5868. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  5869. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  5870. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  5871. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  5872. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  5873. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  5874. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  5875. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  5876. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  5877. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  5878. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  5879. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  5880. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  5881. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  5882. */
  5883. return result;
  5884. }
  5885. int ProcessShareMemory()
  5886. {
  5887. int result = PASS;
  5888. if(InitShareMemory() == FAIL)
  5889. {
  5890. DEBUG_ERROR("InitShareMemory NG\n");
  5891. if(ShmStatusCodeData!=NULL)
  5892. {
  5893. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  5894. }
  5895. result = FAIL;
  5896. }
  5897. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  5898. {
  5899. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  5900. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  5901. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  5902. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  5903. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  5904. ) // 'D' means DC
  5905. {
  5906. // DO series
  5907. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  5908. {
  5909. gunTotalNumber += 1;
  5910. gunType[gun_index] = GUN_TYPE_DO;
  5911. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  5914. {
  5915. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5916. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5917. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  5918. }
  5919. }
  5920. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5921. {
  5922. case Gun_Type_Chademo:
  5923. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  5924. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  5925. {
  5926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  5927. {
  5928. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5929. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5930. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  5931. }
  5932. }
  5933. break;
  5934. case Gun_Type_CCS_2:
  5935. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  5936. for (int index = 0; index < CCS_QUANTITY; index++)
  5937. {
  5938. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  5939. {
  5940. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5941. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5942. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  5943. }
  5944. }
  5945. break;
  5946. case Gun_Type_GB:
  5947. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  5948. for (int index = 0; index < GB_QUANTITY; index++)
  5949. {
  5950. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  5951. {
  5952. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5953. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5954. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  5955. }
  5956. }
  5957. break;
  5958. case Gun_Type_AC:
  5959. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  5960. for (int index = 0; index < AC_QUANTITY; index++)
  5961. {
  5962. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  5963. {
  5964. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5965. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5966. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  5967. }
  5968. }
  5969. break;
  5970. default:
  5971. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  5972. break;
  5973. }
  5974. }
  5975. }
  5976. else
  5977. {
  5978. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  5979. {
  5980. gunTotalNumber += 1;
  5981. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5982. {
  5983. case Gun_Type_Chademo:
  5984. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  5985. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  5986. break;
  5987. case Gun_Type_CCS_2:
  5988. gunType[gun_index] = GUN_TYPE_CCS;
  5989. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  5990. break;
  5991. case Gun_Type_GB:
  5992. gunType[gun_index] = GUN_TYPE_GBT;
  5993. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  5994. break;
  5995. case Gun_Type_AC:
  5996. gunType[gun_index] = GUN_TYPE_AC;
  5997. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  5998. break;
  5999. default:
  6000. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  6001. break;
  6002. }
  6003. }
  6004. }
  6005. }
  6006. else
  6007. {
  6008. DEBUG_ERROR("Model name parsing fail.\n");
  6009. result = FAIL;
  6010. }
  6011. if(result != PASS)sleep(5);
  6012. return result;
  6013. }
  6014. //---------------------common routine---------------------------//
  6015. void checkNetworkProfile(void)
  6016. {
  6017. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  6018. json_object *priority;
  6019. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  6020. if(!is_error(priority))
  6021. {
  6022. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  6023. {
  6024. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  6025. {
  6026. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  6027. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  6028. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  6029. {
  6030. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  6031. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  6032. break;
  6033. }
  6034. }
  6035. }
  6036. }
  6037. json_object_put(priority);
  6038. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  6039. }
  6040. void checkRemoteStart(uint8_t connectorIdx)
  6041. {
  6042. uint8_t tempIndex;
  6043. int isAllowStart = TRUE;
  6044. char cmdBuf[512];
  6045. //check Transaction active
  6046. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  6047. {
  6048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6049. {
  6050. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  6051. }
  6052. else
  6053. {
  6054. tempIndex = (connectorIdx-1);
  6055. }
  6056. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6057. {
  6058. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6059. {
  6060. 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))
  6061. {
  6062. //Reserved
  6063. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  6064. }
  6065. 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))
  6066. {
  6067. //Reserved
  6068. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  6069. isAllowStart = FALSE;
  6070. }
  6071. else
  6072. {
  6073. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6074. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6075. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6076. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6077. {
  6078. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  6079. isAllowStart = FALSE;
  6080. }
  6081. }//END FOR ELSE
  6082. }
  6083. }// END FOR CHAdeMO_QUANTITY
  6084. }
  6085. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  6086. {
  6087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6088. {
  6089. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  6090. }
  6091. else
  6092. {
  6093. tempIndex = (connectorIdx-1);
  6094. }
  6095. for (int index = 0; index < CCS_QUANTITY; index++)
  6096. {
  6097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6098. {
  6099. 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))
  6100. {
  6101. //Reserved
  6102. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  6103. }
  6104. 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))
  6105. {
  6106. //Reserved
  6107. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  6108. isAllowStart = FALSE;
  6109. }
  6110. else
  6111. {
  6112. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6113. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6114. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6115. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6116. {
  6117. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  6118. isAllowStart = FALSE;
  6119. }
  6120. }// END FOR ELSE
  6121. }
  6122. }// END FOR CCS_QUANTITY
  6123. }
  6124. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  6125. {
  6126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6127. {
  6128. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  6129. }
  6130. else
  6131. {
  6132. tempIndex = (connectorIdx-1);
  6133. }
  6134. for (int index = 0; index < GB_QUANTITY; index++)
  6135. {
  6136. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6137. {
  6138. 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))
  6139. {
  6140. //Reserved
  6141. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  6142. }
  6143. 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))
  6144. {
  6145. //Reserved
  6146. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  6147. isAllowStart = FALSE;
  6148. }
  6149. else
  6150. {
  6151. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6152. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6153. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6154. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6155. {
  6156. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  6157. isAllowStart = FALSE;
  6158. }
  6159. }// END FOR ELSE
  6160. }
  6161. } // END FOR GB_QUANTITY
  6162. }
  6163. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  6164. {
  6165. tempIndex = (connectorIdx-1);
  6166. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  6169. {
  6170. 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))
  6171. {
  6172. //Reserved
  6173. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  6174. }
  6175. 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))
  6176. {
  6177. //Reserved
  6178. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  6179. isAllowStart = FALSE;
  6180. }
  6181. else
  6182. {
  6183. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6184. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6185. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6186. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6187. {
  6188. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  6189. isAllowStart = FALSE;
  6190. }
  6191. }// END FOR ELSE
  6192. }
  6193. } // END FOR GB_QUANTITY
  6194. }
  6195. else
  6196. {
  6197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6198. {
  6199. tempIndex = 2;
  6200. }
  6201. else
  6202. {
  6203. tempIndex = (connectorIdx-1);
  6204. }
  6205. for (int index = 0; index < AC_QUANTITY; index++)
  6206. {
  6207. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6208. {
  6209. 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))
  6210. {
  6211. //Reserved
  6212. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  6213. }
  6214. 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))
  6215. {
  6216. //Reserved
  6217. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  6218. isAllowStart = FALSE;
  6219. }
  6220. else
  6221. {
  6222. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6223. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6224. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6225. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6226. {
  6227. DEBUG_WARN("AC connector not allow start cause busy.\n");
  6228. isAllowStart = FALSE;
  6229. }
  6230. }//END FOR ELSE
  6231. }
  6232. }// END FOR AC_QUANTITY
  6233. }
  6234. if(isAllowStart == TRUE)
  6235. {
  6236. if(ShmOCPP20Data->RequestStartTransaction[connectorIdx -1].chargingProfile.id > 0)
  6237. {
  6238. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  6239. {
  6240. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  6241. system(cmdBuf);
  6242. }
  6243. }
  6244. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  6245. }
  6246. }
  6247. void CheckSystemValue(void)
  6248. {
  6249. char filenmae[100]={0};
  6250. char str[100]={0};
  6251. int tempIndex = 0;
  6252. //===============================
  6253. // EVSE operation check
  6254. //===============================
  6255. //===============================
  6256. // Heartbeat check
  6257. //===============================
  6258. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  6259. {
  6260. //parameter for test
  6261. sendHeartbeatRequest(0);
  6262. //==============================================
  6263. // Reset Waiting Time
  6264. //==============================================
  6265. HeartBeatWithNOResponse += 1;
  6266. }
  6267. //===============================
  6268. // CSU Trigger Authorize Request
  6269. //===============================
  6270. if(isWebsocketSendable &&
  6271. (server_sign == TRUE) &&
  6272. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6273. (authorizeRetryTimes < 3))
  6274. {
  6275. sendAuthorizeRequest(0);
  6276. authorizeRetryTimes = authorizeRetryTimes + 1;
  6277. if(authorizeRetryTimes < 3)
  6278. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6279. }
  6280. else if((server_sign == TRUE) &&
  6281. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6282. (authorizeRetryTimes >= 3))
  6283. {
  6284. authorizeRetryTimes = 0;
  6285. SetOcppConnStatus(FALSE);
  6286. server_sign = FALSE;
  6287. }
  6288. else if((server_sign == FALSE) &&
  6289. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true") == 0) &&
  6290. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  6291. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6292. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6293. {
  6294. sendAuthorizeRequest(0);
  6295. }
  6296. //===============================
  6297. // NotifyMonitoringReportRequest
  6298. //===============================
  6299. if(isWebsocketSendable &&
  6300. (server_sign == TRUE) &&
  6301. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6302. {
  6303. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  6304. {
  6305. if((strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0) ||
  6306. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0) ||
  6307. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0))
  6308. {
  6309. /*for(uint8_t idxVarMonitoring=0; idxVarMonitoring<10; idxVarMonitoring++)
  6310. {
  6311. if(strcmp((char*)ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].variableMonitoring[idxVarMonitoring].type, (char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion]))
  6312. {
  6313. strcpy(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxVarMonitoring].component, ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].
  6314. }
  6315. }*/
  6316. }
  6317. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  6318. {
  6319. /*
  6320. * TODO:
  6321. * 1. Report component that are ThresholdMonitoring
  6322. */
  6323. }
  6324. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  6325. {
  6326. /*
  6327. * TODO:
  6328. * 1. Report component that are DeltaMonitoring
  6329. */
  6330. }
  6331. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  6332. {
  6333. /*
  6334. * TODO:
  6335. * 1. Report component that are PeriodicMonitoring
  6336. */
  6337. }
  6338. else
  6339. {
  6340. /*
  6341. * TODO:
  6342. * 1. Process unknown criteria condition
  6343. */
  6344. }
  6345. }
  6346. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6347. }
  6348. if(isWebsocketSendable &&
  6349. (server_sign == TRUE) &&
  6350. (ShmOCPP20Data->GetReport.requestId > 0))
  6351. {
  6352. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6353. {
  6354. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6355. {
  6356. /*
  6357. * TODO:
  6358. * 1. Report component that are active
  6359. */
  6360. }
  6361. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6362. {
  6363. /*
  6364. * TODO:
  6365. * 1. Report component that are available
  6366. */
  6367. }
  6368. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6369. {
  6370. /*
  6371. * TODO:
  6372. * 1. Report component that are enable
  6373. */
  6374. }
  6375. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6376. {
  6377. /*
  6378. * TODO:
  6379. * 1. Report component that are problem
  6380. */
  6381. }
  6382. else
  6383. {
  6384. /*
  6385. * TODO:
  6386. * 1. Process unknown criteria condition
  6387. */
  6388. }
  6389. }
  6390. ShmOCPP20Data->GetReport.requestId = 0;
  6391. }
  6392. if(isWebsocketSendable &&
  6393. (server_sign == TRUE) &&
  6394. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6395. {
  6396. uint8_t reportIdx = 0;
  6397. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  6398. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  6399. {
  6400. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6401. {
  6402. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6403. {
  6404. 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))
  6405. {
  6406. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6407. reportIdx++;
  6408. }
  6409. }
  6410. else
  6411. {
  6412. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6413. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6414. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6415. else
  6416. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6417. sendNotifyReportRequest();
  6418. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6419. reportIdx = 0;
  6420. idx_var--;
  6421. }
  6422. }
  6423. }
  6424. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  6425. {
  6426. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6427. {
  6428. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6429. {
  6430. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6431. reportIdx++;
  6432. }
  6433. else
  6434. {
  6435. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6436. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6437. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6438. else
  6439. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6440. sendNotifyReportRequest();
  6441. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6442. reportIdx = 0;
  6443. idx_var--;
  6444. }
  6445. }
  6446. }
  6447. else
  6448. {
  6449. /*
  6450. * TODO:
  6451. * 1. Fill out summary inventory to response message, currently not support
  6452. */
  6453. }
  6454. if(reportIdx > 0)
  6455. {
  6456. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  6457. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  6458. ShmOCPP20Data->NotifyReport.seqNo += 1;
  6459. else
  6460. ShmOCPP20Data->NotifyReport.seqNo = 0;
  6461. sendNotifyReportRequest();
  6462. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  6463. reportIdx = 0;
  6464. }
  6465. ShmOCPP20Data->GetBaseReport.requestId = 0;
  6466. }
  6467. if(isWebsocketSendable &&
  6468. (server_sign == TRUE) &&
  6469. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  6470. {
  6471. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  6472. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  6473. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  6474. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  6475. else
  6476. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  6477. sendNotifyEventRequest();
  6478. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  6479. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  6480. }
  6481. if(isWebsocketSendable &&
  6482. (server_sign == TRUE) &&
  6483. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  6484. {
  6485. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  6486. {
  6487. /*
  6488. * TODO:
  6489. * 1.
  6490. */
  6491. }
  6492. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  6493. {
  6494. /*
  6495. * TODO:
  6496. * 1.
  6497. */
  6498. }
  6499. else
  6500. {
  6501. /*
  6502. * TODO:
  6503. * 1.
  6504. */
  6505. }
  6506. sendGet15118EVCertificateRequest();
  6507. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  6508. }
  6509. if(isWebsocketSendable &&
  6510. (server_sign == TRUE) &&
  6511. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  6512. {
  6513. sendSecurityEventNotificationRequest();
  6514. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  6515. }
  6516. if(isWebsocketSendable &&
  6517. (server_sign == TRUE) &&
  6518. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  6519. {
  6520. sendNotifyCustomerInformationRequest();
  6521. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  6522. }
  6523. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6524. {
  6525. // ClockAlign MeterValue
  6526. 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))
  6527. {
  6528. //check Transaction active
  6529. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6530. {
  6531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6532. {
  6533. tempIndex = ((gun_index==2) ? 1: 0);
  6534. }
  6535. else
  6536. {
  6537. tempIndex = gun_index;
  6538. }
  6539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6540. {
  6541. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6542. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6543. {
  6544. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6545. }
  6546. }// End for CHAdeMO
  6547. }
  6548. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6549. {
  6550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6551. {
  6552. tempIndex = ((gun_index==2) ? 1: 0);
  6553. }
  6554. else
  6555. {
  6556. tempIndex = gun_index;
  6557. }
  6558. for (int index = 0; index < CCS_QUANTITY; index++)
  6559. {
  6560. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6561. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6562. {
  6563. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6564. }
  6565. } // End for CCS
  6566. }
  6567. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6568. {
  6569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6570. {
  6571. tempIndex = ((gun_index==2) ? 1: 0);
  6572. }
  6573. else
  6574. {
  6575. tempIndex = gun_index;
  6576. }
  6577. for (int index = 0; index < GB_QUANTITY; index++)
  6578. {
  6579. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6580. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6581. {
  6582. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6583. }
  6584. }// End for GB
  6585. }
  6586. else if(gunType[gun_index] == GUN_TYPE_DO)
  6587. {
  6588. tempIndex = gun_index;
  6589. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6590. {
  6591. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6592. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6593. {
  6594. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6595. }
  6596. }
  6597. }
  6598. else
  6599. {
  6600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6601. {
  6602. tempIndex = 2;
  6603. }
  6604. else
  6605. {
  6606. tempIndex = gun_index;
  6607. }
  6608. for (int index = 0; index < AC_QUANTITY; index++)
  6609. {
  6610. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6611. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6612. {
  6613. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  6614. }
  6615. }//End for AC
  6616. }
  6617. }
  6618. }
  6619. //===============================
  6620. // Each connector operation check
  6621. //===============================
  6622. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  6623. {
  6624. //==========================================
  6625. // Check remote start without connector id
  6626. //==========================================
  6627. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  6628. {
  6629. int connectorIdInt = -1;
  6630. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  6631. {
  6632. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  6633. {
  6634. connectorIdInt = (gun_index+1);
  6635. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  6636. checkRemoteStart(connectorIdInt);
  6637. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  6638. break;
  6639. }
  6640. }
  6641. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  6642. {
  6643. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  6644. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  6645. }
  6646. }
  6647. //==========================================
  6648. // csu trigger DataTransferReq
  6649. //==========================================
  6650. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  6651. {
  6652. sendDataTransferRequest(gun_index);
  6653. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  6654. }
  6655. //==============================================
  6656. // Charger status notification & Transaction event report
  6657. //==============================================
  6658. //--- Check Mode Change ---//
  6659. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6660. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6661. {
  6662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6663. {
  6664. tempIndex = ((gun_index==2) ? 1: 0);
  6665. }
  6666. else
  6667. {
  6668. tempIndex = gun_index;
  6669. }
  6670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6671. {
  6672. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6673. {
  6674. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  6675. {
  6676. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  6677. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  6678. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6679. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6680. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  6681. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  6682. {
  6683. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6684. }
  6685. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6686. {
  6687. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6688. if((access(filenmae,F_OK))!=-1)
  6689. {
  6690. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6691. sprintf(str,"rm -f %s",filenmae);
  6692. system(str);
  6693. }
  6694. }
  6695. }
  6696. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6697. #if 1 // for TempStopTransaction
  6698. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6699. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6700. {
  6701. checkTempStopTransaction(gun_index);
  6702. }
  6703. #endif
  6704. }
  6705. }
  6706. }
  6707. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6708. {
  6709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6710. {
  6711. tempIndex = ((gun_index==2) ? 1: 0);
  6712. }
  6713. else
  6714. {
  6715. tempIndex = gun_index;
  6716. }
  6717. for (int index = 0; index < CCS_QUANTITY; index++)
  6718. {
  6719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6720. {
  6721. 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]*/ )
  6722. {
  6723. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  6724. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  6725. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6726. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6727. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  6728. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  6729. {
  6730. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6731. }
  6732. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6733. {
  6734. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6735. if((access(filenmae,F_OK))!=-1)
  6736. {
  6737. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6738. sprintf(str,"rm -f %s",filenmae);
  6739. system(str);
  6740. }
  6741. }
  6742. }
  6743. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6744. #if 1 // for TempStopTransaction
  6745. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6746. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6747. {
  6748. checkTempStopTransaction(gun_index);
  6749. }
  6750. #endif
  6751. }
  6752. }
  6753. }
  6754. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6755. {
  6756. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6757. {
  6758. tempIndex = ((gun_index==2) ? 1: 0);
  6759. }
  6760. else
  6761. {
  6762. tempIndex = gun_index;
  6763. }
  6764. for (int index = 0; index < GB_QUANTITY; index++)
  6765. {
  6766. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6767. {
  6768. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  6769. {
  6770. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  6771. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  6772. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6773. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6774. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  6775. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  6776. {
  6777. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6778. }
  6779. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6780. {
  6781. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6782. if((access(filenmae,F_OK))!=-1)
  6783. {
  6784. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6785. sprintf(str,"rm -f %s",filenmae);
  6786. system(str);
  6787. }
  6788. }
  6789. }
  6790. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6791. #if 1 // for TempStopTransaction
  6792. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6793. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6794. {
  6795. checkTempStopTransaction(gun_index);
  6796. }
  6797. #endif
  6798. }
  6799. }
  6800. }
  6801. else if(gunType[gun_index] == GUN_TYPE_DO)
  6802. {
  6803. tempIndex = gun_index;
  6804. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6807. {
  6808. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  6809. {
  6810. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  6811. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  6812. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6813. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  6814. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE) &&
  6815. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != AcPreviousSystemStatus[index]))
  6816. {
  6817. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6818. }
  6819. 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
  6820. {
  6821. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6822. if((access(filenmae,F_OK))!=-1)
  6823. {
  6824. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6825. sprintf(str,"rm -f %s",filenmae);
  6826. system(str);
  6827. }
  6828. }
  6829. }
  6830. 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);
  6831. #if 1 // for TempStopTransaction
  6832. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  6833. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6834. {
  6835. checkTempStopTransaction(gun_index);
  6836. }
  6837. #endif
  6838. }
  6839. }
  6840. }
  6841. else
  6842. {
  6843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6844. {
  6845. tempIndex = 2;
  6846. }
  6847. else
  6848. {
  6849. tempIndex = gun_index;
  6850. }
  6851. for (int index = 0; index < AC_QUANTITY; index++)
  6852. {
  6853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6854. {
  6855. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  6856. {
  6857. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  6858. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6859. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6860. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  6861. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) && (AcPreviousSystemStatus[index] != 99))
  6862. {
  6863. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6864. }
  6865. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  6866. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  6867. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6868. {
  6869. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6870. if((access(filenmae,F_OK))!=-1)
  6871. {
  6872. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6873. sprintf(str,"rm -f %s",filenmae);
  6874. system(str);
  6875. }
  6876. }
  6877. }
  6878. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6879. #if 1 // for TempStopTransaction
  6880. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6881. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6882. {
  6883. checkTempStopTransaction(gun_index);
  6884. }
  6885. #endif
  6886. }
  6887. }// END
  6888. }
  6889. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  6890. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  6891. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") == 0) &&
  6892. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  6893. {
  6894. sendStatusNotificationRequest(gun_index);
  6895. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  6896. }
  6897. //==============================================
  6898. // CSU Trigger or timer timeout refresh Smart Charging Profile
  6899. //==============================================
  6900. if((ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON) ||
  6901. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value))))
  6902. {
  6903. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  6904. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  6905. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  6906. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  6907. }
  6908. //==============================================
  6909. // CSU transaction event
  6910. //==============================================
  6911. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON || cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  6912. {
  6913. sendTransactionEventRequest(gun_index);
  6914. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  6915. cpinitateMsg.bits[gun_index].TriggerTransactionEventReq = OFF;
  6916. //storeTempStopTransaction(gun_index);
  6917. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  6918. }
  6919. //==============================================
  6920. // Meter report
  6921. //==============================================
  6922. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  6923. {
  6924. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  6925. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  6926. }
  6927. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  6928. {
  6929. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  6930. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  6931. }
  6932. // Sample period MeterValue
  6933. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0) &&
  6934. (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)))
  6935. {
  6936. //check Transaction active
  6937. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6938. {
  6939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6940. {
  6941. tempIndex = ((gun_index==2) ? 1: 0);
  6942. }
  6943. else
  6944. {
  6945. tempIndex = gun_index;
  6946. }
  6947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6948. {
  6949. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6950. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6951. {
  6952. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6953. {
  6954. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6955. }
  6956. }
  6957. }// End for CHAdeMO
  6958. }
  6959. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6960. {
  6961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6962. {
  6963. tempIndex = ((gun_index==2) ? 1: 0);
  6964. }
  6965. else
  6966. {
  6967. tempIndex = gun_index;
  6968. }
  6969. for (int index = 0; index < CCS_QUANTITY; index++)
  6970. {
  6971. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6972. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6973. {
  6974. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6975. {
  6976. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6977. }
  6978. }
  6979. } // End for CCS
  6980. }
  6981. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6982. {
  6983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6984. {
  6985. tempIndex = ((gun_index==2) ? 1: 0);
  6986. }
  6987. else
  6988. {
  6989. tempIndex = gun_index;
  6990. }
  6991. for (int index = 0; index < GB_QUANTITY; index++)
  6992. {
  6993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6994. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6995. {
  6996. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6997. {
  6998. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6999. }
  7000. }
  7001. }// End for GB
  7002. }
  7003. else if(gunType[gun_index] == GUN_TYPE_DO)
  7004. {
  7005. tempIndex = gun_index;
  7006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7007. {
  7008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7009. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7010. {
  7011. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  7012. {
  7013. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7014. }
  7015. }
  7016. }
  7017. }
  7018. else
  7019. {
  7020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7021. {
  7022. tempIndex = 2;
  7023. }
  7024. else
  7025. {
  7026. tempIndex = gun_index;
  7027. }
  7028. for (int index = 0; index < AC_QUANTITY; index++)
  7029. {
  7030. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7031. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7032. {
  7033. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7034. {
  7035. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7036. }
  7037. }
  7038. }//End for AC
  7039. }
  7040. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7041. {
  7042. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7043. {
  7044. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  7045. }
  7046. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7047. }
  7048. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  7049. }
  7050. //==============================================
  7051. // Check Connector reserved
  7052. //==============================================
  7053. //===============================
  7054. // Check if Reserve is expired
  7055. //===============================
  7056. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  7057. {
  7058. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  7059. {
  7060. DEBUG_INFO("reserve expired.\n");
  7061. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  7062. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  7063. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  7064. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  7065. }
  7066. }//END OF Check if Reserve is expired
  7067. //==========================================
  7068. // csu trigger FirmwareStatusNotificationReq
  7069. //==========================================
  7070. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  7071. {
  7072. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  7073. }
  7074. //==========================================
  7075. // csu cleared charging limit request
  7076. //==========================================
  7077. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  7078. {
  7079. sendClearedChargingLimitRequest(gun_index);
  7080. }
  7081. //==========================================
  7082. // csu trigger CancelReservationConf
  7083. //==========================================
  7084. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  7085. {
  7086. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  7087. }
  7088. //==========================================
  7089. // csu notify EV charging need request
  7090. //==========================================
  7091. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  7092. {
  7093. sendNotifyEVChargingNeedsRequest(gun_index);
  7094. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  7095. }
  7096. //==========================================
  7097. // csu notify EV charging schedule request
  7098. //==========================================
  7099. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq == ON))
  7100. {
  7101. sendNotifyEVChargingScheduleRequest(gun_index);
  7102. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  7103. }
  7104. //==========================================
  7105. // csu trigger ChangeAvailabilityConf
  7106. //==========================================
  7107. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  7108. {
  7109. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  7110. }
  7111. //==========================================
  7112. // csu trigger UnlockConnectorConf
  7113. //==========================================
  7114. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  7115. {
  7116. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  7117. }
  7118. //==========================================
  7119. // csu trigger ReserveNowConf
  7120. //==========================================
  7121. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  7122. {
  7123. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  7124. }
  7125. //==========================================
  7126. // csu trigger ReserveNowConf
  7127. //==========================================
  7128. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  7129. {
  7130. sendReservationStatusUpdateRequest(gun_index);
  7131. }
  7132. //==========================================
  7133. // csu trigger LogStatusNotificationReq
  7134. //==========================================
  7135. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  7136. {
  7137. if(isCancelUploadLog == TRUE)
  7138. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7139. else
  7140. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  7141. }
  7142. //==========================================
  7143. // csu trigger SignCertificateReq
  7144. //==========================================
  7145. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  7146. {
  7147. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  7148. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  7149. {
  7150. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  7151. }
  7152. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  7153. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  7154. {
  7155. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  7156. }
  7157. }
  7158. }
  7159. }
  7160. //==========================================
  7161. // send request routine
  7162. //==========================================
  7163. int sendAuthorizeRequest(int gun_index)
  7164. {
  7165. mtrace();
  7166. int result = FAIL;
  7167. char message[4096]={0};
  7168. char guid[37];
  7169. char tempdata[128]={0};
  7170. json_object *Authorize = json_object_new_object();
  7171. json_object *idToken = json_object_new_object();
  7172. json_object *iso15118CertificateHashData = json_object_new_array();
  7173. DEBUG_INFO("sendAuthorizeRequest...\n");
  7174. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  7175. //Local Authorize
  7176. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "true")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  7177. {
  7178. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  7179. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7180. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  7181. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  7182. result = PASS;
  7183. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7184. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7185. authorizeRetryTimes = 0;
  7186. return result;
  7187. }
  7188. 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)) ||
  7189. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true") == 0)))
  7190. {
  7191. // Query idtag from cache
  7192. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  7193. // Query idtag from list
  7194. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  7195. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  7196. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  7197. {
  7198. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  7199. {
  7200. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7201. }
  7202. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  7203. {
  7204. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7205. }
  7206. // Return authorize result if does not connect to server
  7207. if(!ShmOCPP20Data->OcppConnStatus)
  7208. {
  7209. DEBUG_INFO("Local Authorization Fail.\n");
  7210. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7211. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7212. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  7213. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7214. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7215. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7216. authorizeRetryTimes = 0;
  7217. return result;
  7218. }
  7219. }
  7220. else
  7221. {
  7222. DEBUG_INFO("Local Authorization get result.\n");
  7223. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  7224. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7225. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  7226. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  7227. else
  7228. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  7229. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7230. result = PASS;
  7231. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7232. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7233. authorizeRetryTimes = 0;
  7234. return result;
  7235. }
  7236. }
  7237. //get data from shared memory
  7238. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7239. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  7240. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  7241. if(strcmp((char*)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenType_eMAID]) == 0)
  7242. {
  7243. json_object *OCSPRequestDataType = json_object_new_object();
  7244. json_object_object_add(Authorize, "certificate", json_object_new_string((char*)ShmOCPP20Data->Authorize.certificate));
  7245. for(int idx=0; idx < 4; idx++)
  7246. {
  7247. if(strlen((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL) >= 7)
  7248. {
  7249. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  7250. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  7251. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  7252. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].serialNumber));
  7253. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL));
  7254. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  7255. }
  7256. }
  7257. json_object_object_add(Authorize, "iso15118CertificateHashData", iso15118CertificateHashData);
  7258. }
  7259. json_object_object_add(Authorize, "idToken", idToken);
  7260. random_uuid(guid);
  7261. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  7262. json_object_put(Authorize);
  7263. LWS_Send(message);
  7264. sprintf(tempdata, "Authorize,%d", gun_index);
  7265. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7266. {
  7267. result = PASS;
  7268. }
  7269. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7270. return result;
  7271. }
  7272. int sendBootNotificationRequest()
  7273. {
  7274. mtrace();
  7275. int result = FAIL;
  7276. char message[4096]={0};
  7277. char guid[37]={0};
  7278. char tempdata[128]={0};
  7279. json_object *BootNotification = json_object_new_object();
  7280. json_object *chargingStation = json_object_new_object();
  7281. json_object *modem = json_object_new_object();
  7282. DEBUG_INFO("sendBootNotificationRequest...\n");
  7283. // Fill BootNotification fields
  7284. DB_getBooType();
  7285. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  7286. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7287. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7288. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  7289. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  7290. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  7291. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  7292. {
  7293. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  7294. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  7295. json_object_object_add(chargingStation, "modem", modem);
  7296. }
  7297. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  7298. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  7299. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  7300. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  7301. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  7302. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  7303. random_uuid(guid);
  7304. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  7305. json_object_put(BootNotification);
  7306. LWS_Send(message);
  7307. sprintf(tempdata, "BootNotification,0");
  7308. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7309. {
  7310. result = PASS;
  7311. }
  7312. return result;
  7313. }
  7314. int sendClearedChargingLimitRequest(int gun_index)
  7315. {
  7316. mtrace();
  7317. int result = FAIL;
  7318. char message[4096]={0};
  7319. char guid[37]={0};
  7320. char tempdata[128]={0};
  7321. json_object *ClearedChargingLimit = json_object_new_object();
  7322. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  7323. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  7324. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  7325. random_uuid(guid);
  7326. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  7327. json_object_put(ClearedChargingLimit);
  7328. LWS_Send(message);
  7329. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  7330. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7331. {
  7332. result = PASS;
  7333. }
  7334. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  7335. return result;
  7336. }
  7337. int sendDataTransferRequest(int gun_index)
  7338. {
  7339. mtrace();
  7340. char message[1000]={0};
  7341. char guid[37]={0};
  7342. char tempdata[65]={0};
  7343. int result = FAIL;
  7344. DEBUG_INFO("sendDataTransferRequest...\n");
  7345. random_uuid(guid);
  7346. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  7347. MESSAGE_TYPE_CALL,
  7348. guid,
  7349. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  7350. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  7351. ShmOCPP20Data->DataTransfer[gun_index].data);
  7352. LWS_Send(message);
  7353. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  7354. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7355. {
  7356. result = PASS;
  7357. }
  7358. return result;
  7359. }
  7360. int sendFirmwareStatusNotificationRequest(char *status)
  7361. {
  7362. mtrace();
  7363. int result = FAIL;
  7364. char message[110]={0};
  7365. char guid[37]={0};
  7366. char tempdata[65]={0};
  7367. json_object *FirmwareStatusNotification = json_object_new_object();
  7368. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  7369. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  7370. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  7371. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  7372. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  7373. random_uuid(guid);
  7374. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7375. json_object_put(FirmwareStatusNotification);
  7376. LWS_SendNow(message);
  7377. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7378. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7379. {
  7380. result = PASS;
  7381. }
  7382. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  7383. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  7384. //record status
  7385. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  7386. {
  7387. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  7388. }
  7389. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  7390. {
  7391. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  7392. }
  7393. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  7394. {
  7395. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  7396. }
  7397. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  7398. {
  7399. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  7400. }
  7401. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  7402. {
  7403. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  7404. }
  7405. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  7406. {
  7407. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  7408. }
  7409. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  7410. {
  7411. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  7412. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7413. }
  7414. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  7415. {
  7416. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  7417. }
  7418. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  7419. {
  7420. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  7421. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7422. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  7423. }
  7424. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  7425. {
  7426. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  7427. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  7428. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  7429. }
  7430. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  7431. {
  7432. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  7433. }
  7434. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  7435. {
  7436. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  7437. }
  7438. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  7439. {
  7440. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  7441. }
  7442. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  7443. {
  7444. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  7445. }
  7446. return result;
  7447. }
  7448. int sendGet15118EVCertificateRequest()
  7449. {
  7450. mtrace();
  7451. int result = FAIL;
  7452. char message[4096]={0};
  7453. char guid[37]={0};
  7454. char tempdata[128]={0};
  7455. json_object *Get15118EVCertificate = json_object_new_object();
  7456. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  7457. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  7458. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  7459. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  7460. random_uuid(guid);
  7461. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  7462. json_object_put(Get15118EVCertificate);
  7463. LWS_Send(message);
  7464. sprintf(tempdata, "Get15118EVCertificate,0");
  7465. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7466. {
  7467. result = PASS;
  7468. }
  7469. return result;
  7470. }
  7471. int sendGetCertificateStatusRequest()
  7472. {
  7473. mtrace();
  7474. int result = FAIL;
  7475. char message[4096]={0};
  7476. char guid[37]={0};
  7477. char tempdata[128]={0};
  7478. json_object *GetCertificateStatus = json_object_new_object();
  7479. json_object *ocspRequestData = json_object_new_object();
  7480. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  7481. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  7482. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  7483. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  7484. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  7485. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  7486. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  7487. random_uuid(guid);
  7488. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  7489. json_object_put(GetCertificateStatus);
  7490. LWS_Send(message);
  7491. sprintf(tempdata, "GetCertificateStatus,0");
  7492. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7493. {
  7494. result = PASS;
  7495. }
  7496. return result;
  7497. }
  7498. int sendHeartbeatRequest()
  7499. {
  7500. mtrace();
  7501. int result = FAIL;
  7502. char message[40096]={0};
  7503. char guid[37]={0};
  7504. char tempdata[128]={0};
  7505. DEBUG_INFO("sendHeartbeatRequest...\n");
  7506. random_uuid(guid);
  7507. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{}]"
  7508. , MESSAGE_TYPE_CALL
  7509. , guid );
  7510. LWS_Send(message);
  7511. sprintf(tempdata, "Heartbeat,%d", 0);
  7512. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7513. {
  7514. result = PASS;
  7515. }
  7516. return result;
  7517. }
  7518. int sendLogStatusNotificationRequest(char *status)
  7519. {
  7520. mtrace();
  7521. int result = FAIL;
  7522. char message[4096]={0};
  7523. char guid[37]={0};
  7524. char tempdata[128]={0};
  7525. json_object *LogStatusNotification = json_object_new_object();
  7526. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7527. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  7528. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  7529. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  7530. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  7531. random_uuid(guid);
  7532. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7533. json_object_put(LogStatusNotification);
  7534. LWS_SendNow(message);
  7535. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7536. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7537. {
  7538. result = PASS;
  7539. }
  7540. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7541. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  7542. //record status
  7543. if(strcmp(status,"BadMessage")==0)
  7544. {
  7545. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  7546. }
  7547. else if(strcmp(status,"Idle")==0)
  7548. {
  7549. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  7550. }
  7551. else if(strcmp(status,"NotSupportedOperation")==0)
  7552. {
  7553. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  7554. }
  7555. else if(strcmp(status,"PermissionDenied")==0)
  7556. {
  7557. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  7558. }
  7559. else if(strcmp(status,"Uploaded")==0)
  7560. {
  7561. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  7562. }
  7563. else if(strcmp(status,"UploadFailure")==0)
  7564. {
  7565. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  7566. }
  7567. else if(strcmp(status,"Uploading")==0)
  7568. {
  7569. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  7570. }
  7571. return result;
  7572. }
  7573. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  7574. {
  7575. mtrace();
  7576. int result = FAIL;
  7577. char guid[37]={0};
  7578. char tempdata[65]={0};
  7579. int tempIndex = 0;
  7580. json_object *MeterValueReq = json_object_new_object();
  7581. json_object *meterValues = json_object_new_array();
  7582. json_object *sampledValues = json_object_new_array();
  7583. DEBUG_INFO("sendMeterValuesRequest...\n");
  7584. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  7585. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  7586. //set value
  7587. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  7588. //UTC Date time
  7589. struct timeval tmnow;
  7590. struct tm *tm;
  7591. char buf[28];//, usec_buf[6];
  7592. gettimeofday(&tmnow, NULL);
  7593. time_t t;
  7594. t = time(NULL);
  7595. /*UTC time and date*/
  7596. tm = gmtime(&t);
  7597. if(dataType == ReadingContextEnumType_Sample_Clock)
  7598. {
  7599. struct tm *tmTarget;
  7600. struct timeb tbTarget;
  7601. tbTarget.time = mktime(tm);
  7602. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  7603. tmTarget = gmtime(&tbTarget.time);
  7604. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  7605. }
  7606. else
  7607. {
  7608. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7609. }
  7610. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  7611. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  7612. //idx_sample=0;
  7613. //********************************(1)Current.Import L1************************************************/
  7614. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7615. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7616. (dataType == ReadingContextEnumType_Trigger))
  7617. {
  7618. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7619. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7620. {
  7621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7622. {
  7623. tempIndex = ((gun_index==2) ? 1: 0);
  7624. }
  7625. else
  7626. {
  7627. tempIndex = gun_index;
  7628. }
  7629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7630. {
  7631. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7632. {
  7633. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent*100))/100.0;
  7634. }
  7635. }
  7636. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7637. }
  7638. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7639. {
  7640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7641. {
  7642. tempIndex = ((gun_index==2) ? 1: 0);
  7643. }
  7644. else
  7645. {
  7646. tempIndex = gun_index;
  7647. }
  7648. for (int index = 0; index < CCS_QUANTITY; index++)
  7649. {
  7650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7651. {
  7652. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent*100))/100.0;
  7653. }
  7654. }
  7655. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7656. }
  7657. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7658. {
  7659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7660. {
  7661. tempIndex = ((gun_index==2) ? 1: 0);
  7662. }
  7663. else
  7664. {
  7665. tempIndex = gun_index;
  7666. }
  7667. for (int index = 0; index < GB_QUANTITY; index++)
  7668. {
  7669. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7670. {
  7671. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent*100))/100.0;
  7672. }
  7673. }
  7674. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7675. }
  7676. else if(gunType[gun_index] == GUN_TYPE_DO)
  7677. {
  7678. tempIndex = gun_index;
  7679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7680. {
  7681. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7682. {
  7683. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent*100))/100.0;
  7684. }
  7685. }
  7686. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7687. }
  7688. else
  7689. {
  7690. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7691. {
  7692. tempIndex = 2;
  7693. }
  7694. else
  7695. {
  7696. tempIndex = gun_index;
  7697. }
  7698. for (int index = 0; index < AC_QUANTITY; index++)
  7699. {
  7700. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7701. {
  7702. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent*100))/100.0;
  7703. }
  7704. }
  7705. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7706. }
  7707. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  7708. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7709. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7710. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  7711. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  7712. }
  7713. //idx_sample=1;
  7714. //********************************(2)Energy.Active.Import.Register ************************************************/
  7715. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  7716. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  7717. (dataType == ReadingContextEnumType_Trigger))
  7718. {
  7719. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7720. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7721. {
  7722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7723. {
  7724. tempIndex = ((gun_index==2) ? 1: 0);
  7725. }
  7726. else
  7727. {
  7728. tempIndex = gun_index;
  7729. }
  7730. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7731. {
  7732. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7733. {
  7734. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*100))/100.0;
  7735. }
  7736. }
  7737. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7738. }
  7739. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7740. {
  7741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7742. {
  7743. tempIndex = ((gun_index==2) ? 1: 0);
  7744. }
  7745. else
  7746. {
  7747. tempIndex = gun_index;
  7748. }
  7749. for (int index = 0; index < CCS_QUANTITY; index++)
  7750. {
  7751. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7752. {
  7753. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*100))/100.0;
  7754. }
  7755. }
  7756. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7757. }
  7758. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7759. {
  7760. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7761. {
  7762. tempIndex = ((gun_index==2) ? 1: 0);
  7763. }
  7764. else
  7765. {
  7766. tempIndex = gun_index;
  7767. }
  7768. for (int index = 0; index < GB_QUANTITY; index++)
  7769. {
  7770. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7771. {
  7772. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*100))/100.0;
  7773. }
  7774. }
  7775. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7776. }
  7777. else if(gunType[gun_index] == GUN_TYPE_DO)
  7778. {
  7779. tempIndex = gun_index;
  7780. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7781. {
  7782. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7783. {
  7784. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*100))/100.0;
  7785. }
  7786. }
  7787. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7788. }
  7789. else
  7790. {
  7791. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7792. {
  7793. tempIndex = 2;
  7794. }
  7795. else
  7796. {
  7797. tempIndex = gun_index;
  7798. }
  7799. for (int index = 0; index < AC_QUANTITY; index++)
  7800. {
  7801. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7802. {
  7803. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*100))/100.0;
  7804. }
  7805. }
  7806. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7807. }
  7808. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  7809. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  7810. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7811. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  7812. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7813. }
  7814. //idx_sample=2;
  7815. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7816. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7817. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7818. (dataType == ReadingContextEnumType_Trigger))
  7819. {
  7820. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7821. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7822. {
  7823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7824. {
  7825. tempIndex = ((gun_index==2) ? 1: 0);
  7826. }
  7827. else
  7828. {
  7829. tempIndex = gun_index;
  7830. }
  7831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7832. {
  7833. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7834. {
  7835. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*100))/100.0;
  7836. if(dataType == ReadingContextEnumType_Sample_Clock)
  7837. {
  7838. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7839. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7840. }
  7841. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7842. {
  7843. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7844. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7845. }
  7846. else
  7847. {
  7848. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7849. }
  7850. }
  7851. } // END OF FOR CHAdeMO_QUANTITY
  7852. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7853. }
  7854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7855. {
  7856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7857. {
  7858. tempIndex = ((gun_index==2) ? 1: 0);
  7859. }
  7860. else
  7861. {
  7862. tempIndex = gun_index;
  7863. }
  7864. for (int index = 0; index < CCS_QUANTITY; index++)
  7865. {
  7866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7867. {
  7868. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*100))/100.0;
  7869. if(dataType == ReadingContextEnumType_Sample_Clock)
  7870. {
  7871. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7872. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7873. }
  7874. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7875. {
  7876. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7877. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7878. }
  7879. else
  7880. {
  7881. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7882. }
  7883. }
  7884. } // END OF CCS_QUANTITY
  7885. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7886. }
  7887. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7888. {
  7889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7890. {
  7891. tempIndex = ((gun_index==2) ? 1: 0);
  7892. }
  7893. else
  7894. {
  7895. tempIndex = gun_index;
  7896. }
  7897. for (int index = 0; index < GB_QUANTITY; index++)
  7898. {
  7899. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7900. {
  7901. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*100))/100.0;
  7902. if(dataType == ReadingContextEnumType_Sample_Clock)
  7903. {
  7904. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7905. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7906. }
  7907. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7908. {
  7909. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7910. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7911. }
  7912. else
  7913. {
  7914. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7915. }
  7916. }
  7917. } // END OF GB_QUANTITY
  7918. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7919. }
  7920. else if(gunType[gun_index] == GUN_TYPE_DO)
  7921. {
  7922. tempIndex = gun_index;
  7923. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7924. {
  7925. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7926. {
  7927. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*100))/100.0;
  7928. if(dataType == ReadingContextEnumType_Sample_Clock)
  7929. {
  7930. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]);
  7931. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7932. }
  7933. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7934. {
  7935. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7936. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7937. }
  7938. else
  7939. {
  7940. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7941. }
  7942. }
  7943. }
  7944. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7945. }
  7946. else
  7947. {
  7948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7949. {
  7950. tempIndex = 2;
  7951. }
  7952. else
  7953. {
  7954. tempIndex = gun_index;
  7955. }
  7956. for (int index = 0; index < AC_QUANTITY; index++)
  7957. {
  7958. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7959. {
  7960. //ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*100))/100.0;
  7961. if(dataType == ReadingContextEnumType_Sample_Clock)
  7962. {
  7963. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]);
  7964. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7965. }
  7966. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  7967. {
  7968. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  7969. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7970. }
  7971. else
  7972. {
  7973. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  7974. }
  7975. }
  7976. }
  7977. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7978. }
  7979. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  7980. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  7981. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7982. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  7983. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7984. }
  7985. //idx_sample=3;
  7986. //********************************(4)Power.Active.Import************************************************/
  7987. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7988. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7989. (dataType == ReadingContextEnumType_Trigger))
  7990. {
  7991. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7992. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7993. {
  7994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7995. {
  7996. tempIndex = ((gun_index==2) ? 1: 0);
  7997. }
  7998. else
  7999. {
  8000. tempIndex = gun_index;
  8001. }
  8002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8003. {
  8004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8005. {
  8006. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower*100))/100.0;
  8007. }
  8008. } // END OF FOR
  8009. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8010. }
  8011. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8012. {
  8013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8014. {
  8015. tempIndex = ((gun_index==2) ? 1: 0);
  8016. }
  8017. else
  8018. {
  8019. tempIndex = gun_index;
  8020. }
  8021. for (int index = 0; index < CCS_QUANTITY; index++)
  8022. {
  8023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8024. {
  8025. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower*100))/100.0;
  8026. }
  8027. }
  8028. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8029. }
  8030. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8031. {
  8032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8033. {
  8034. tempIndex = ((gun_index==2) ? 1: 0);
  8035. }
  8036. else
  8037. {
  8038. tempIndex = gun_index;
  8039. }
  8040. for (int index = 0; index < GB_QUANTITY; index++)
  8041. {
  8042. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8043. {
  8044. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8045. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower*100))/100.0;
  8046. }
  8047. }
  8048. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8049. }
  8050. else if(gunType[gun_index] == GUN_TYPE_DO)
  8051. {
  8052. tempIndex = gun_index;
  8053. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8054. {
  8055. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8056. {
  8057. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8058. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower*100))/100.0;
  8059. }
  8060. }
  8061. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8062. }
  8063. else
  8064. {
  8065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8066. {
  8067. tempIndex = 2;
  8068. }
  8069. else
  8070. {
  8071. tempIndex = gun_index;
  8072. }
  8073. for (int index = 0; index < AC_QUANTITY; index++)
  8074. {
  8075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8076. {
  8077. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower*100))/100.0;
  8078. }
  8079. }
  8080. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8081. }
  8082. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  8083. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  8084. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8085. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  8086. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  8087. }
  8088. //idx_sample=4;
  8089. //***********************************************(5)VOLTAGE L1******************************************************/
  8090. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8091. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8092. (dataType == ReadingContextEnumType_Trigger))
  8093. {
  8094. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8096. {
  8097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8098. {
  8099. tempIndex = ((gun_index==2) ? 1: 0);
  8100. }
  8101. else
  8102. {
  8103. tempIndex = gun_index;
  8104. }
  8105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8106. {
  8107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8108. {
  8109. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage*100))/100.0;
  8110. }
  8111. }
  8112. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8113. }
  8114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8115. {
  8116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8117. {
  8118. tempIndex = ((gun_index==2) ? 1: 0);
  8119. }
  8120. else
  8121. {
  8122. tempIndex = gun_index;
  8123. }
  8124. for (int index = 0; index < CCS_QUANTITY; index++)
  8125. {
  8126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8127. {
  8128. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage*100))/100.0;
  8129. }
  8130. }
  8131. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8132. }
  8133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8134. {
  8135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8136. {
  8137. tempIndex = ((gun_index==2) ? 1: 0);
  8138. }
  8139. else
  8140. {
  8141. tempIndex = gun_index;
  8142. }
  8143. for (int index = 0; index < GB_QUANTITY; index++)
  8144. {
  8145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8146. {
  8147. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage*100))/100.0;
  8148. }
  8149. }
  8150. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8151. }
  8152. else if(gunType[gun_index] == GUN_TYPE_DO)
  8153. {
  8154. tempIndex = gun_index;
  8155. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8156. {
  8157. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8158. {
  8159. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage*100))/100.0;
  8160. }
  8161. }
  8162. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8163. }
  8164. else
  8165. {
  8166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8167. {
  8168. tempIndex = 2;
  8169. }
  8170. else
  8171. {
  8172. tempIndex = gun_index;
  8173. }
  8174. for (int index = 0; index < AC_QUANTITY; index++)
  8175. {
  8176. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8177. {
  8178. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage*100))/100.0;
  8179. }
  8180. }
  8181. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8182. }
  8183. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  8184. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8185. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8186. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  8187. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  8188. }
  8189. //***********************************************(6)SOC******************************************************/
  8190. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8191. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8192. (dataType == ReadingContextEnumType_Trigger))
  8193. {
  8194. 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))
  8195. {
  8196. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  8197. {
  8198. tempIndex = ((gun_index==2) ? 1: 0);
  8199. }
  8200. else
  8201. {
  8202. tempIndex = gun_index;
  8203. }
  8204. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8205. {
  8206. //tempIndex = ((gun_index==2) ? 1: 0);
  8207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8208. {
  8209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8210. {
  8211. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  8212. }
  8213. }
  8214. }
  8215. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8216. {
  8217. //tempIndex = ((gun_index==2) ? 1: 0);
  8218. for (int index = 0; index < CCS_QUANTITY; index++)
  8219. {
  8220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8221. {
  8222. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  8223. }
  8224. }
  8225. }
  8226. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8227. {
  8228. //tempIndex = ((gun_index==2) ? 1: 0);
  8229. for (int index = 0; index < GB_QUANTITY; index++)
  8230. {
  8231. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8232. {
  8233. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  8234. }
  8235. }
  8236. }
  8237. else if(gunType[gun_index] == GUN_TYPE_DO)
  8238. {
  8239. //tempIndex = ((gun_index==2) ? 1: 0);
  8240. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8241. {
  8242. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8243. {
  8244. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  8245. }
  8246. }
  8247. }
  8248. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  8249. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  8250. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8251. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  8252. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  8253. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  8254. }
  8255. }
  8256. //********************************(7)Current.Import L2************************************************/
  8257. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8258. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8259. (dataType == ReadingContextEnumType_Trigger))
  8260. {
  8261. // Only for AC 3 phase
  8262. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8263. {
  8264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8265. {
  8266. tempIndex = 2;
  8267. }
  8268. else
  8269. {
  8270. tempIndex = gun_index;
  8271. }
  8272. for (int index = 0; index < AC_QUANTITY; index++)
  8273. {
  8274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8275. {
  8276. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2*100))/100.0;
  8277. }
  8278. }
  8279. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8280. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  8281. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8282. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8283. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  8284. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  8285. }
  8286. }
  8287. //********************************(8)Current.Import L3************************************************/
  8288. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8289. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8290. (dataType == ReadingContextEnumType_Trigger))
  8291. {
  8292. // Only for AC 3 phase
  8293. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8294. {
  8295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8296. {
  8297. tempIndex = 2;
  8298. }
  8299. else
  8300. {
  8301. tempIndex = gun_index;
  8302. }
  8303. for (int index = 0; index < AC_QUANTITY; index++)
  8304. {
  8305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8306. {
  8307. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3*100))/100.0;
  8308. }
  8309. }
  8310. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8311. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  8312. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8313. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8314. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  8315. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  8316. }
  8317. }
  8318. //***********************************************(9)VOLTAGE L2******************************************************/
  8319. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8320. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8321. (dataType == ReadingContextEnumType_Trigger))
  8322. {
  8323. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8324. {
  8325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8326. {
  8327. tempIndex = 2;
  8328. }
  8329. else
  8330. {
  8331. tempIndex = gun_index;
  8332. }
  8333. for (int index = 0; index < AC_QUANTITY; index++)
  8334. {
  8335. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8336. {
  8337. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2*100))/100.0;
  8338. }
  8339. }
  8340. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8341. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8342. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8343. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8344. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8345. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8346. }
  8347. }
  8348. //***********************************************(10)VOLTAGE L3******************************************************/
  8349. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8350. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8351. (dataType == ReadingContextEnumType_Trigger))
  8352. {
  8353. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8354. {
  8355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8356. {
  8357. tempIndex = 2;
  8358. }
  8359. else
  8360. {
  8361. tempIndex = gun_index;
  8362. }
  8363. for (int index = 0; index < AC_QUANTITY; index++)
  8364. {
  8365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8366. {
  8367. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3*100))/100.0;
  8368. }
  8369. }
  8370. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8371. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8372. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8373. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8374. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8375. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8376. }
  8377. }
  8378. //***********************************************(11)Current.Offered******************************************************/
  8379. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8380. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8381. (dataType == ReadingContextEnumType_Trigger))
  8382. {
  8383. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8384. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8385. {
  8386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8387. {
  8388. tempIndex = ((gun_index==2) ? 1: 0);
  8389. }
  8390. else
  8391. {
  8392. tempIndex = gun_index;
  8393. }
  8394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8395. {
  8396. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8397. {
  8398. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10);
  8399. }
  8400. } // END OF FOR
  8401. }
  8402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8403. {
  8404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8405. {
  8406. tempIndex = ((gun_index==2) ? 1: 0);
  8407. }
  8408. else
  8409. {
  8410. tempIndex = gun_index;
  8411. }
  8412. for (int index = 0; index < CCS_QUANTITY; index++)
  8413. {
  8414. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8415. {
  8416. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10);
  8417. }
  8418. }
  8419. }
  8420. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8421. {
  8422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8423. {
  8424. tempIndex = ((gun_index==2) ? 1: 0);
  8425. }
  8426. else
  8427. {
  8428. tempIndex = gun_index;
  8429. }
  8430. for (int index = 0; index < GB_QUANTITY; index++)
  8431. {
  8432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8433. {
  8434. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8435. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10);;
  8436. }
  8437. }
  8438. }
  8439. else if(gunType[gun_index] == GUN_TYPE_DO)
  8440. {
  8441. tempIndex = gun_index;
  8442. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8443. {
  8444. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8445. {
  8446. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8447. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10);;
  8448. }
  8449. }
  8450. }
  8451. else
  8452. {
  8453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8454. {
  8455. tempIndex = 2;
  8456. }
  8457. else
  8458. {
  8459. tempIndex = gun_index;
  8460. }
  8461. for (int index = 0; index < AC_QUANTITY; index++)
  8462. {
  8463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8464. {
  8465. uint16_t currentOffer;
  8466. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8467. {
  8468. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8469. }
  8470. else
  8471. {
  8472. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8473. }
  8474. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8475. }
  8476. }
  8477. }
  8478. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8479. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8480. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8481. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8482. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8483. }
  8484. //***********************************************(12)Power.Offered******************************************************/
  8485. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8486. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8487. (dataType == ReadingContextEnumType_Trigger))
  8488. {
  8489. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8490. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8491. {
  8492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8493. {
  8494. tempIndex = ((gun_index==2) ? 1: 0);
  8495. }
  8496. else
  8497. {
  8498. tempIndex = gun_index;
  8499. }
  8500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8501. {
  8502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8503. {
  8504. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100);
  8505. }
  8506. } // END OF FOR
  8507. }
  8508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8509. {
  8510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8511. {
  8512. tempIndex = ((gun_index==2) ? 1: 0);
  8513. }
  8514. else
  8515. {
  8516. tempIndex = gun_index;
  8517. }
  8518. for (int index = 0; index < CCS_QUANTITY; index++)
  8519. {
  8520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8521. {
  8522. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100);
  8523. }
  8524. }
  8525. }
  8526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8527. {
  8528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8529. {
  8530. tempIndex = ((gun_index==2) ? 1: 0);
  8531. }
  8532. else
  8533. {
  8534. tempIndex = gun_index;
  8535. }
  8536. for (int index = 0; index < GB_QUANTITY; index++)
  8537. {
  8538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8539. {
  8540. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8541. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100);
  8542. }
  8543. }
  8544. }
  8545. else if(gunType[gun_index] == GUN_TYPE_DO)
  8546. {
  8547. tempIndex = gun_index;
  8548. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8549. {
  8550. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8551. {
  8552. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  8553. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100);
  8554. }
  8555. }
  8556. }
  8557. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8558. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8559. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8560. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8561. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8562. }
  8563. // Message create ====================================================================================================
  8564. random_uuid(guid);
  8565. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8566. {
  8567. json_object *meterValue = json_object_new_object();
  8568. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8569. {
  8570. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8571. {
  8572. json_object *sampledValue = json_object_new_object();
  8573. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8574. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8575. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8576. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8577. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8578. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8579. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8580. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8581. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8582. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8583. {
  8584. json_object *unitOfMeasure = json_object_new_object();
  8585. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8586. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8587. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8588. }
  8589. json_object_array_add(sampledValues, sampledValue);
  8590. }
  8591. }
  8592. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8593. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8594. json_object_array_add(meterValues, meterValue);
  8595. idxMeter++;
  8596. }
  8597. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8598. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8599. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8600. ,MESSAGE_TYPE_CALL
  8601. ,guid
  8602. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8603. json_object_put(MeterValueReq);
  8604. if((dataType != ReadingContextEnumType_Trigger) &&
  8605. (dataType != ReadingContextEnumType_Sample_Clock))
  8606. {
  8607. // Transaction meter value send by TransactionEvent message
  8608. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8609. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8610. result = PASS;
  8611. }
  8612. else
  8613. {
  8614. // Put request guid to hash map
  8615. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8616. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8617. {
  8618. result = PASS;
  8619. }
  8620. if((dataType != ReadingContextEnumType_Trigger) &&
  8621. (dataType != ReadingContextEnumType_Sample_Clock))
  8622. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8623. else
  8624. {
  8625. if(FirstHeartBeat)
  8626. LWS_Send(queuedata);
  8627. }
  8628. }
  8629. return result;
  8630. }
  8631. int sendNotifyChargingLimitRequest(int gun_index)
  8632. {
  8633. mtrace();
  8634. int result = FAIL;
  8635. char message[4096]={0};
  8636. char guid[37]={0};
  8637. char tempdata[128]={0};
  8638. json_object *NotifyChargingLimit = json_object_new_object();
  8639. json_object *chargingLimit = json_object_new_object();
  8640. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8641. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8642. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8643. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8644. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8645. random_uuid(guid);
  8646. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8647. json_object_put(NotifyChargingLimit);
  8648. LWS_Send(message);
  8649. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8650. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8651. {
  8652. result = PASS;
  8653. }
  8654. return result;
  8655. }
  8656. int sendNotifyCustomerInformationRequest()
  8657. {
  8658. mtrace();
  8659. int result = FAIL;
  8660. char message[4096]={0};
  8661. char guid[37]={0};
  8662. char tempdata[128]={0};
  8663. json_object *NotifyCustomerInformation = json_object_new_object();
  8664. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8665. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8666. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8667. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8668. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8669. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8670. random_uuid(guid);
  8671. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8672. json_object_put(NotifyCustomerInformation);
  8673. LWS_Send(message);
  8674. sprintf(tempdata, "NotifyCustomerInformation,0");
  8675. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8676. {
  8677. result = PASS;
  8678. }
  8679. return result;
  8680. }
  8681. int sendNotifyDisplayMessagesRequest()
  8682. {
  8683. mtrace();
  8684. int result = FAIL;
  8685. char message[4096]={0};
  8686. char guid[37]={0};
  8687. char tempdata[128]={0};
  8688. json_object *NotifyDisplayMessages = json_object_new_object();
  8689. json_object *messageInfos = json_object_new_array();
  8690. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8691. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8692. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8693. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8694. {
  8695. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8696. {
  8697. json_object *messageInfo = json_object_new_object();
  8698. json_object *message = json_object_new_object();
  8699. json_object *display = json_object_new_object();
  8700. json_object *evse = json_object_new_object();
  8701. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8702. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8703. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8704. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8705. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8706. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8707. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8708. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8709. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8710. json_object_object_add(messageInfo, "message", message);
  8711. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8712. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8713. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8714. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8715. json_object_object_add(display, "evse",evse);
  8716. json_object_object_add(messageInfo, "evse", display);
  8717. json_object_array_add(messageInfos, messageInfo);
  8718. }
  8719. }
  8720. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8721. random_uuid(guid);
  8722. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8723. json_object_put(NotifyDisplayMessages);
  8724. LWS_Send(message);
  8725. sprintf(tempdata, "NotifyDisplayMessages,0");
  8726. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8727. {
  8728. result = PASS;
  8729. }
  8730. return result;
  8731. }
  8732. int sendNotifyEVChargingNeedsRequest(int gun_index)
  8733. {
  8734. mtrace();
  8735. int result = FAIL;
  8736. char message[4096]={0};
  8737. char guid[37]={0};
  8738. char tempdata[128]={0};
  8739. json_object *NotifyEVChargingNeeds = json_object_new_object();
  8740. json_object *chargingNeeds = json_object_new_object();
  8741. json_object *acChargingParameters = json_object_new_object();
  8742. json_object *dcChargingParameters = json_object_new_object();
  8743. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8744. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8745. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8746. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8747. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8748. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8749. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8750. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8751. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8752. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8753. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8754. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8755. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8756. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8757. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8758. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8759. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8760. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8761. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8762. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8763. random_uuid(guid);
  8764. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8765. json_object_put(NotifyEVChargingNeeds);
  8766. LWS_Send(message);
  8767. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8768. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8769. {
  8770. result = PASS;
  8771. }
  8772. return result;
  8773. }
  8774. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8775. {
  8776. mtrace();
  8777. int result = FAIL;
  8778. char message[4096]={0};
  8779. char guid[37]={0};
  8780. char tempdata[128]={0};
  8781. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8782. json_object *chargingSchedule = json_object_new_object();
  8783. json_object *periods = json_object_new_array();
  8784. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8785. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8786. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8787. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8788. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8789. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8790. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8791. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8792. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8793. {
  8794. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8795. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8796. {
  8797. json_object *Period = json_object_new_object();
  8798. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8799. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8800. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8801. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8802. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8803. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8804. json_object_array_add(periods, Period);
  8805. }
  8806. }
  8807. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8808. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8809. random_uuid(guid);
  8810. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8811. json_object_put(NotifyEVChargingSchedule);
  8812. LWS_Send(message);
  8813. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8814. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8815. {
  8816. result = PASS;
  8817. }
  8818. return result;
  8819. }
  8820. int sendNotifyEventRequest()
  8821. {
  8822. mtrace();
  8823. int result = FAIL;
  8824. char message[4096]={0};
  8825. char guid[37]={0};
  8826. char tempdata[128]={0};
  8827. json_object *NotifyEvent = json_object_new_object();
  8828. json_object *eventDatas = json_object_new_array();
  8829. DEBUG_INFO("sendNotifyEventRequest...\n");
  8830. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8831. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8832. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8833. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8834. {
  8835. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8836. {
  8837. json_object *eventData = json_object_new_object();
  8838. json_object *component = json_object_new_object();
  8839. json_object *evse = json_object_new_object();
  8840. json_object *variable = json_object_new_object();
  8841. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8842. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8843. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8844. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8845. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8846. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8847. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8848. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8849. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8850. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8851. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8852. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8853. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8854. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8855. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  8856. json_object_object_add(component, "evse",evse);
  8857. json_object_object_add(eventData, "component", component);
  8858. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  8859. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  8860. json_object_object_add(eventData, "variable", variable);
  8861. json_object_array_add(eventDatas, eventData);
  8862. }
  8863. }
  8864. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  8865. random_uuid(guid);
  8866. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  8867. json_object_put(NotifyEvent);
  8868. LWS_Send(message);
  8869. sprintf(tempdata, "NotifyEvent,0");
  8870. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8871. {
  8872. result = PASS;
  8873. }
  8874. return result;
  8875. }
  8876. int sendNotifyMonitoringReportRequest()
  8877. {
  8878. mtrace();
  8879. int result = FAIL;
  8880. char message[4096]={0};
  8881. char guid[37]={0};
  8882. char tempdata[128]={0};
  8883. json_object *NotifyMonitoringReport = json_object_new_object();
  8884. json_object *monitors = json_object_new_array();
  8885. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  8886. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  8887. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  8888. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  8889. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  8890. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  8891. {
  8892. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  8893. {
  8894. json_object *monitor = json_object_new_object();
  8895. json_object *component = json_object_new_object();
  8896. json_object *evse = json_object_new_object();
  8897. json_object *variable = json_object_new_object();
  8898. json_object *variableMonitorings = json_object_new_array();
  8899. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  8900. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  8901. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  8902. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  8903. json_object_object_add(component, "evse",evse);
  8904. json_object_object_add(monitor, "component", component);
  8905. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  8906. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  8907. json_object_object_add(monitor, "variable", variable);
  8908. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  8909. {
  8910. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  8911. {
  8912. json_object *variableMonitoring = json_object_new_object();
  8913. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  8914. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  8915. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  8916. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  8917. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  8918. json_object_array_add(variableMonitorings, variableMonitoring);
  8919. }
  8920. }
  8921. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  8922. json_object_array_add(monitors, monitor);
  8923. }
  8924. }
  8925. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  8926. random_uuid(guid);
  8927. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8928. json_object_put(NotifyMonitoringReport);
  8929. LWS_Send(message);
  8930. sprintf(tempdata, "NotifyMonitoringReport,0");
  8931. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8932. {
  8933. result = PASS;
  8934. }
  8935. return result;
  8936. }
  8937. int sendNotifyReportRequest()
  8938. {
  8939. mtrace();
  8940. int result = FAIL;
  8941. char message[4096]={0};
  8942. char guid[37]={0};
  8943. char tempdata[128]={0};
  8944. json_object *NotifyReport = json_object_new_object();
  8945. json_object *reportDatas = json_object_new_array();
  8946. DEBUG_INFO("sendNotifyReportRequest...\n");
  8947. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  8948. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  8949. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  8950. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  8951. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  8952. {
  8953. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  8954. {
  8955. json_object *reportData = json_object_new_object();
  8956. json_object *component = json_object_new_object();
  8957. json_object *evse = json_object_new_object();
  8958. json_object *variable = json_object_new_object();
  8959. json_object *variableAttributes = json_object_new_array();
  8960. json_object *variableCharacteristics = json_object_new_object();
  8961. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  8962. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  8963. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  8964. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  8965. json_object_object_add(component, "evse",evse);
  8966. json_object_object_add(reportData, "component", component);
  8967. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  8968. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  8969. json_object_object_add(reportData, "variable",variable);
  8970. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  8971. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  8972. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  8973. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  8974. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  8975. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  8976. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  8977. {
  8978. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  8979. {
  8980. json_object *variableAttribute = json_object_new_object();
  8981. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  8982. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  8983. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  8984. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  8985. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  8986. json_object_array_add(variableAttributes, variableAttribute);
  8987. }
  8988. }
  8989. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  8990. json_object_array_add(reportDatas, reportData);
  8991. }
  8992. }
  8993. json_object_object_add(NotifyReport, "reportData", reportDatas);
  8994. random_uuid(guid);
  8995. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  8996. json_object_put(NotifyReport);
  8997. LWS_SendNow(message);
  8998. sprintf(tempdata, "NotifyReport,0");
  8999. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9000. {
  9001. result = PASS;
  9002. }
  9003. return result;
  9004. }
  9005. int sendPublishFirmwareStatusNotificationRequest()
  9006. {
  9007. mtrace();
  9008. int result = FAIL;
  9009. char message[4096]={0};
  9010. char guid[37]={0};
  9011. char tempdata[128]={0};
  9012. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  9013. json_object *locations = json_object_new_array();
  9014. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  9015. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  9016. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  9017. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  9018. {
  9019. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  9020. }
  9021. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  9022. random_uuid(guid);
  9023. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  9024. json_object_put(PublishFirmwareStatusNotification);
  9025. LWS_Send(message);
  9026. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  9027. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9028. {
  9029. result = PASS;
  9030. }
  9031. return result;
  9032. }
  9033. int sendReportChargingProfilesRequest(int gun_index)
  9034. {
  9035. mtrace();
  9036. int result = FAIL;
  9037. char message[4096]={0};
  9038. char guid[37]={0};
  9039. char tempdata[128]={0};
  9040. json_object *ReportChargingProfiles = json_object_new_object();
  9041. json_object *chargingProfiles = json_object_new_array();
  9042. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  9043. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  9044. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  9045. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  9046. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  9047. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  9048. {
  9049. json_object *chargingProfile = json_object_new_object();
  9050. json_object *chargingSchedules = json_object_new_array();
  9051. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  9052. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  9053. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  9054. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  9055. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  9056. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  9057. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  9058. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  9059. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  9060. {
  9061. json_object *chargingSchedule = json_object_new_object();
  9062. json_object *chargingSchedulePeriods = json_object_new_array();
  9063. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  9064. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  9065. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  9066. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  9067. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  9068. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  9069. {
  9070. json_object *chargingSchedulePeriod = json_object_new_object();
  9071. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  9072. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  9073. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  9074. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  9075. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  9076. }
  9077. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  9078. json_object_array_add(chargingSchedules, chargingSchedule);
  9079. }
  9080. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  9081. json_object_array_add(chargingProfiles, chargingProfile);
  9082. }
  9083. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  9084. random_uuid(guid);
  9085. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  9086. json_object_put(ReportChargingProfiles);
  9087. LWS_Send(message);
  9088. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  9089. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9090. {
  9091. result = PASS;
  9092. }
  9093. return result;
  9094. }
  9095. int sendReservationStatusUpdateRequest(int gun_index)
  9096. {
  9097. mtrace();
  9098. int result = FAIL;
  9099. char message[4096]={0};
  9100. char guid[37]={0};
  9101. char tempdata[128]={0};
  9102. json_object *ReservationStatusUpdate = json_object_new_object();
  9103. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  9104. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  9105. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  9106. random_uuid(guid);
  9107. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  9108. json_object_put(ReservationStatusUpdate);
  9109. LWS_Send(message);
  9110. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  9111. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9112. {
  9113. result = PASS;
  9114. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  9115. }
  9116. return result;
  9117. }
  9118. int sendSecurityEventNotificationRequest()
  9119. {
  9120. mtrace();
  9121. int result = FAIL;
  9122. char message[4096]={0};
  9123. char guid[37]={0};
  9124. char tempdata[128]={0};
  9125. struct timeval tmnow;
  9126. struct tm *tm;
  9127. char buf[28];//, usec_buf[6];
  9128. json_object *SecurityEventNotification = json_object_new_object();
  9129. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  9130. DB_getSecurityEventType();
  9131. gettimeofday(&tmnow, NULL);
  9132. time_t t;
  9133. t = time(NULL);
  9134. /*UTC time and date*/
  9135. tm = gmtime(&t);
  9136. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9137. #if 0 // remove temporally
  9138. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9139. strcat(buf,".");
  9140. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9141. strcat(buf,usec_buf);
  9142. #endif
  9143. printf("%s",buf);
  9144. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  9145. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  9146. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  9147. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  9148. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  9149. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  9150. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  9151. random_uuid(guid);
  9152. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  9153. json_object_put(SecurityEventNotification);
  9154. LWS_Send(message);
  9155. sprintf(tempdata, "SecurityEventNotification,0");
  9156. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9157. {
  9158. result = PASS;
  9159. }
  9160. return result;
  9161. }
  9162. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  9163. {
  9164. mtrace();
  9165. int result = FAIL;
  9166. char message[4096]={0};
  9167. char guid[37]={0};
  9168. char tempdata[128]={0};
  9169. json_object *SignCertificate = json_object_new_object();
  9170. DEBUG_INFO("sendSignCertificateRequest...\n");
  9171. // Read csr file content
  9172. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  9173. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  9174. char *line = NULL;
  9175. size_t len = 0;
  9176. while(getline(&line, &len, fp) != -1)
  9177. {
  9178. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  9179. {
  9180. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  9181. }
  9182. }
  9183. fclose(fp);
  9184. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  9185. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  9186. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  9187. random_uuid(guid);
  9188. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  9189. json_object_put(SignCertificate);
  9190. LWS_Send(message);
  9191. sprintf(tempdata, "SignCertificate,0");
  9192. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9193. {
  9194. result = PASS;
  9195. }
  9196. return result;
  9197. }
  9198. int sendStatusNotificationRequest(int gun_index)
  9199. {
  9200. mtrace();
  9201. int result = FAIL;
  9202. char message[600]={0};
  9203. char guid[37];
  9204. int currentStatus = 0;
  9205. struct timeval tmnow;
  9206. struct tm *tm;
  9207. char buf[28];//, usec_buf[6];
  9208. char tempdata[65]={0};
  9209. int tempIndex = 0;
  9210. uint8_t isStateChanged = TRUE;
  9211. DEBUG_INFO("sendStatusNotificationRequest...\n");
  9212. gettimeofday(&tmnow, NULL);
  9213. time_t t;
  9214. t = time(NULL);
  9215. /*UTC time and date*/
  9216. tm = gmtime(&t);
  9217. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9218. #if 0 // remove temporally
  9219. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9220. strcat(buf,".");
  9221. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9222. strcat(buf,usec_buf);
  9223. #endif
  9224. printf("%s",buf);
  9225. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  9226. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  9227. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  9228. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  9229. /*
  9230. enum _SYSTEM_STATUS
  9231. {
  9232. S_BOOTING = 0,
  9233. S_IDLE, = 1
  9234. S_AUTHORIZING, =2
  9235. S_REASSIGN_CHECK, =3
  9236. S_REASSIGN, =4
  9237. S_PRECHARGE, =5
  9238. S_PREPARING_FOR_EV, =6
  9239. S_PREPARING_FOR_EVSE, =7
  9240. S_CHARGING, =8
  9241. S_TERMINATING, =9
  9242. S_COMPLETE, =10
  9243. S_ALARM, =11
  9244. S_FAULT =12
  9245. }
  9246. */
  9247. //check Transaction active
  9248. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  9249. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9250. {
  9251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9252. {
  9253. tempIndex = ((gun_index==2) ? 1: 0);
  9254. }
  9255. else
  9256. {
  9257. tempIndex = gun_index;
  9258. }
  9259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9260. {
  9261. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9262. {
  9263. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9264. {
  9265. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9266. {
  9267. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9268. }
  9269. else
  9270. {
  9271. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9272. }
  9273. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9274. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9275. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9276. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9277. }
  9278. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9279. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9280. ) //S_PRECHARGE
  9281. {
  9282. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9283. }
  9284. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9285. {
  9286. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9287. }
  9288. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9289. {
  9290. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9291. }
  9292. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9293. {
  9294. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9295. }
  9296. 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
  9297. {
  9298. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9299. }
  9300. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9301. {
  9302. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9303. }
  9304. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9305. {
  9306. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9307. }
  9308. } //end of the same index
  9309. }//end of for CHAdeMO_QUANTITY
  9310. }
  9311. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9312. {
  9313. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9314. {
  9315. tempIndex = ((gun_index==2) ? 1: 0);
  9316. }
  9317. else
  9318. {
  9319. tempIndex = gun_index;
  9320. }
  9321. for (int index = 0; index < CCS_QUANTITY; index++)
  9322. {
  9323. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9324. {
  9325. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9326. {
  9327. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9328. {
  9329. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9330. }
  9331. else
  9332. {
  9333. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9334. }
  9335. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9336. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9337. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9338. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9339. }
  9340. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9341. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9342. ) //S_PRECHARGE
  9343. {
  9344. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9345. }
  9346. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9347. {
  9348. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9349. }
  9350. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9351. {
  9352. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9353. }
  9354. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9355. {
  9356. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9357. }
  9358. 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
  9359. {
  9360. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9361. }
  9362. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9363. {
  9364. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9365. }
  9366. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9367. {
  9368. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9369. }
  9370. } //end of the same index
  9371. } // end of for CCS_QUANTITY
  9372. }
  9373. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9374. {
  9375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9376. {
  9377. tempIndex = ((gun_index==2) ? 1: 0);
  9378. }
  9379. else
  9380. {
  9381. tempIndex = gun_index;
  9382. }
  9383. for (int index = 0; index < GB_QUANTITY; index++)
  9384. {
  9385. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9386. {
  9387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9388. {
  9389. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9390. {
  9391. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9392. }
  9393. else
  9394. {
  9395. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9396. }
  9397. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9398. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9399. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9400. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9401. }
  9402. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9403. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9404. ) //S_PRECHARGE
  9405. {
  9406. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9407. }
  9408. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9409. {
  9410. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9411. }
  9412. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9413. {
  9414. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9415. }
  9416. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9417. {
  9418. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9419. }
  9420. 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
  9421. {
  9422. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9423. }
  9424. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9425. {
  9426. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9427. }
  9428. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9429. {
  9430. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9431. }
  9432. } //end of the same index
  9433. } // end of for GB_QUANTITY
  9434. }
  9435. else if(gunType[gun_index] == GUN_TYPE_DO)
  9436. {
  9437. tempIndex = gun_index;
  9438. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9439. {
  9440. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9441. {
  9442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9443. {
  9444. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9445. {
  9446. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9447. }
  9448. else
  9449. {
  9450. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9451. }
  9452. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9453. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9454. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9455. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9456. }
  9457. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9458. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9459. ) //S_PRECHARGE
  9460. {
  9461. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9462. }
  9463. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9464. {
  9465. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9466. }
  9467. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9468. {
  9469. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9470. }
  9471. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9472. {
  9473. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9474. }
  9475. 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
  9476. {
  9477. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9478. }
  9479. 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
  9480. {
  9481. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9482. }
  9483. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9484. {
  9485. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9486. }
  9487. } //end of the same index
  9488. }
  9489. }
  9490. else
  9491. {
  9492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9493. {
  9494. tempIndex = 2;
  9495. }
  9496. else
  9497. {
  9498. tempIndex = gun_index;
  9499. }
  9500. for (int index = 0; index < AC_QUANTITY; index++)
  9501. {
  9502. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9503. {
  9504. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9505. {
  9506. 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))
  9507. {
  9508. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9509. }
  9510. else
  9511. {
  9512. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9513. }
  9514. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9515. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9516. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9517. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9518. }
  9519. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9520. {
  9521. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9522. }
  9523. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9524. {
  9525. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9526. }
  9527. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9528. {
  9529. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9530. }
  9531. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9532. {
  9533. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9534. }
  9535. 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
  9536. {
  9537. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9538. }
  9539. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9540. {
  9541. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9542. }
  9543. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9544. {
  9545. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9546. }
  9547. }//end of the same index
  9548. }//end of for AC_QUANTITY
  9549. }
  9550. //it's option
  9551. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9552. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9553. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") != 0))
  9554. {
  9555. isStateChanged = FALSE;
  9556. }
  9557. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9558. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9559. random_uuid(guid);
  9560. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9561. , MESSAGE_TYPE_CALL
  9562. , guid
  9563. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9564. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9565. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9566. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9567. if((server_sign == TRUE) && isStateChanged)
  9568. {
  9569. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9570. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9571. LWS_Send(message);
  9572. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9573. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9574. {
  9575. result = PASS;
  9576. }
  9577. }
  9578. else
  9579. {
  9580. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9581. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9582. result = PASS;
  9583. }
  9584. return result;
  9585. }
  9586. int sendTransactionEventRequest(int gun_index)
  9587. {
  9588. mtrace();
  9589. int result = FAIL;
  9590. char message[1024*20]={0};
  9591. char guid[37]={0};
  9592. char tempdata[128]={0};
  9593. uint8_t tempIndex;
  9594. json_object *TransactionEvent = json_object_new_object();
  9595. json_object *transactionInfo = json_object_new_object();
  9596. json_object *idToken = json_object_new_object();
  9597. json_object *evse = json_object_new_object();
  9598. json_object *meterValues = json_object_new_array();
  9599. char TempStopTransaction[256];
  9600. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9601. DEBUG_INFO("sendTransactionEventRequest...\n");
  9602. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9603. {
  9604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9605. {
  9606. tempIndex = ((gun_index==2) ? 1: 0);
  9607. }
  9608. else
  9609. {
  9610. tempIndex = gun_index;
  9611. }
  9612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9613. {
  9614. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9615. {
  9616. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9617. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9618. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9619. else
  9620. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9621. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9622. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9623. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9624. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9625. {
  9626. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9627. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9628. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9629. {
  9630. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9631. }
  9632. else
  9633. {
  9634. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9635. }
  9636. }
  9637. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9638. {
  9639. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9640. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9641. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9642. }
  9643. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9644. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9645. ) //S_PRECHARGE
  9646. {
  9647. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9648. {
  9649. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9650. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9651. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9652. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9653. }
  9654. else
  9655. {
  9656. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9657. }
  9658. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9659. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9660. }
  9661. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9662. {
  9663. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9664. {
  9665. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9666. {
  9667. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9668. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9669. }
  9670. else
  9671. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9672. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9673. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9674. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9675. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9676. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9677. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  9678. }
  9679. else
  9680. {
  9681. storeTempStopTransaction(gun_index);
  9682. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9683. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9684. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9685. }
  9686. }
  9687. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9688. {
  9689. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9690. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9691. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9692. if((access(TempStopTransaction,F_OK))!=-1)
  9693. {
  9694. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9695. }
  9696. }
  9697. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9698. {
  9699. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9700. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9701. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9702. }
  9703. 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
  9704. {
  9705. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9706. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9707. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9708. }
  9709. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9710. {
  9711. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9712. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9713. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9714. }
  9715. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9716. {
  9717. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9718. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9719. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9720. }
  9721. } //end of the same index
  9722. }//end of for CHAdeMO_QUANTITY
  9723. }
  9724. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9725. {
  9726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9727. {
  9728. tempIndex = ((gun_index==2) ? 1: 0);
  9729. }
  9730. else
  9731. {
  9732. tempIndex = gun_index;
  9733. }
  9734. for (int index = 0; index < CCS_QUANTITY; index++)
  9735. {
  9736. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9737. {
  9738. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9739. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9740. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9741. else
  9742. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9743. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9744. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9745. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9746. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9747. {
  9748. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9749. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9750. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9751. {
  9752. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9753. }
  9754. else
  9755. {
  9756. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9757. }
  9758. }
  9759. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9760. {
  9761. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9762. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9763. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9764. }
  9765. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9766. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9767. ) //S_PRECHARGE
  9768. {
  9769. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9770. {
  9771. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9772. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9773. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9774. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9775. }
  9776. else
  9777. {
  9778. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9779. }
  9780. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9781. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9782. }
  9783. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9784. {
  9785. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9786. {
  9787. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9788. {
  9789. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9790. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9791. }
  9792. else
  9793. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9794. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9795. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9796. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9797. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9798. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9799. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  9800. }
  9801. else
  9802. {
  9803. storeTempStopTransaction(gun_index);
  9804. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9805. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9806. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9807. }
  9808. }
  9809. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9810. {
  9811. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9812. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9813. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9814. if((access(TempStopTransaction,F_OK))!=-1)
  9815. {
  9816. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9817. }
  9818. }
  9819. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9820. {
  9821. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9822. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9823. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9824. }
  9825. 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
  9826. {
  9827. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9828. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9829. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9830. }
  9831. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9832. {
  9833. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9834. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9835. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9836. }
  9837. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  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_SuspendedEVSE]);
  9841. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9842. }
  9843. } //end of the same index
  9844. } // end of for CCS_QUANTITY
  9845. }
  9846. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9847. {
  9848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9849. {
  9850. tempIndex = ((gun_index==2) ? 1: 0);
  9851. }
  9852. else
  9853. {
  9854. tempIndex = gun_index;
  9855. }
  9856. for (int index = 0; index < GB_QUANTITY; index++)
  9857. {
  9858. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9859. {
  9860. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9861. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9862. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9863. else
  9864. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9865. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9866. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9867. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9869. {
  9870. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9871. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9872. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9873. {
  9874. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9875. }
  9876. else
  9877. {
  9878. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9879. }
  9880. }
  9881. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9882. {
  9883. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9884. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9885. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9886. }
  9887. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9888. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9889. ) //S_PRECHARGE
  9890. {
  9891. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9892. {
  9893. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9894. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9895. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9896. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9897. }
  9898. else
  9899. {
  9900. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9901. }
  9902. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9903. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9904. }
  9905. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9906. {
  9907. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9908. {
  9909. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  9910. {
  9911. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9912. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9913. }
  9914. else
  9915. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9916. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9917. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9918. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9919. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9920. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9921. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  9922. }
  9923. else
  9924. {
  9925. storeTempStopTransaction(gun_index);
  9926. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9927. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9928. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9929. }
  9930. }
  9931. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9932. {
  9933. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9934. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9935. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9936. if((access(TempStopTransaction,F_OK))!=-1)
  9937. {
  9938. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9939. }
  9940. }
  9941. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9942. {
  9943. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9944. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9945. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9946. }
  9947. 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
  9948. {
  9949. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9950. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9951. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9952. }
  9953. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9954. {
  9955. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9956. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9957. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9958. }
  9959. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  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_SuspendedEVSE]);
  9963. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9964. }
  9965. } //end of the same index
  9966. } // end of for GB_QUANTITY
  9967. }
  9968. else if(gunType[gun_index] == GUN_TYPE_DO)
  9969. {
  9970. tempIndex = gun_index;
  9971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9972. {
  9973. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9974. {
  9975. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9976. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9977. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9978. else
  9979. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9980. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9981. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9982. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9983. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9984. {
  9985. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9986. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9987. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9988. {
  9989. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9990. }
  9991. else
  9992. {
  9993. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9994. }
  9995. }
  9996. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9997. {
  9998. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9999. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10000. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10001. }
  10002. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10003. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10004. ) //S_PRECHARGE
  10005. {
  10006. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10007. {
  10008. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10009. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10010. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10011. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10012. }
  10013. else
  10014. {
  10015. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10016. }
  10017. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10018. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10019. }
  10020. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10021. {
  10022. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10023. {
  10024. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  10025. {
  10026. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10027. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10028. }
  10029. else
  10030. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10031. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10032. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10033. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10034. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10035. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10036. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  10037. }
  10038. else
  10039. {
  10040. storeTempStopTransaction(gun_index);
  10041. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10042. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10043. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10044. }
  10045. }
  10046. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10047. {
  10048. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10049. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10050. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10051. if((access(TempStopTransaction,F_OK))!=-1)
  10052. {
  10053. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10054. }
  10055. }
  10056. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10057. {
  10058. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10059. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10060. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10061. }
  10062. 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
  10063. {
  10064. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10065. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10066. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10067. }
  10068. 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
  10069. {
  10070. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10071. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10072. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10073. }
  10074. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10075. {
  10076. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10077. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10078. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10079. }
  10080. } //end of the same index
  10081. }
  10082. }
  10083. else
  10084. {
  10085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10086. {
  10087. tempIndex = 2;
  10088. }
  10089. else
  10090. {
  10091. tempIndex = gun_index;
  10092. }
  10093. for (int index = 0; index < AC_QUANTITY; index++)
  10094. {
  10095. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10096. {
  10097. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10098. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10099. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10100. else
  10101. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10102. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10103. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10104. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  10105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  10106. {
  10107. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10108. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10109. 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))
  10110. {
  10111. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10112. }
  10113. else
  10114. {
  10115. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10116. }
  10117. }
  10118. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10119. {
  10120. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10121. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10122. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10123. }
  10124. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10125. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10126. ) //S_PRECHARGE
  10127. {
  10128. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10129. {
  10130. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10131. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10132. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10133. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10134. }
  10135. else
  10136. {
  10137. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10138. }
  10139. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10140. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10141. }
  10142. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10143. {
  10144. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10145. {
  10146. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10147. {
  10148. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10149. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10150. }
  10151. else
  10152. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10153. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10154. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10155. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10156. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10157. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10158. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  10159. }
  10160. else
  10161. {
  10162. storeTempStopTransaction(gun_index);
  10163. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10164. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10165. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10166. }
  10167. }
  10168. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10169. {
  10170. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10171. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10172. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10173. if((access(TempStopTransaction,F_OK))!=-1)
  10174. {
  10175. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10176. }
  10177. }
  10178. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10179. {
  10180. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10181. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10182. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10183. }
  10184. 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
  10185. {
  10186. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10187. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10188. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10189. }
  10190. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10191. {
  10192. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10193. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10194. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10195. }
  10196. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10197. {
  10198. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10199. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10200. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10201. }
  10202. }//end of the same index
  10203. }//end of for AC_QUANTITY
  10204. }
  10205. // Check if this message is triggered by TriggerMessage
  10206. if(cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  10207. {
  10208. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10209. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Trigger]);
  10210. }
  10211. // Message
  10212. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  10213. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  10214. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  10215. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  10216. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  10217. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  10218. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  10219. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  10220. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  10221. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  10222. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  10223. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  10224. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  10225. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  10226. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  10227. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  10228. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  10229. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  10230. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10231. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  10232. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  10233. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  10234. {
  10235. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  10236. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  10237. json_object_object_add(TransactionEvent, "idToken", idToken);
  10238. }
  10239. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  10240. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  10241. json_object_object_add(TransactionEvent, "evse", evse);
  10242. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  10243. {
  10244. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  10245. {
  10246. json_object *meterValue = json_object_new_object();
  10247. json_object *sampledValues = json_object_new_array();
  10248. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  10249. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  10250. {
  10251. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  10252. ((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)))
  10253. {
  10254. 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)) ||
  10255. (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  10256. {
  10257. json_object *sampledValue = json_object_new_object();
  10258. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  10259. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  10260. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  10261. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  10262. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  10263. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  10264. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  10265. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  10266. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  10267. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  10268. {
  10269. json_object *unitOfMeasure = json_object_new_object();
  10270. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  10271. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  10272. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  10273. }
  10274. json_object_array_add(sampledValues, sampledValue);
  10275. }
  10276. }
  10277. }
  10278. json_object_object_add(meterValue, "sampledValue", sampledValues);
  10279. json_object_array_add(meterValues, meterValue);
  10280. }
  10281. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10282. }
  10283. random_uuid(guid);
  10284. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  10285. json_object_put(TransactionEvent);
  10286. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  10287. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  10288. {
  10289. result = PASS;
  10290. }
  10291. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  10292. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10293. OCPP_insert_transaction_msg(YES, message);
  10294. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10295. {
  10296. OCPP_insert_transaction_msg(NO, message);
  10297. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  10298. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  10299. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  10300. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  10301. }
  10302. return result;
  10303. }
  10304. //==========================================
  10305. // send confirm routine
  10306. //==========================================
  10307. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  10308. {
  10309. mtrace();
  10310. int result = FAIL;
  10311. char message[4096]={0};
  10312. json_object *CancelReservation = json_object_new_object();
  10313. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  10314. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  10315. sprintf(message,"[%d,\"%s\",%s]"
  10316. ,MESSAGE_TYPE_CALLRESULT
  10317. ,uuid
  10318. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  10319. json_object_put(CancelReservation);
  10320. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  10321. LWS_Send(message);
  10322. result = TRUE;
  10323. return result;
  10324. }
  10325. int sendCertificateSignedConfirmation(char *uuid)
  10326. {
  10327. mtrace();
  10328. int result = FAIL;
  10329. char message[4096]={0};
  10330. json_object *CertificateSigned = json_object_new_object();
  10331. json_object *statusInfo = json_object_new_object();
  10332. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  10333. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10334. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10335. {
  10336. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10337. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10338. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10339. }
  10340. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10341. sprintf(message,"[%d,\"%s\",%s]"
  10342. ,MESSAGE_TYPE_CALLRESULT
  10343. ,uuid
  10344. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10345. json_object_put(CertificateSigned);
  10346. LWS_Send(message);
  10347. result = TRUE;
  10348. return result;
  10349. }
  10350. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10351. {
  10352. mtrace();
  10353. int result = FAIL;
  10354. char message[4096]={0};
  10355. json_object *ChangeAvailability = json_object_new_object();
  10356. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10357. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10358. sprintf(message,"[%d,\"%s\",%s]"
  10359. ,MESSAGE_TYPE_CALLRESULT
  10360. ,uuid
  10361. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10362. json_object_put(ChangeAvailability);
  10363. LWS_Send(message);
  10364. result = TRUE;
  10365. return result;
  10366. }
  10367. int sendClearCacheConfirmation(char *uuid)
  10368. {
  10369. mtrace();
  10370. int result = FAIL;
  10371. char message[4096]={0};
  10372. json_object *ClearCache = json_object_new_object();
  10373. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10374. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10375. sprintf(message,"[%d,\"%s\",%s]"
  10376. ,MESSAGE_TYPE_CALLRESULT
  10377. ,uuid
  10378. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10379. json_object_put(ClearCache);
  10380. LWS_Send(message);
  10381. result = TRUE;
  10382. return result;
  10383. }
  10384. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10385. {
  10386. mtrace();
  10387. int result = FAIL;
  10388. char message[500]={0};
  10389. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10390. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10391. LWS_Send(message);
  10392. return result;
  10393. }
  10394. int sendClearDisplayMessageConfirmation(char *uuid)
  10395. {
  10396. mtrace();
  10397. int result = FAIL;
  10398. char message[4096]={0};
  10399. json_object *ClearDisplayMessage = json_object_new_object();
  10400. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10401. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10402. sprintf(message,"[%d,\"%s\",%s]"
  10403. ,MESSAGE_TYPE_CALLRESULT
  10404. ,uuid
  10405. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10406. json_object_put(ClearDisplayMessage);
  10407. LWS_Send(message);
  10408. result = TRUE;
  10409. return result;
  10410. }
  10411. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10412. {
  10413. mtrace();
  10414. int result = FAIL;
  10415. char message[4096]={0};
  10416. json_object *ClearVariableMonitoring = json_object_new_object();
  10417. json_object *clearMonitoringResults = json_object_new_array();
  10418. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10419. for(int idx=0;idx<variableQuantity;idx++)
  10420. {
  10421. json_object *clearMonitoringResult = json_object_new_object();
  10422. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10423. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10424. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10425. }
  10426. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10427. sprintf(message,"[%d,\"%s\",%s]"
  10428. ,MESSAGE_TYPE_CALLRESULT
  10429. ,uuid
  10430. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10431. json_object_put(ClearVariableMonitoring);
  10432. LWS_Send(message);
  10433. result = TRUE;
  10434. return result;
  10435. }
  10436. int sendCostUpdatedConfirmation(char *uuid)
  10437. {
  10438. mtrace();
  10439. int result = FAIL;
  10440. char message[4096]={0};
  10441. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10442. sprintf(message,"[%d,\"%s\",{}]"
  10443. ,MESSAGE_TYPE_CALLRESULT
  10444. ,uuid);
  10445. LWS_Send(message);
  10446. result = TRUE;
  10447. return result;
  10448. }
  10449. int sendCustomerInformationConfirmation(char *uuid)
  10450. {
  10451. mtrace();
  10452. int result = FAIL;
  10453. char message[4096]={0};
  10454. json_object *CustomerInformation = json_object_new_object();
  10455. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10456. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10457. sprintf(message,"[%d,\"%s\",%s]"
  10458. ,MESSAGE_TYPE_CALLRESULT
  10459. ,uuid
  10460. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10461. json_object_put(CustomerInformation);
  10462. LWS_Send(message);
  10463. result = TRUE;
  10464. return result;
  10465. }
  10466. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10467. {
  10468. mtrace();
  10469. int result = FAIL;
  10470. char message[4096]={0};
  10471. json_object *DataTransfer = json_object_new_object();
  10472. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10473. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10474. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10475. sprintf(message,"[%d,\"%s\",%s]"
  10476. ,MESSAGE_TYPE_CALLRESULT
  10477. ,uuid
  10478. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10479. json_object_put(DataTransfer);
  10480. LWS_Send(message);
  10481. result = TRUE;
  10482. return result;
  10483. }
  10484. int sendDeleteCertificateConfirmation(char *uuid)
  10485. {
  10486. mtrace();
  10487. int result = FAIL;
  10488. char message[4096]={0};
  10489. json_object *DeleteCertificate = json_object_new_object();
  10490. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10491. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10492. sprintf(message,"[%d,\"%s\",%s]"
  10493. ,MESSAGE_TYPE_CALLRESULT
  10494. ,uuid
  10495. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10496. json_object_put(DeleteCertificate);
  10497. LWS_Send(message);
  10498. result = TRUE;
  10499. return result;
  10500. }
  10501. int sendGetBaseReportConfirmation(char *uuid)
  10502. {
  10503. mtrace();
  10504. int result = FAIL;
  10505. char message[4096]={0};
  10506. json_object *GetBaseReport = json_object_new_object();
  10507. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10508. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10509. sprintf(message,"[%d,\"%s\",%s]"
  10510. ,MESSAGE_TYPE_CALLRESULT
  10511. ,uuid
  10512. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10513. json_object_put(GetBaseReport);
  10514. LWS_Send(message);
  10515. result = TRUE;
  10516. return result;
  10517. }
  10518. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10519. {
  10520. mtrace();
  10521. int result = FAIL;
  10522. char message[4096]={0};
  10523. json_object *GetChargingProfiles = json_object_new_object();
  10524. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10525. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10526. sprintf(message,"[%d,\"%s\",%s]"
  10527. ,MESSAGE_TYPE_CALLRESULT
  10528. ,uuid
  10529. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10530. json_object_put(GetChargingProfiles);
  10531. LWS_Send(message);
  10532. result = TRUE;
  10533. return result;
  10534. }
  10535. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  10536. {
  10537. mtrace();
  10538. int result = FAIL;
  10539. char message[4096]={0};
  10540. int CompositeScheduleIndex = 0;
  10541. json_object *GetCompositeSchedule = json_object_new_object();
  10542. json_object *schedule = json_object_new_object();
  10543. json_object *chargingSchedule = json_object_new_object();
  10544. json_object *chargingSchedulePeriod = json_object_new_array();
  10545. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10546. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10547. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  10548. json_object_object_add(schedule, "evseId", json_object_new_int(connectorIdInt));
  10549. if(nPeriod == 0)
  10550. {
  10551. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10552. {
  10553. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10554. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10555. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10556. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10557. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10558. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10559. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10560. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10561. uint8_t isNullSchedulePeriod = TRUE;
  10562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10563. {
  10564. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10565. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10566. {
  10567. json_object *Period = json_object_new_object();
  10568. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10569. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10570. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10571. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10572. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10573. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10574. json_object_array_add(chargingSchedulePeriod, Period);
  10575. isNullSchedulePeriod = FALSE;
  10576. }
  10577. }
  10578. if(isNullSchedulePeriod == TRUE)
  10579. {
  10580. json_object *Period = json_object_new_object();
  10581. json_object_object_add(Period, "startPeriod", json_object_new_int(0));
  10582. float limit = ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  10583. json_object_object_add(Period, "limit", json_object_new_double(limit));
  10584. json_object_array_add(chargingSchedulePeriod, Period);
  10585. }
  10586. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10587. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10588. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10589. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10590. }
  10591. }
  10592. else
  10593. {
  10594. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10595. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10596. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10597. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10598. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10599. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10600. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10601. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10602. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10603. {
  10604. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10605. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10606. {
  10607. json_object *Period = json_object_new_object();
  10608. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10609. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10610. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10611. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10612. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10613. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10614. json_object_array_add(chargingSchedulePeriod, Period);
  10615. }
  10616. }
  10617. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10618. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10619. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10620. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10621. }
  10622. sprintf(message,"[%d,\"%s\",%s]"
  10623. ,MESSAGE_TYPE_CALLRESULT
  10624. ,uuid
  10625. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10626. json_object_put(GetCompositeSchedule);
  10627. LWS_Send(message);
  10628. result = TRUE;
  10629. return result;
  10630. }
  10631. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10632. {
  10633. mtrace();
  10634. int result = FAIL;
  10635. char message[4096]={0};
  10636. json_object *GetGetDisplayMessages = json_object_new_object();
  10637. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10638. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10639. sprintf(message,"[%d,\"%s\",%s]"
  10640. ,MESSAGE_TYPE_CALLRESULT
  10641. ,uuid
  10642. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10643. json_object_put(GetGetDisplayMessages);
  10644. LWS_Send(message);
  10645. result = TRUE;
  10646. return result;
  10647. }
  10648. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10649. {
  10650. mtrace();
  10651. int result = FAIL;
  10652. char message[4096]={0};
  10653. json_object *GetInstalledCertificateIds = json_object_new_object();
  10654. json_object *certificateHashDataChains = json_object_new_array();
  10655. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10656. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10657. for(int idx=0;idx<certQuantity;idx++)
  10658. {
  10659. json_object *cert = json_object_new_object();
  10660. json_object *certificateHashData = json_object_new_object();
  10661. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10662. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10663. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10664. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10665. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10666. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10667. json_object_array_add(certificateHashDataChains, cert);
  10668. }
  10669. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10670. sprintf(message,"[%d,\"%s\",%s]"
  10671. ,MESSAGE_TYPE_CALLRESULT
  10672. ,uuid
  10673. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10674. json_object_put(GetInstalledCertificateIds);
  10675. LWS_Send(message);
  10676. result = TRUE;
  10677. return result;
  10678. }
  10679. int sendGetLocalListVersionConfirmation(char *uuid)
  10680. {
  10681. mtrace();
  10682. int result = FAIL;
  10683. char message[4096]={0};
  10684. json_object *GetLocalListVersion = json_object_new_object();
  10685. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10686. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10687. sprintf(message,"[%d,\"%s\",%s]"
  10688. ,MESSAGE_TYPE_CALLRESULT
  10689. ,uuid
  10690. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10691. json_object_put(GetLocalListVersion);
  10692. LWS_Send(message);
  10693. result = TRUE;
  10694. return result;
  10695. }
  10696. int sendGetLogConfirmation(char *uuid)
  10697. {
  10698. mtrace();
  10699. int result = FAIL;
  10700. char message[4096]={0};
  10701. json_object *GetLog = json_object_new_object();
  10702. DEBUG_INFO("sendGetLogConfirmation...\n");
  10703. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10704. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10705. sprintf(message,"[%d,\"%s\",%s]"
  10706. ,MESSAGE_TYPE_CALLRESULT
  10707. ,uuid
  10708. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10709. json_object_put(GetLog);
  10710. LWS_Send(message);
  10711. result = TRUE;
  10712. return result;
  10713. }
  10714. int sendGetMonitoringReportConfirmation(char *uuid)
  10715. {
  10716. mtrace();
  10717. int result = FAIL;
  10718. char message[4096]={0};
  10719. json_object *GetMonitoringReport = json_object_new_object();
  10720. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10721. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10722. sprintf(message,"[%d,\"%s\",%s]"
  10723. ,MESSAGE_TYPE_CALLRESULT
  10724. ,uuid
  10725. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10726. json_object_put(GetMonitoringReport);
  10727. LWS_Send(message);
  10728. result = TRUE;
  10729. return result;
  10730. }
  10731. int sendGetReportConfirmation(char *uuid)
  10732. {
  10733. mtrace();
  10734. int result = FAIL;
  10735. char message[4096]={0};
  10736. json_object *GetReport = json_object_new_object();
  10737. DEBUG_INFO("sendGetReportConfirmation...\n");
  10738. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10739. sprintf(message,"[%d,\"%s\",%s]"
  10740. ,MESSAGE_TYPE_CALLRESULT
  10741. ,uuid
  10742. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10743. json_object_put(GetReport);
  10744. LWS_Send(message);
  10745. result = TRUE;
  10746. return result;
  10747. }
  10748. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  10749. {
  10750. mtrace();
  10751. int result = FAIL;
  10752. char message[4096]={0};
  10753. json_object *GetTransactionStatus = json_object_new_object();
  10754. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10755. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  10756. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  10757. sprintf(message,"[%d,\"%s\",%s]"
  10758. ,MESSAGE_TYPE_CALLRESULT
  10759. ,uuid
  10760. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10761. json_object_put(GetTransactionStatus);
  10762. LWS_Send(message);
  10763. result = TRUE;
  10764. return result;
  10765. }
  10766. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10767. {
  10768. mtrace();
  10769. int result = FAIL;
  10770. char message[4096]={0};
  10771. json_object *GetVariables = json_object_new_object();
  10772. json_object *getVariableResults = json_object_new_array();
  10773. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10774. for(int idx=0;idx<variableQuantity;idx++)
  10775. {
  10776. json_object *variableResult = json_object_new_object();
  10777. json_object *component = json_object_new_object();
  10778. json_object *variable = json_object_new_object();
  10779. json_object *evse = json_object_new_object();
  10780. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10781. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10782. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10783. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10784. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10785. if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id > 0)
  10786. {
  10787. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10788. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10789. json_object_object_add(component, "evse", evse);
  10790. }
  10791. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10792. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10793. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10794. json_object_object_add(variableResult, "component", component);
  10795. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10796. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10797. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10798. json_object_object_add(variableResult, "variable", variable);
  10799. json_object_array_add(getVariableResults, variableResult);
  10800. }
  10801. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10802. sprintf(message,"[%d,\"%s\",%s]"
  10803. ,MESSAGE_TYPE_CALLRESULT
  10804. ,uuid
  10805. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10806. json_object_put(GetVariables);
  10807. LWS_Send(message);
  10808. result = TRUE;
  10809. return result;
  10810. }
  10811. int sendInstallCertificateConfirmation(char *uuid)
  10812. {
  10813. mtrace();
  10814. int result = FAIL;
  10815. char message[4096]={0};
  10816. json_object *InstallCertificate = json_object_new_object();
  10817. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10818. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10819. sprintf(message,"[%d,\"%s\",%s]"
  10820. ,MESSAGE_TYPE_CALLRESULT
  10821. ,uuid
  10822. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  10823. json_object_put(InstallCertificate);
  10824. LWS_Send(message);
  10825. result = TRUE;
  10826. return result;
  10827. }
  10828. int sendPublishFirmwareConfirmation(char *uuid)
  10829. {
  10830. mtrace();
  10831. int result = FAIL;
  10832. char message[4096]={0};
  10833. json_object *PublishFirmware = json_object_new_object();
  10834. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  10835. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  10836. sprintf(message,"[%d,\"%s\",%s]"
  10837. ,MESSAGE_TYPE_CALLRESULT
  10838. ,uuid
  10839. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  10840. json_object_put(PublishFirmware);
  10841. LWS_Send(message);
  10842. result = TRUE;
  10843. return result;
  10844. }
  10845. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  10846. {
  10847. mtrace();
  10848. int result = FAIL;
  10849. char message[4096]={0};
  10850. json_object *RemoteStartTransaction = json_object_new_object();
  10851. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  10852. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  10853. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  10854. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  10855. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  10856. sprintf(message,"[%d,\"%s\",%s]"
  10857. ,MESSAGE_TYPE_CALLRESULT
  10858. ,uuid
  10859. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  10860. json_object_put(RemoteStartTransaction);
  10861. LWS_Send(message);
  10862. result = TRUE;
  10863. return result;
  10864. }
  10865. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  10866. {
  10867. mtrace();
  10868. int result = FAIL;
  10869. char message[4096]={0};
  10870. json_object *RemoteStopTransaction = json_object_new_object();
  10871. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  10872. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  10873. sprintf(message,"[%d,\"%s\",%s]"
  10874. ,MESSAGE_TYPE_CALLRESULT
  10875. ,uuid
  10876. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  10877. json_object_put(RemoteStopTransaction);
  10878. LWS_Send(message);
  10879. result = TRUE;
  10880. return result;
  10881. }
  10882. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  10883. {
  10884. mtrace();
  10885. int result = FAIL;
  10886. char message[4096]={0};
  10887. json_object *ReserveNow = json_object_new_object();
  10888. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  10889. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  10890. sprintf(message,"[%d,\"%s\",%s]"
  10891. ,MESSAGE_TYPE_CALLRESULT
  10892. ,uuid
  10893. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  10894. json_object_put(ReserveNow);
  10895. LWS_Send(message);
  10896. result = TRUE;
  10897. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  10898. return result;
  10899. }
  10900. int sendResetConfirmation(char *uuid)
  10901. {
  10902. mtrace();
  10903. int result = FAIL;
  10904. char message[4096]={0};
  10905. json_object *Reset = json_object_new_object();
  10906. DEBUG_INFO("sendResetConfirmation...\n");
  10907. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  10908. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  10909. sprintf(message,"[%d,\"%s\",%s]"
  10910. ,MESSAGE_TYPE_CALLRESULT
  10911. ,uuid
  10912. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  10913. json_object_put(Reset);
  10914. LWS_Send(message);
  10915. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  10916. {
  10917. DB_updateBootType(BootReasonEnumType_RemoteReset);
  10918. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10919. }
  10920. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  10921. {
  10922. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  10923. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  10924. }
  10925. result = TRUE;
  10926. return result;
  10927. }
  10928. int sendSendLocalListConfirmation(char *uuid)
  10929. {
  10930. mtrace();
  10931. int result = FAIL;
  10932. char message[4096]={0};
  10933. json_object *SendLocalList = json_object_new_object();
  10934. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  10935. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  10936. sprintf(message,"[%d,\"%s\",%s]"
  10937. ,MESSAGE_TYPE_CALLRESULT
  10938. ,uuid
  10939. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  10940. json_object_put(SendLocalList);
  10941. LWS_Send(message);
  10942. result = TRUE;
  10943. return result;
  10944. }
  10945. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  10946. {
  10947. mtrace();
  10948. int result = FAIL;
  10949. char message[4096]={0};
  10950. json_object *SetChargingProfile = json_object_new_object();
  10951. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  10952. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  10953. sprintf(message,"[%d,\"%s\",%s]"
  10954. ,MESSAGE_TYPE_CALLRESULT
  10955. ,uuid
  10956. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10957. json_object_put(SetChargingProfile);
  10958. LWS_Send(message);
  10959. result = TRUE;
  10960. return result;
  10961. }
  10962. int sendSetDisplayMessagesConfirmation(char *uuid)
  10963. {
  10964. mtrace();
  10965. int result = FAIL;
  10966. char message[4096]={0};
  10967. json_object *SetDisplayMessage = json_object_new_object();
  10968. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  10969. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  10970. sprintf(message,"[%d,\"%s\",%s]"
  10971. ,MESSAGE_TYPE_CALLRESULT
  10972. ,uuid
  10973. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10974. json_object_put(SetDisplayMessage);
  10975. LWS_Send(message);
  10976. result = TRUE;
  10977. return result;
  10978. }
  10979. int sendSetMonitoringBaseConfirmation(char *uuid)
  10980. {
  10981. mtrace();
  10982. int result = FAIL;
  10983. char message[4096]={0};
  10984. json_object *SetMonitoringBase = json_object_new_object();
  10985. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  10986. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  10987. sprintf(message,"[%d,\"%s\",%s]"
  10988. ,MESSAGE_TYPE_CALLRESULT
  10989. ,uuid
  10990. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  10991. json_object_put(SetMonitoringBase);
  10992. LWS_Send(message);
  10993. result = TRUE;
  10994. return result;
  10995. }
  10996. int sendSetMonitoringLevelConfirmation(char *uuid)
  10997. {
  10998. mtrace();
  10999. int result = FAIL;
  11000. char message[4096]={0};
  11001. json_object *SetMonitoringLevel = json_object_new_object();
  11002. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  11003. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  11004. sprintf(message,"[%d,\"%s\",%s]"
  11005. ,MESSAGE_TYPE_CALLRESULT
  11006. ,uuid
  11007. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  11008. json_object_put(SetMonitoringLevel);
  11009. LWS_Send(message);
  11010. result = TRUE;
  11011. return result;
  11012. }
  11013. int sendSetNetworkProfileConfirmation(char *uuid)
  11014. {
  11015. mtrace();
  11016. int result = FAIL;
  11017. char message[4096]={0};
  11018. json_object *SetNetworkProfile = json_object_new_object();
  11019. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  11020. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  11021. sprintf(message,"[%d,\"%s\",%s]"
  11022. ,MESSAGE_TYPE_CALLRESULT
  11023. ,uuid
  11024. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  11025. json_object_put(SetNetworkProfile);
  11026. LWS_Send(message);
  11027. result = TRUE;
  11028. return result;
  11029. }
  11030. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  11031. {
  11032. mtrace();
  11033. int result = FAIL;
  11034. char message[4096]={0};
  11035. json_object *SetVariableMonitoring = json_object_new_object();
  11036. json_object *setMonitoringResults = json_object_new_array();
  11037. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  11038. for(int idx=0;idx<variableQuantity;idx++)
  11039. {
  11040. json_object *variableMonitorResult = json_object_new_object();
  11041. json_object *component = json_object_new_object();
  11042. json_object *variable = json_object_new_object();
  11043. json_object *evse = json_object_new_object();
  11044. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  11045. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  11046. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  11047. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  11048. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  11049. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  11050. json_object_object_add(component, "evse", evse);
  11051. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  11052. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  11053. json_object_object_add(variableMonitorResult, "component", component);
  11054. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  11055. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  11056. json_object_object_add(variableMonitorResult, "variable", variable);
  11057. json_object_array_add(setMonitoringResults, variableMonitorResult);
  11058. }
  11059. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  11060. sprintf(message,"[%d,\"%s\",%s]"
  11061. ,MESSAGE_TYPE_CALLRESULT
  11062. ,uuid
  11063. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  11064. json_object_put(SetVariableMonitoring);
  11065. LWS_Send(message);
  11066. result = TRUE;
  11067. return result;
  11068. }
  11069. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  11070. {
  11071. mtrace();
  11072. int result = FAIL;
  11073. char message[4096]={0};
  11074. json_object *SetVariable = json_object_new_object();
  11075. json_object *setVariableResults = json_object_new_array();
  11076. DEBUG_INFO("sendSetVariableConfirmation...\n");
  11077. for(int idx=0;idx<variableQuantity;idx++)
  11078. {
  11079. json_object *variableResult = json_object_new_object();
  11080. json_object *component = json_object_new_object();
  11081. json_object *variable = json_object_new_object();
  11082. json_object *evse = json_object_new_object();
  11083. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  11084. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  11085. if(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id > 0)
  11086. {
  11087. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  11088. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  11089. json_object_object_add(component, "evse", evse);
  11090. }
  11091. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  11092. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance) > 0)
  11093. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  11094. json_object_object_add(variableResult, "component", component);
  11095. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  11096. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance)>0)
  11097. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  11098. json_object_object_add(variableResult, "variable", variable);
  11099. json_object_array_add(setVariableResults, variableResult);
  11100. }
  11101. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  11102. sprintf(message,"[%d,\"%s\",%s]"
  11103. ,MESSAGE_TYPE_CALLRESULT
  11104. ,uuid
  11105. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  11106. json_object_put(SetVariable);
  11107. LWS_Send(message);
  11108. result = TRUE;
  11109. return result;
  11110. }
  11111. int sendTriggerMessageConfirmation(char *uuid)
  11112. {
  11113. mtrace();
  11114. int result = FAIL;
  11115. char message[4096]={0};
  11116. json_object *TriggerMessage = json_object_new_object();
  11117. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  11118. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  11119. sprintf(message,"[%d,\"%s\",%s]",
  11120. MESSAGE_TYPE_CALLRESULT,
  11121. uuid,
  11122. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  11123. json_object_put(TriggerMessage);
  11124. LWS_Send(message);
  11125. result = TRUE;
  11126. return result;
  11127. }
  11128. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  11129. {
  11130. mtrace();
  11131. int result = FAIL;
  11132. char message[4096]={0};
  11133. json_object *UnlockConnector = json_object_new_object();
  11134. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  11135. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  11136. sprintf(message,"[%d,\"%s\",%s]",
  11137. MESSAGE_TYPE_CALLRESULT,
  11138. uuid,
  11139. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  11140. json_object_put(UnlockConnector);
  11141. LWS_Send(message);
  11142. result = TRUE;
  11143. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  11144. return result;
  11145. }
  11146. int sendUnpublishFirmwareConfirmation(char *uuid)
  11147. {
  11148. mtrace();
  11149. int result = FAIL;
  11150. char message[4096]={0};
  11151. json_object *UnpublishFirmware = json_object_new_object();
  11152. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  11153. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  11154. sprintf(message,"[%d,\"%s\",%s]"
  11155. ,MESSAGE_TYPE_CALLRESULT
  11156. ,uuid
  11157. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  11158. json_object_put(UnpublishFirmware);
  11159. LWS_Send(message);
  11160. result = TRUE;
  11161. return result;
  11162. }
  11163. int sendUpdateFirmwareConfirmation(char *uuid)
  11164. {
  11165. mtrace();
  11166. int result = FAIL;
  11167. char message[4096]={0};
  11168. json_object *UpdateFirmware = json_object_new_object();
  11169. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  11170. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  11171. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  11172. sprintf(message,"[%d,\"%s\",%s]"
  11173. ,MESSAGE_TYPE_CALLRESULT
  11174. ,uuid
  11175. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  11176. json_object_put(UpdateFirmware);
  11177. LWS_Send(message);
  11178. result = TRUE;
  11179. return result;
  11180. }
  11181. int sendUnknownConfirmation(char *uuid)
  11182. {
  11183. mtrace();
  11184. int result = FAIL;
  11185. char message[256]={0};
  11186. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  11187. DEBUG_INFO("sendUnknownConfirmation...\n");
  11188. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  11189. LWS_Send(message);
  11190. result = TRUE;
  11191. return result;
  11192. }
  11193. //==========================================
  11194. // send CallError routine
  11195. //==========================================
  11196. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  11197. {
  11198. mtrace();
  11199. char message[220]={0};
  11200. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  11201. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  11202. LWS_Send(message);
  11203. }
  11204. //==========================================
  11205. // Handle server request routine Start
  11206. //==========================================
  11207. int handleCancelReservationRequest(char *uuid, char *payload)
  11208. {
  11209. mtrace();
  11210. int result = FAIL;
  11211. int gunNO = 0;
  11212. int reservationIdInt = -1;
  11213. DEBUG_INFO("handleCancelReservationRequest...\n");
  11214. json_object *CancelReservation;
  11215. CancelReservation = json_tokener_parse(payload);
  11216. if(!is_error(CancelReservation))
  11217. {
  11218. // Required data
  11219. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  11220. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  11221. }
  11222. json_object_put(CancelReservation);
  11223. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  11224. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  11225. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  11226. if(reservationIdInt != -1)
  11227. {
  11228. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11229. //check Transaction active
  11230. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  11231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11232. {
  11233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  11234. {
  11235. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11236. if(gunType[2] == GUN_TYPE_CHAdeMO)
  11237. {
  11238. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  11239. }
  11240. else
  11241. {
  11242. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  11243. }
  11244. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11245. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11246. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11247. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11248. goto end;
  11249. }
  11250. }
  11251. for (int index = 0; index < CCS_QUANTITY; index++)
  11252. {
  11253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  11254. {
  11255. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11256. if(gunType[2] == GUN_TYPE_CCS)
  11257. {
  11258. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  11259. }
  11260. else
  11261. {
  11262. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  11263. }
  11264. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11265. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11266. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11267. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11268. goto end;
  11269. }
  11270. }
  11271. for (int index = 0; index < GB_QUANTITY; index++)
  11272. {
  11273. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  11274. {
  11275. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11276. if(gunType[2] == GUN_TYPE_GBT)
  11277. {
  11278. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  11279. }
  11280. else
  11281. {
  11282. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11283. }
  11284. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11285. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11286. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11287. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11288. goto end;
  11289. }
  11290. }
  11291. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11292. {
  11293. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  11294. {
  11295. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11296. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11297. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11298. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11299. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11300. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11301. goto end;
  11302. }
  11303. }
  11304. for (int index = 0; index < AC_QUANTITY; index++)
  11305. {
  11306. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  11307. {
  11308. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11309. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11310. {
  11311. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  11312. }
  11313. else
  11314. {
  11315. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  11316. }
  11317. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11318. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11319. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11320. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11321. goto end;
  11322. }
  11323. }
  11324. }
  11325. //The reservationId does NOT match the reservationId
  11326. sendCancelReservationConfirmation(uuid, gunNO);
  11327. end:
  11328. // Fill in ocpp packet uuid
  11329. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  11330. return result;
  11331. }
  11332. int handleCertificateSignedRequest(char *uuid, char *payload)
  11333. {
  11334. mtrace();
  11335. int result = FAIL;
  11336. json_object *CertificateSigned;
  11337. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11338. CertificateSigned = json_tokener_parse(payload);
  11339. if(!is_error(CertificateSigned))
  11340. {
  11341. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  11342. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  11343. // Required data
  11344. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  11345. // Optional data
  11346. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  11347. {
  11348. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  11349. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11350. {
  11351. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11352. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11353. fclose(fp);
  11354. }
  11355. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11356. {
  11357. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  11358. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11359. fclose(fp);
  11360. }
  11361. }
  11362. else
  11363. {
  11364. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11365. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11366. fclose(fp);
  11367. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  11368. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11369. fclose(fp);
  11370. }
  11371. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11372. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11373. }
  11374. else
  11375. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11376. json_object_put(CertificateSigned);
  11377. sendCertificateSignedConfirmation(uuid);
  11378. return result;
  11379. }
  11380. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11381. {
  11382. mtrace();
  11383. int result = FAIL;
  11384. int evseId = 0, gunIndex = 0;
  11385. char operationalStatus[16]={0};
  11386. char comfirmstr[20];
  11387. int specificId = FALSE;
  11388. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11389. json_object *ChangeAvailability;
  11390. ChangeAvailability = json_tokener_parse(payload);
  11391. if(!is_error(ChangeAvailability))
  11392. {
  11393. // Required data
  11394. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11395. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11396. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11397. {
  11398. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11399. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11400. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11401. }
  11402. }
  11403. json_object_put(ChangeAvailability);
  11404. if((evseId != 0) && (evseId <= gunTotalNumber))
  11405. {
  11406. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  11407. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11408. }
  11409. else if(evseId == 0)
  11410. {
  11411. for(int i=0; i < gunTotalNumber; i++)
  11412. {
  11413. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  11414. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11415. }
  11416. }
  11417. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11418. {
  11419. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  11420. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11421. }
  11422. else if(gunIndex == 0)
  11423. {
  11424. for(int i=0; i < gunTotalNumber; i++)
  11425. {
  11426. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  11427. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11428. }
  11429. }
  11430. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11431. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11432. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  11433. {
  11434. specificId = TRUE;
  11435. }
  11436. if(specificId == FALSE)
  11437. goto end;
  11438. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11439. {
  11440. //----------------------gunIndex is 0 ------------------------------------------------//
  11441. if(gunIndex == 0)
  11442. {
  11443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11444. {
  11445. for(int i=0; i < gunTotalNumber; i++)
  11446. {
  11447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11448. {
  11449. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11450. {
  11451. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11452. {
  11453. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11454. goto end;
  11455. }
  11456. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11457. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11458. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11459. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11460. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11461. {
  11462. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11463. goto end;
  11464. }
  11465. }
  11466. }//END FOR CHAdeMO_QUANTITY
  11467. for (int index = 0; index < CCS_QUANTITY; index++)
  11468. {
  11469. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11470. {
  11471. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11472. {
  11473. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11474. goto end;
  11475. }
  11476. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11477. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11478. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11479. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11480. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11481. {
  11482. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11483. goto end;
  11484. }
  11485. }
  11486. }//END FOR CCS_QUANTITY
  11487. for (int index = 0; index < GB_QUANTITY; index++)
  11488. {
  11489. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11490. {
  11491. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11492. {
  11493. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11494. goto end;
  11495. }
  11496. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11497. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11498. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11499. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11500. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11501. {
  11502. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11503. goto end;
  11504. }
  11505. }
  11506. }// END FOR GB_QUANTITY
  11507. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11508. {
  11509. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11510. {
  11511. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11512. {
  11513. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11514. goto end;
  11515. }
  11516. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11517. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11518. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11519. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11520. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11521. {
  11522. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11523. goto end;
  11524. }
  11525. }
  11526. }// END FOR DO_QUANTITY
  11527. for (int index = 0; index < AC_QUANTITY; index++)
  11528. {
  11529. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11530. {
  11531. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11532. {
  11533. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11534. goto end;
  11535. }
  11536. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11537. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11538. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11539. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11540. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11541. {
  11542. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11543. goto end;
  11544. }
  11545. }
  11546. }//END FOR AC_QUANTITY
  11547. }// END FOR gunTotalNumber
  11548. }
  11549. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11550. {
  11551. for(int i=0; i < gunTotalNumber; i++)
  11552. {
  11553. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11554. {
  11555. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11556. goto end;
  11557. }
  11558. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11559. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11560. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11561. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11562. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11563. {
  11564. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11565. goto end;
  11566. }
  11567. }
  11568. }
  11569. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11570. goto end;
  11571. }
  11572. //----------------------gunIndex is not 0 ------------------------------------------------//
  11573. //check Transaction active
  11574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11575. {
  11576. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  11577. {
  11578. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11579. {
  11580. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11581. goto end;
  11582. }
  11583. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11584. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11585. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11586. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11587. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11588. {
  11589. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11590. goto end;
  11591. }
  11592. else
  11593. {
  11594. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11595. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11596. goto end;
  11597. }
  11598. }
  11599. }//END FOR CHAdeMO_QUANTITY
  11600. for (int index = 0; index < CCS_QUANTITY; index++)
  11601. {
  11602. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  11603. {
  11604. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11605. {
  11606. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11607. goto end;
  11608. }
  11609. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11610. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11611. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11612. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11613. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11614. {
  11615. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11616. goto end;
  11617. }
  11618. else
  11619. {
  11620. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11621. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11622. goto end;
  11623. }
  11624. }
  11625. }//END FOR CCS_QUANTITY
  11626. for (int index = 0; index < GB_QUANTITY; index++)
  11627. {
  11628. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  11629. {
  11630. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11631. {
  11632. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11633. goto end;
  11634. }
  11635. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11636. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11637. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11638. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11639. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11640. {
  11641. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11642. goto end;
  11643. }
  11644. else
  11645. {
  11646. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11647. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11648. goto end;
  11649. }
  11650. }
  11651. }// END FOR GB_QUANTITY
  11652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11653. {
  11654. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  11655. {
  11656. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11657. {
  11658. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11659. goto end;
  11660. }
  11661. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11662. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11663. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11664. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11665. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11666. {
  11667. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11668. goto end;
  11669. }
  11670. else
  11671. {
  11672. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11673. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11674. goto end;
  11675. }
  11676. }
  11677. }// END FOR DO_QUANTITY
  11678. for (int index = 0; index < AC_QUANTITY; index++)
  11679. {
  11680. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  11681. {
  11682. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11683. {
  11684. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11685. goto end;
  11686. }
  11687. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11688. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11689. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11690. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11691. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11692. {
  11693. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11694. goto end;
  11695. }
  11696. else
  11697. {
  11698. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11699. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11700. goto end;
  11701. }
  11702. }
  11703. }//END FOR AC_QUANTITY
  11704. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11705. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11706. {
  11707. //----------------------gunIndex is 0 ------------------------------------------------//
  11708. if(gunIndex == 0)
  11709. {
  11710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11711. {
  11712. for(int i=0; i < gunTotalNumber; i++)
  11713. {
  11714. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11715. {
  11716. 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
  11717. {
  11718. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11719. goto end;
  11720. }
  11721. }//END FOR CHAdeMO_QUANTITY
  11722. for (int index = 0; index < CCS_QUANTITY; index++)
  11723. {
  11724. 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
  11725. {
  11726. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11727. goto end;
  11728. }
  11729. }//END FOR CCS_QUANTITY
  11730. for (int index = 0; index < GB_QUANTITY; index++)
  11731. {
  11732. 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
  11733. {
  11734. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11735. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11736. goto end;
  11737. }
  11738. }// END FOR GB_QUANTITY
  11739. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11740. {
  11741. 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
  11742. {
  11743. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11744. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11745. goto end;
  11746. }
  11747. }// END FOR DO_QUANTITY
  11748. for (int index = 0; index < AC_QUANTITY; index++)
  11749. {
  11750. 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
  11751. {
  11752. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11753. goto end;
  11754. }
  11755. }//END FOR CHAdeMO_QUANTITY
  11756. }// END FOR gunTotalNumber
  11757. }
  11758. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11759. {
  11760. for(int i=0; i < gunTotalNumber; i++)
  11761. {
  11762. for (int index = 0; index < AC_QUANTITY; index++)
  11763. {
  11764. 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
  11765. {
  11766. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11767. goto end;
  11768. }
  11769. }//END FOR CHAdeMO_QUANTITY
  11770. } // END FOR gunTotalNumber
  11771. }
  11772. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11773. goto end;
  11774. }
  11775. //----------------------gunIndex is not 0 ------------------------------------------------//
  11776. //check Transaction active
  11777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11778. {
  11779. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11780. {
  11781. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11782. goto end;
  11783. }
  11784. }//END FOR CHAdeMO_QUANTITY
  11785. for (int index = 0; index < CCS_QUANTITY; index++)
  11786. {
  11787. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11788. {
  11789. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11790. goto end;
  11791. }
  11792. }//END FOR CCS_QUANTITY
  11793. for (int index = 0; index < GB_QUANTITY; index++)
  11794. {
  11795. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11796. {
  11797. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11798. goto end;
  11799. }
  11800. }// END FOR GB_QUANTITY
  11801. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11802. {
  11803. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11804. {
  11805. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11806. goto end;
  11807. }
  11808. }// END FOR DO_QUANTITY
  11809. for (int index = 0; index < AC_QUANTITY; index++)
  11810. {
  11811. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11812. {
  11813. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11814. goto end;
  11815. }
  11816. }//END FOR AC_QUANTITY
  11817. }//END FOR AvailabilityEnumTypeStr[Operative]
  11818. end:
  11819. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11820. {
  11821. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  11822. }
  11823. else
  11824. {
  11825. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  11826. }
  11827. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11828. {
  11829. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11830. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11831. }
  11832. else if(gunIndex == 0)
  11833. {
  11834. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  11835. {
  11836. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  11837. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  11838. }
  11839. }
  11840. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  11841. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11842. return result;
  11843. }
  11844. int handleClearCacheRequest(char *uuid, char *payload)
  11845. {
  11846. mtrace();
  11847. int result = FAIL;
  11848. char rmFileCmd[100]={0};
  11849. struct stat stats;
  11850. DEBUG_INFO("handleClearCacheRequest...\n");
  11851. stat("/Storage/OCPP", &stats);
  11852. // Check for directory existence
  11853. if (S_ISDIR(stats.st_mode) == 1)
  11854. {}
  11855. else
  11856. {
  11857. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  11858. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  11859. system(rmFileCmd);
  11860. }
  11861. if(DB_cleanLocalCache() != PASS)
  11862. {
  11863. DEBUG_INFO("open AuthorizationCache file failed\n");
  11864. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  11865. }
  11866. else
  11867. {
  11868. DEBUG_INFO("open AuthorizationCache file successful\n");
  11869. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  11870. }
  11871. sendClearCacheConfirmation(uuid);
  11872. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11873. return result;
  11874. }
  11875. int handleClearChargingProfileRequest(char *uuid, char *payload)
  11876. {
  11877. mtrace();
  11878. int result = FAIL;
  11879. int resultRename;
  11880. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  11881. char chargingProfilePurposeStr[26]={0};
  11882. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  11883. char tempchargingProfilePurposeStr[26]={0};
  11884. char sstr[160]={0};
  11885. char str[100]={0};
  11886. int c = 0;
  11887. char *loc;
  11888. char fname[200]={0};
  11889. char comfirmstr[20]={0};
  11890. char word[1600]={0};
  11891. int clearflag = FALSE;
  11892. int chargingProfileIdIsNULL = FALSE;
  11893. int connectorIsNULL = FALSE;
  11894. int chargingProfilePurposeIsNULL = FALSE;
  11895. int stackLevelIsNULL = FALSE;
  11896. //int GotoEnd = FALSE;
  11897. FILE *fptr1, *fptr2;
  11898. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  11899. int n_chargingProfile=0;
  11900. int isEmptyFile = FALSE;
  11901. char sLineWord[1600]={0};
  11902. char chargingProfiles[10][100]={0};
  11903. int ChargeProfileCount = 0;
  11904. int ch;
  11905. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  11906. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  11907. json_object *ClearChargingProfile;
  11908. ClearChargingProfile = json_tokener_parse(payload);
  11909. if(!is_error(ClearChargingProfile))
  11910. {
  11911. // Optional data
  11912. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  11913. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  11914. else
  11915. chargingProfileIdIsNULL = TRUE;
  11916. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  11917. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  11918. else
  11919. connectorIsNULL = TRUE;
  11920. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  11921. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  11922. else
  11923. chargingProfilePurposeIsNULL = TRUE;
  11924. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  11925. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  11926. else
  11927. stackLevelIsNULL = TRUE;
  11928. }
  11929. json_object_put(ClearChargingProfile);
  11930. if(connectorIsNULL == FALSE)
  11931. {
  11932. switch(connectorIdInt)
  11933. {
  11934. case 0:
  11935. if(chargingProfilePurposeIsNULL == TRUE)
  11936. {
  11937. int l = 0;
  11938. strcpy(fname, ChargingStationMaxProfile_JSON);
  11939. if((access(fname,F_OK))!=-1)
  11940. {
  11941. strcpy(chargingProfiles[l], fname);
  11942. l = l + 1;
  11943. }
  11944. strcpy(fname, TxDefaultProfile_0_JSON);
  11945. if((access(fname,F_OK))!=-1)
  11946. {
  11947. strcpy(chargingProfiles[l], fname);
  11948. l = l + 1;
  11949. }
  11950. ChargeProfileCount = l;
  11951. }
  11952. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  11953. {
  11954. strcpy(fname, ChargingStationMaxProfile_JSON);
  11955. if((access(fname,F_OK))!=-1)
  11956. {
  11957. strcpy(chargingProfiles[0], fname);
  11958. ChargeProfileCount = 1;
  11959. }
  11960. }
  11961. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11962. {
  11963. strcpy(fname, TxDefaultProfile_0_JSON);
  11964. if((access(fname,F_OK))!=-1)
  11965. {
  11966. strcpy(chargingProfiles[0], fname);
  11967. ChargeProfileCount = 1;
  11968. }
  11969. }
  11970. break;
  11971. default:
  11972. if(chargingProfilePurposeIsNULL == TRUE)
  11973. {
  11974. int m = 0;
  11975. memset(fname, 0, ARRAY_SIZE(fname));
  11976. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11977. if((access(fname,F_OK))!=-1)
  11978. {
  11979. strcpy(chargingProfiles[m], fname);
  11980. m = m + 1;
  11981. }
  11982. memset(fname, 0, ARRAY_SIZE(fname));
  11983. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11984. if((access(fname,F_OK))!=-1)
  11985. {
  11986. strcpy(chargingProfiles[m], fname);
  11987. m = m + 1;
  11988. }
  11989. ChargeProfileCount = m;
  11990. }
  11991. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11992. {
  11993. //strcpy(fname, TxDefaultProfile_1_JSON);
  11994. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11995. if((access(fname,F_OK))!=-1)
  11996. {
  11997. strcpy(chargingProfiles[0], fname);
  11998. ChargeProfileCount = 1;
  11999. }
  12000. }
  12001. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  12002. {
  12003. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  12004. if((access(fname,F_OK))!=-1)
  12005. {
  12006. strcpy(chargingProfiles[0], fname);
  12007. ChargeProfileCount = 1;
  12008. }
  12009. }
  12010. //strcpy(fname, ChargePointMaxProfile_JSON );
  12011. break;
  12012. }
  12013. }
  12014. else // Check all Charging Profiles
  12015. {
  12016. int i = 0;
  12017. char fnametemp[200]={0};
  12018. ChargeProfileCount = 0;
  12019. //Check ChargePointMaxProfile.json exit
  12020. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12021. {
  12022. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  12023. i = i + 1;
  12024. }
  12025. //Check TxDefaultProfile_%d.json
  12026. for(int j=1; j <= gunTotalNumber; j++)
  12027. {
  12028. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12029. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  12030. if((access(fnametemp,F_OK))!=-1)
  12031. {
  12032. strcpy(chargingProfiles[i], fnametemp);
  12033. i = i + 1;
  12034. }
  12035. }
  12036. //Check TxProfile_%d.json
  12037. for(int j=1; j <= gunTotalNumber; j++)
  12038. {
  12039. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12040. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  12041. if((access(fnametemp,F_OK))!=-1)
  12042. {
  12043. strcpy(chargingProfiles[i], fnametemp);
  12044. i = i + 1;
  12045. }
  12046. }
  12047. ChargeProfileCount = i;
  12048. }// End connectorIsNULL is TRUE
  12049. if(ChargeProfileCount == 0)
  12050. {
  12051. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12052. goto end;
  12053. }
  12054. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  12055. {
  12056. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12057. goto end;
  12058. }
  12059. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  12060. {
  12061. memset(str, 0, ARRAY_SIZE(str));
  12062. // clear temp file
  12063. sprintf(str,"rm -f %s",temp);
  12064. system(str);
  12065. for(int k=0; k < ChargeProfileCount; k++)
  12066. {
  12067. memset(str, 0, ARRAY_SIZE(str));
  12068. //clear file in C
  12069. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12070. system(str);
  12071. }
  12072. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12073. goto end;
  12074. }
  12075. else if(connectorIsNULL == TRUE)
  12076. {
  12077. for(int k=0; k < ChargeProfileCount; k++)
  12078. {
  12079. fptr1 = fopen(chargingProfiles[k], "r");
  12080. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  12081. //Check Charging Profile Count
  12082. while(fscanf(fptr1, "%s", word) != EOF)
  12083. {
  12084. //DEBUG_INFO("word=%s\n",word);
  12085. if(strstr(word, "id")!= NULL)
  12086. {
  12087. //DEBUG_INFO("test id \n");
  12088. n_chargingProfile = n_chargingProfile + 1;
  12089. //DEBUG_INFO("id Found\n");
  12090. }
  12091. }
  12092. rewind(fptr1);
  12093. //search Charging Profile Element
  12094. //int i= 0;
  12095. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12096. {
  12097. //------------------------tempconnectorIdInt------------------------//
  12098. loc = strstr(sLineWord, "evseId");
  12099. c = 0;
  12100. memset(sstr ,0, sizeof(sstr) );
  12101. while (loc[strlen("evseId")+2+c] != ',')
  12102. {
  12103. sstr[c] = loc[strlen("evseId")+2+c];
  12104. c++;
  12105. }
  12106. sstr[c] = '\0';
  12107. tempconnectorIdInt = atoi(sstr);
  12108. printf("file's gun number is %d\n", tempconnectorIdInt);
  12109. //--------------------------id--------------------//
  12110. c = 0;
  12111. loc = strstr(sLineWord, "id");
  12112. memset(sstr ,0, ARRAY_SIZE(sstr));
  12113. while (loc[strlen("id")+2+c] != ',')
  12114. {
  12115. sstr[c] = loc[strlen("id")+2+c];
  12116. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12117. c++;
  12118. }
  12119. sstr[c] = '\0';
  12120. tempchargingProfileIdInt = atoi(sstr);
  12121. //stackLevel
  12122. c = 0;
  12123. loc = strstr(sLineWord, "stackLevel");
  12124. memset(sstr ,0, ARRAY_SIZE(sstr));
  12125. while (loc[strlen("stackLevel")+2+c] != ',')
  12126. {
  12127. sstr[c] = loc[strlen("stackLevel")+2+c];
  12128. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12129. c++;
  12130. }
  12131. sstr[c] = '\0';
  12132. tempstackLevelInt = atoi(sstr);
  12133. c = 0;
  12134. loc = strstr(sLineWord, "chargingProfilePurpose");
  12135. memset(sstr ,0, ARRAY_SIZE(sstr));
  12136. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12137. {
  12138. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12139. c++;
  12140. }
  12141. sstr[c] = '\0';
  12142. strcpy(tempchargingProfilePurposeStr, sstr);
  12143. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12144. {
  12145. //------- not write to fptr2-------//
  12146. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12147. //clearflag = TRUE;
  12148. }
  12149. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  12150. {
  12151. //------- not write to fptr2-------//
  12152. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12153. }
  12154. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12155. {
  12156. //------- not write to fptr2-------//
  12157. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12158. }
  12159. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  12160. {
  12161. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12162. }
  12163. else
  12164. {
  12165. fprintf(fptr2, sLineWord);//writing data into file
  12166. }
  12167. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12168. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12169. if(clearflag == TRUE)
  12170. {
  12171. fclose(fptr1);
  12172. fclose(fptr2);
  12173. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12174. system(str);
  12175. // clear temp file
  12176. sprintf(str,"rm -f %s",temp);
  12177. system(str);
  12178. }
  12179. else
  12180. {
  12181. fclose(fptr1);
  12182. fclose(fptr2);
  12183. memset(str, 0, ARRAY_SIZE(str));
  12184. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12185. system(str);
  12186. resultRename = rename(temp, chargingProfiles[k]);
  12187. if(resultRename == 0)
  12188. {
  12189. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  12190. }
  12191. else
  12192. {
  12193. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  12194. }
  12195. if(comfirmstr[0]== 0)
  12196. {
  12197. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12198. }
  12199. //Check chargingProfile is empty file
  12200. /*------ Read the file ----------------*/
  12201. fptr1=fopen(chargingProfiles[k],"r");
  12202. ch=fgetc(fptr1);
  12203. rewind(fptr1);
  12204. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12205. if(ch!=EOF)
  12206. {
  12207. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12208. {
  12209. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12210. if(sLineWord[0]=='\0')
  12211. {
  12212. isEmptyFile = TRUE;
  12213. break;
  12214. }
  12215. else
  12216. {
  12217. isEmptyFile = FALSE;
  12218. break;
  12219. }
  12220. }
  12221. }
  12222. else
  12223. isEmptyFile = TRUE;
  12224. fclose(fptr1);
  12225. if(isEmptyFile == TRUE)
  12226. {
  12227. memset(str, 0, ARRAY_SIZE(str));
  12228. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12229. system(str);
  12230. }
  12231. }
  12232. }// End of while(int k=0; k < ChargePointCount; k++)
  12233. }
  12234. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  12235. {
  12236. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  12237. for(int k=0; k < ChargeProfileCount; k++)
  12238. {
  12239. fptr1 = fopen(chargingProfiles[k], "r");
  12240. fptr2 = fopen(temp, "w+");
  12241. //Check Charging Profile Count
  12242. while(fscanf(fptr1, "%s", word) != EOF)
  12243. {
  12244. //DEBUG_INFO("word=%s\n",word);
  12245. if(strstr(word, "id")!= NULL)
  12246. {
  12247. n_chargingProfile = n_chargingProfile + 1;
  12248. }
  12249. }
  12250. rewind(fptr1);
  12251. //search Charging Profile Element
  12252. //int i= 0;
  12253. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12254. {
  12255. //*************************tempconnectorIdInt*********************************/
  12256. loc = strstr(sLineWord, "connectorId");
  12257. c = 0;
  12258. memset(sstr ,0, ARRAY_SIZE(sstr));
  12259. while (loc[strlen("connectorId")+2+c] != ',')
  12260. {
  12261. sstr[c] = loc[strlen("connectorId")+2+c];
  12262. c++;
  12263. }
  12264. sstr[c] = '\0';
  12265. tempconnectorIdInt = atoi(sstr);
  12266. //id
  12267. c = 0;
  12268. loc = strstr(sLineWord, "id");
  12269. memset(sstr ,0, ARRAY_SIZE(sstr));
  12270. while (loc[strlen("id")+2+c] != ',')
  12271. {
  12272. sstr[c] = loc[strlen("id")+2+c];
  12273. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12274. c++;
  12275. }
  12276. sstr[c] = '\0';
  12277. tempchargingProfileIdInt = atoi(sstr);
  12278. //stackLevel
  12279. c = 0;
  12280. loc = strstr(sLineWord, "stackLevel");
  12281. memset(sstr ,0, ARRAY_SIZE(sstr));
  12282. while (loc[strlen("stackLevel")+2+c] != ',')
  12283. {
  12284. sstr[c] = loc[strlen("stackLevel")+2+c];
  12285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12286. c++;
  12287. }
  12288. sstr[c] = '\0';
  12289. tempstackLevelInt = atoi(sstr);
  12290. c = 0;
  12291. loc = strstr(sLineWord, "chargingProfilePurpose");
  12292. memset(sstr ,0, ARRAY_SIZE(sstr));
  12293. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12294. {
  12295. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12296. c++;
  12297. }
  12298. sstr[c] = '\0';
  12299. strcpy(tempchargingProfilePurposeStr, sstr);
  12300. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12301. {
  12302. //------- not write to fptr2-------//
  12303. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12304. //clearflag = TRUE;
  12305. }
  12306. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12307. {
  12308. //------- not write to fptr2-------//
  12309. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12310. }
  12311. else if(stackLevelIsNULL == TRUE)
  12312. {
  12313. //Clear Whole File
  12314. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12315. clearflag = TRUE;
  12316. break;
  12317. }
  12318. else
  12319. {
  12320. fprintf(fptr2, sLineWord);//writing data into file
  12321. }
  12322. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12323. }
  12324. if(clearflag == TRUE)
  12325. {
  12326. fclose(fptr1);
  12327. fclose(fptr2);
  12328. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12329. system(str);
  12330. // clear temp file
  12331. sprintf(str,"rm -f %s",temp);
  12332. system(str);
  12333. }
  12334. else
  12335. {
  12336. fclose(fptr1);
  12337. fclose(fptr2);
  12338. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12339. system(str);
  12340. resultRename = rename(temp, chargingProfiles[k]);
  12341. if(resultRename == 0)
  12342. {
  12343. DEBUG_INFO("File ChargingProfile renamed successfully");
  12344. }
  12345. else
  12346. {
  12347. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  12348. }
  12349. if(comfirmstr[0]== 0)
  12350. {
  12351. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12352. }
  12353. //Check chargingProfile is empty file
  12354. /*------ Read the file ----------------*/
  12355. fptr1=fopen(chargingProfiles[k],"r");
  12356. ch=fgetc(fptr1);
  12357. rewind(fptr1);
  12358. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12359. if(ch!=EOF)
  12360. {
  12361. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12362. {
  12363. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12364. if(sLineWord[0]=='\0')
  12365. {
  12366. isEmptyFile = TRUE;
  12367. break;
  12368. }
  12369. else
  12370. {
  12371. isEmptyFile = FALSE;
  12372. break;
  12373. }
  12374. }
  12375. }
  12376. else
  12377. isEmptyFile = TRUE;
  12378. fclose(fptr1);
  12379. if(isEmptyFile == TRUE)
  12380. {
  12381. memset(str, 0, ARRAY_SIZE(str));
  12382. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12383. system(str);
  12384. }
  12385. /*------- End of reading ---------------*/
  12386. }
  12387. } // while(int k=0; k < ChargeProfileCount; k++)
  12388. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12389. end:
  12390. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12391. {
  12392. if(connectorIdInt == 0)
  12393. {
  12394. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12395. {
  12396. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12397. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12398. }
  12399. }
  12400. else
  12401. {
  12402. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12403. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  12404. }
  12405. }
  12406. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12407. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12408. return result;
  12409. }
  12410. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12411. {
  12412. mtrace();
  12413. int result = FAIL;
  12414. json_object *ClearDisplayMessage;
  12415. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12416. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12417. ClearDisplayMessage = json_tokener_parse(payload);
  12418. if(!is_error(ClearDisplayMessage))
  12419. {
  12420. // Required data
  12421. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12422. {
  12423. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12424. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12425. }
  12426. }
  12427. json_object_put(ClearDisplayMessage);
  12428. sendCostUpdatedConfirmation(uuid);
  12429. return result;
  12430. }
  12431. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12432. {
  12433. mtrace();
  12434. int result = FAIL;
  12435. json_object *ClearVariableMonitorin;
  12436. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12437. ClearVariableMonitorin = json_tokener_parse(payload);
  12438. if(!is_error(ClearVariableMonitorin))
  12439. {
  12440. // Required data
  12441. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12442. {
  12443. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  12444. {
  12445. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  12446. /*
  12447. * TODO:
  12448. * 1. Check response
  12449. */
  12450. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12451. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12452. }
  12453. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  12454. }
  12455. }
  12456. json_object_put(ClearVariableMonitorin);
  12457. return result;
  12458. }
  12459. int handleCostUpdatedRequest(char *uuid, char *payload)
  12460. {
  12461. mtrace();
  12462. int result = FAIL;
  12463. json_object *CostUpdate;
  12464. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12465. CostUpdate = json_tokener_parse(payload);
  12466. if(!is_error(CostUpdate))
  12467. {
  12468. // Required data
  12469. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12470. {
  12471. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12472. }
  12473. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12474. {
  12475. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12476. }
  12477. }
  12478. json_object_put(CostUpdate);
  12479. sendCostUpdatedConfirmation(uuid);
  12480. return result;
  12481. }
  12482. int handleCustomerInformationRequest(char *uuid, char *payload)
  12483. {
  12484. mtrace();
  12485. int result = FAIL;
  12486. json_object *CustomerInformation;
  12487. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12488. CustomerInformation = json_tokener_parse(payload);
  12489. if(!is_error(CustomerInformation))
  12490. {
  12491. // Required data
  12492. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12493. {
  12494. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12495. }
  12496. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12497. {
  12498. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12499. }
  12500. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12501. {
  12502. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12503. }
  12504. // Optional data
  12505. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12506. {
  12507. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12508. {
  12509. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12510. }
  12511. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12512. {
  12513. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12514. }
  12515. }
  12516. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12517. {
  12518. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12519. {
  12520. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12521. }
  12522. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12523. {
  12524. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12525. }
  12526. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12527. {
  12528. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12529. }
  12530. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12531. {
  12532. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12533. }
  12534. }
  12535. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12536. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12537. }
  12538. else
  12539. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12540. json_object_put(CustomerInformation);
  12541. sendCustomerInformationConfirmation(uuid);
  12542. return result;
  12543. }
  12544. void createFirmwareVersionByDataTransfer(void)
  12545. {
  12546. json_object *FirmwareDataTransfer = json_object_new_object();
  12547. // AC & DC model
  12548. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12549. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12550. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12551. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12552. // DC model
  12553. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12554. {
  12555. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12556. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12557. (gunType[3] != GUN_TYPE_UNKNOWN))
  12558. {
  12559. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12560. }
  12561. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  12562. {
  12563. // DS DM DW
  12564. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12565. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12566. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12567. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12568. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12569. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12570. }
  12571. else
  12572. {
  12573. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12574. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12575. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12576. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12577. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12578. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12579. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12580. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12581. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12582. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12583. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12584. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12585. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12586. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12587. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12588. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12589. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12590. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12591. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12592. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12593. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12594. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12595. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12596. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12597. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12598. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12599. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12600. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12601. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12602. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12603. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12604. }
  12605. }
  12606. // 4G model
  12607. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12608. {
  12609. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12610. }
  12611. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12612. json_object_put(FirmwareDataTransfer);
  12613. }
  12614. int handleDataTransferRequest(char *uuid, char *payload)
  12615. {
  12616. mtrace();
  12617. int result = PASS;
  12618. DEBUG_INFO("handleDataTransferRequest...\n");
  12619. if((uuid != NULL) && (payload != NULL))
  12620. {
  12621. json_object *DataTransfer;
  12622. DataTransfer = json_tokener_parse(payload);
  12623. if(!is_error(DataTransfer))
  12624. {
  12625. // Required data
  12626. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12627. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12628. // Optional data
  12629. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12630. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12631. if(json_object_object_get(DataTransfer, "data") != NULL)
  12632. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12633. result = PASS;
  12634. }
  12635. json_object_put(DataTransfer);
  12636. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12637. {
  12638. // Send all moudle firmware version on EVSE
  12639. createFirmwareVersionByDataTransfer();
  12640. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12641. }
  12642. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12643. {
  12644. system("/usr/bin/run_tmate_restart.sh &");
  12645. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12646. }
  12647. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12648. {
  12649. json_object *data;
  12650. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12651. if(!is_error(data))
  12652. {
  12653. 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))
  12654. {
  12655. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12656. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12657. if(json_object_object_get(data, "SOC") != NULL)
  12658. {
  12659. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12660. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12661. }
  12662. if(json_object_object_get(data, "Energy") != NULL)
  12663. {
  12664. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12665. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12666. }
  12667. if(json_object_object_get(data, "Duration") != NULL)
  12668. {
  12669. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12670. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12671. }
  12672. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12673. }
  12674. else
  12675. {
  12676. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12677. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12678. }
  12679. }
  12680. else
  12681. {
  12682. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12683. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12684. }
  12685. json_object_put(data);
  12686. }
  12687. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12688. {
  12689. json_object *data;
  12690. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12691. if(!is_error(data))
  12692. {
  12693. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12694. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12695. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12696. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12697. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12698. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12699. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12700. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12701. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12702. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12703. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12704. }
  12705. else
  12706. {
  12707. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12708. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12709. }
  12710. json_object_put(data);
  12711. }
  12712. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12713. {
  12714. json_object *data;
  12715. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12716. if(!is_error(data))
  12717. {
  12718. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12719. if(json_object_object_get(data, "Content_Type") != NULL)
  12720. {
  12721. 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))
  12722. {
  12723. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12724. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12725. {
  12726. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12727. }
  12728. }
  12729. else
  12730. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12731. }
  12732. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12733. }
  12734. else
  12735. {
  12736. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12737. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12738. }
  12739. json_object_put(data);
  12740. }
  12741. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12742. {
  12743. json_object *data;
  12744. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12745. if(!is_error(data))
  12746. {
  12747. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12748. if(json_object_object_get(data, "ConnectorId") != NULL)
  12749. {
  12750. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12751. }
  12752. if(json_object_object_get(data, "Page_Index") != NULL)
  12753. {
  12754. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  12755. }
  12756. if(json_object_object_get(data, "Duration") != NULL)
  12757. {
  12758. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  12759. }
  12760. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  12761. }
  12762. else
  12763. {
  12764. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12765. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12766. }
  12767. json_object_put(data);
  12768. }
  12769. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  12770. {
  12771. json_object *data;
  12772. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12773. if(!is_error(data))
  12774. {
  12775. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12776. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  12777. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  12778. {
  12779. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  12780. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  12781. else
  12782. {
  12783. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12784. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12785. }
  12786. }
  12787. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  12788. {
  12789. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  12790. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  12791. else
  12792. {
  12793. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12794. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12795. }
  12796. }
  12797. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  12798. {
  12799. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  12800. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  12801. else
  12802. {
  12803. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12804. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12805. }
  12806. }
  12807. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  12808. {
  12809. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  12810. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  12811. else
  12812. {
  12813. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12814. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12815. }
  12816. }
  12817. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  12818. {
  12819. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  12820. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  12821. else
  12822. {
  12823. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12824. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12825. }
  12826. }
  12827. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  12828. {
  12829. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  12830. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  12831. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  12832. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  12833. else
  12834. {
  12835. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12836. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12837. }
  12838. }
  12839. if(json_object_object_get(data, "isAuthentication") != NULL)
  12840. {
  12841. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  12842. {
  12843. case 0:
  12844. case 1:
  12845. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  12846. break;
  12847. default:
  12848. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12849. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12850. break;
  12851. }
  12852. }
  12853. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  12854. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12855. }
  12856. else
  12857. {
  12858. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12859. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12860. }
  12861. json_object_put(data);
  12862. }
  12863. else
  12864. {
  12865. // Can not find valid message id
  12866. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12867. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  12868. ,ShmOCPP20Data->DataTransfer[0].vendorId
  12869. ,ShmOCPP20Data->DataTransfer[0].messageId
  12870. ,ShmOCPP20Data->DataTransfer[0].data);
  12871. }
  12872. }
  12873. else
  12874. {
  12875. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  12876. result = FAIL;
  12877. }
  12878. sendDataTransferConfirmation(uuid, 0);
  12879. return result;
  12880. }
  12881. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12882. {
  12883. mtrace();
  12884. int result = FAIL;
  12885. json_object *DeleteCertificate;
  12886. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12887. DeleteCertificate = json_tokener_parse(payload);
  12888. if(!is_error(DeleteCertificate))
  12889. {
  12890. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  12891. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  12892. // Required data
  12893. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  12894. {
  12895. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  12896. {
  12897. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12898. }
  12899. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  12900. {
  12901. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12902. }
  12903. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  12904. {
  12905. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12906. }
  12907. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  12908. {
  12909. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12910. }
  12911. /*
  12912. * TODO:
  12913. * 1. Delete certification and response
  12914. */
  12915. if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA256]) != NULL)
  12916. {
  12917. }
  12918. else if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA384]) != NULL)
  12919. {
  12920. }
  12921. else
  12922. {
  12923. }
  12924. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  12925. }
  12926. }
  12927. else
  12928. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  12929. json_object_put(DeleteCertificate);
  12930. sendDeleteCertificateConfirmation(uuid);
  12931. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12932. return result;
  12933. }
  12934. int handleGetBaseReportRequest(char *uuid, char *payload)
  12935. {
  12936. mtrace();
  12937. int result = FAIL;
  12938. json_object *GetBaseRepor;
  12939. DEBUG_INFO("handleGetBaseReportRequest...\n");
  12940. GetBaseRepor = json_tokener_parse(payload);
  12941. if(!is_error(GetBaseRepor))
  12942. {
  12943. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  12944. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  12945. // Required data
  12946. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  12947. {
  12948. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  12949. }
  12950. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  12951. {
  12952. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  12953. }
  12954. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  12955. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12956. else
  12957. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12958. }
  12959. else
  12960. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12961. json_object_put(GetBaseRepor);
  12962. sendGetBaseReportConfirmation(uuid);
  12963. return result;
  12964. }
  12965. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  12966. {
  12967. mtrace();
  12968. int result = FAIL;
  12969. int gun_index = -1;
  12970. json_object *GetChargingProfiles;
  12971. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  12972. GetChargingProfiles = json_tokener_parse(payload);
  12973. if(!is_error(GetChargingProfiles))
  12974. {
  12975. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  12976. {
  12977. 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;
  12978. }
  12979. if(gun_index >-1)
  12980. {
  12981. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  12982. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  12983. // Required data
  12984. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  12985. {
  12986. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  12987. }
  12988. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  12989. {
  12990. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  12991. {
  12992. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  12993. }
  12994. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  12995. {
  12996. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  12997. }
  12998. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  12999. {
  13000. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  13001. {
  13002. 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)));
  13003. }
  13004. }
  13005. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  13006. {
  13007. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  13008. {
  13009. 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));
  13010. }
  13011. }
  13012. }
  13013. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  13014. }
  13015. else
  13016. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  13017. }
  13018. json_object_put(GetChargingProfiles);
  13019. sendGetChargingProfilesConfirmation(uuid, gun_index);
  13020. return result;
  13021. }
  13022. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  13023. {
  13024. mtrace();
  13025. int result = FAIL;
  13026. int connectorIdInt, durationInt;
  13027. char chargingRateUnitStr[4]={0};
  13028. char comfirmstr[20];
  13029. int confirmPeriods = 0;
  13030. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  13031. json_object *GetCompositeSchedule;
  13032. GetCompositeSchedule = json_tokener_parse(payload);
  13033. if(!is_error(GetCompositeSchedule))
  13034. {
  13035. // Required data
  13036. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  13037. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  13038. else
  13039. connectorIdInt = -1;
  13040. if(json_object_object_get(GetCompositeSchedule, "duration"))
  13041. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  13042. else
  13043. durationInt = 86400;
  13044. // Optional data
  13045. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  13046. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  13047. }
  13048. json_object_put(GetCompositeSchedule);
  13049. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  13050. if((connectorIdInt == 0) ||
  13051. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  13052. {
  13053. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  13054. struct ChargingProfileType tmpProfile[1];
  13055. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  13056. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  13057. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  13058. {
  13059. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  13060. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, FALSE);
  13061. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  13062. }
  13063. else
  13064. {
  13065. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  13066. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, TRUE);
  13067. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  13068. }
  13069. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13070. {
  13071. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  13072. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  13073. }
  13074. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct ChargingScheduleType));
  13075. strcpy((char *)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.startDateTime, (char *)tmpProfile[0].chargingSchedule[0].startSchedule);
  13076. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13077. {
  13078. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  13079. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  13080. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  13081. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  13082. (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))
  13083. {
  13084. confirmPeriods = idx;
  13085. break;
  13086. }
  13087. }
  13088. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  13089. {
  13090. confirmPeriods += 1;
  13091. }
  13092. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13093. }
  13094. else
  13095. {
  13096. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  13097. }
  13098. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  13099. return result;
  13100. }
  13101. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  13102. {
  13103. mtrace();
  13104. int result = FAIL;
  13105. json_object *GetDisplayMessages;
  13106. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  13107. GetDisplayMessages = json_tokener_parse(payload);
  13108. if(!is_error(GetDisplayMessages))
  13109. {
  13110. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  13111. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  13112. // Required data
  13113. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  13114. {
  13115. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  13116. }
  13117. // Optional data
  13118. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  13119. {
  13120. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  13121. }
  13122. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  13123. {
  13124. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  13125. }
  13126. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  13127. {
  13128. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  13129. {
  13130. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  13131. }
  13132. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  13133. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  13134. }
  13135. else
  13136. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  13137. }
  13138. json_object_put(GetDisplayMessages);
  13139. return result;
  13140. }
  13141. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13142. {
  13143. mtrace();
  13144. int result = FAIL;
  13145. json_object *GetInstalledCertificateIds;
  13146. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13147. GetInstalledCertificateIds = json_tokener_parse(payload);
  13148. if(!is_error(GetInstalledCertificateIds))
  13149. {
  13150. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  13151. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  13152. // Optional data
  13153. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  13154. {
  13155. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  13156. {
  13157. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  13158. /*
  13159. * TODO:
  13160. * 1. Get installed certificate info for response
  13161. */
  13162. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GRootCertificate]) != NULL)
  13163. {
  13164. }
  13165. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_MORootCertificate]) != NULL)
  13166. {
  13167. }
  13168. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_CSMSRootCertificate]) != NULL)
  13169. {
  13170. }
  13171. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GCertificateChain]) != NULL)
  13172. {
  13173. }
  13174. else
  13175. {
  13176. }
  13177. }
  13178. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13179. }
  13180. else
  13181. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13182. }
  13183. json_object_put(GetInstalledCertificateIds);
  13184. sendInstallCertificateConfirmation(uuid);
  13185. return result;
  13186. }
  13187. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  13188. {
  13189. mtrace();
  13190. int result = FAIL;
  13191. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  13192. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  13193. {
  13194. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  13195. localversion = 0;
  13196. }
  13197. else
  13198. {
  13199. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  13200. localversion = 0;
  13201. DB_getListVerion();
  13202. }
  13203. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  13204. sendGetLocalListVersionConfirmation(uuid);
  13205. return result;
  13206. }
  13207. static char fnamePlusPath[100]={0};
  13208. static char fnamePWithNoPath[60]={0};
  13209. void checkUploadLog(void)
  13210. {
  13211. FILE *fp;
  13212. /* Open the command for reading. */
  13213. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  13214. if (fp == NULL) {
  13215. printf("Failed to run command\n" );
  13216. exit(1);
  13217. }
  13218. int ftppathlen = 0;
  13219. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  13220. int i = 0;
  13221. /* Read the output a line at a time - output it. */
  13222. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  13223. if(i==0)
  13224. {
  13225. ftppathlen = strlen(fnamePlusPath);
  13226. printf("%s\n", fnamePlusPath);
  13227. fnamePlusPath[ftppathlen]='\0';
  13228. break;
  13229. }
  13230. i= i+1;
  13231. }
  13232. /* close */
  13233. pclose(fp);
  13234. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  13235. {
  13236. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  13237. {
  13238. fnamePlusPath[k]='\0';
  13239. }
  13240. }
  13241. i=1;
  13242. //char fname[60]={0};
  13243. while(i < ftppathlen)
  13244. {
  13245. int len=ftppathlen-i;
  13246. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  13247. {
  13248. printf("compare '/' all right\n");
  13249. break;
  13250. }
  13251. i=i+1;
  13252. }
  13253. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  13254. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  13255. fnamePWithNoPath[i+1] = '\0';
  13256. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  13257. {
  13258. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  13259. {
  13260. fnamePWithNoPath[j]='\0';
  13261. }
  13262. }
  13263. FILE* fp1 = fopen(fnamePlusPath, "r");
  13264. if (fp1)
  13265. {
  13266. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  13267. // file exists
  13268. fclose(fp1);
  13269. }
  13270. else
  13271. {
  13272. // file doesn't exist
  13273. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  13274. }
  13275. }
  13276. void* GetLogProcess(void* data)
  13277. {
  13278. th_GetLog = pthread_self();
  13279. pthread_detach(pthread_self());
  13280. mtrace();
  13281. int requestId, retriesInt=0, retryIntervalInt=0;
  13282. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  13283. 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};
  13284. int port=0;
  13285. int isSuccess = FALSE;
  13286. char ftpbuf[1024]={0};
  13287. char cmdBuf[2048];
  13288. struct tm *tmNow;
  13289. time_t CurrentTime;
  13290. struct tm tmStart;
  13291. struct tm tmStop;
  13292. CurrentTime = time(NULL);
  13293. tmNow=localtime(&CurrentTime);
  13294. uint16_t targetYear, targetMonth;
  13295. json_object *GetLog;
  13296. DEBUG_INFO("GetGetProcess...\n");
  13297. GetLog = json_tokener_parse(data);
  13298. if(!is_error(GetLog))
  13299. {
  13300. // Required data
  13301. if(json_object_object_get(GetLog, "requestId") != NULL)
  13302. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13303. if(json_object_object_get(GetLog, "logType") != NULL)
  13304. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13305. if(json_object_object_get(GetLog, "log") != NULL)
  13306. {
  13307. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  13308. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13309. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13310. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13311. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13312. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13313. }
  13314. // Optional data
  13315. if(json_object_object_get(GetLog, "retries") != NULL)
  13316. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13317. else
  13318. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  13319. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13320. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13321. else
  13322. retryIntervalInt = 30;
  13323. }
  13324. json_object_put(GetLog);
  13325. ShmOCPP20Data->GetLog.requestId = requestId;
  13326. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  13327. {
  13328. /*
  13329. * TODO:
  13330. * 1. Pack security log
  13331. */
  13332. }
  13333. else
  13334. {
  13335. // Pack log to compress file
  13336. 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) &&
  13337. (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))
  13338. {
  13339. // Pack system log
  13340. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13341. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13342. targetYear = tmStart.tm_year;
  13343. targetMonth = tmStart.tm_mon;
  13344. do
  13345. {
  13346. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13347. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13348. if(targetMonth+1>=13)
  13349. {
  13350. targetYear += 1;
  13351. targetMonth = 1;
  13352. }
  13353. else
  13354. {
  13355. targetMonth += 1;
  13356. }
  13357. }while((targetYear < (tmNow->tm_year+1900)) ||
  13358. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13359. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13360. system(cmdBuf);
  13361. // Pack charging & event log
  13362. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13363. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13364. targetYear = tmStart.tm_year;
  13365. targetMonth = tmStart.tm_mon;
  13366. do
  13367. {
  13368. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13369. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  13370. if(targetMonth+1>=13)
  13371. {
  13372. targetYear += 1;
  13373. targetMonth = 1;
  13374. }
  13375. else
  13376. {
  13377. targetMonth += 1;
  13378. }
  13379. }while((targetYear < (tmNow->tm_year+1900)) ||
  13380. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13381. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13382. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13383. system(cmdBuf);
  13384. // Combine log file
  13385. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13386. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13387. }
  13388. else
  13389. {
  13390. system("exec /root/logPackTools 'log' 6");
  13391. }
  13392. }
  13393. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13394. system(cmdBuf);
  13395. checkUploadLog();
  13396. //****************location*******************/
  13397. if(strcmp(remoteLocation,"")==0)
  13398. {
  13399. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13400. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13401. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13402. goto end;
  13403. }
  13404. memset(protocol, 0, ARRAY_SIZE(protocol));
  13405. memset(user, 0, ARRAY_SIZE(user) );
  13406. memset(password, 0, ARRAY_SIZE(password));
  13407. memset(host, 0, ARRAY_SIZE(host));
  13408. memset(path, 0, ARRAY_SIZE(path));
  13409. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13410. memset(host1, 0, ARRAY_SIZE(host1));
  13411. memset(path1, 0, ARRAY_SIZE(path1));
  13412. /*location: ftp://user:password@host:port/path*/
  13413. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13414. if((access(fnamePlusPath,F_OK))!=-1)
  13415. {
  13416. DEBUG_INFO("fnamePlusPath exist.\n");
  13417. }
  13418. else
  13419. {
  13420. DEBUG_INFO("fnamePlusPath not exist!\n");
  13421. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13422. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13423. goto end;
  13424. }
  13425. if(strchr(remoteLocation,'@')==NULL)
  13426. {
  13427. sscanf(remoteLocation,
  13428. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13429. protocol, host, &port, path);
  13430. strcpy(user,"anonymous");
  13431. strcpy(password,"");
  13432. }
  13433. else
  13434. {
  13435. //DEBUG_INFO("pch=%s\n", pch);
  13436. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13437. protocol, user, password, host, &port, path);
  13438. }
  13439. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13440. {
  13441. DEBUG_INFO("protocol is not ftp/http ! \n");
  13442. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13443. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13444. goto end;
  13445. }
  13446. if(strncmp(remoteLocation,"http", 4) == 0)
  13447. {
  13448. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13449. sprintf(ftppath,"/%s", path);
  13450. do
  13451. {
  13452. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13453. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13454. sleep(3);
  13455. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  13456. if(!isSuccess)
  13457. {
  13458. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13459. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13460. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13461. sleep(retryIntervalInt);
  13462. }
  13463. else
  13464. {
  13465. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13466. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13467. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13468. }
  13469. retriesInt--;
  13470. }while((isSuccess == 0)&&(retriesInt >= 0));
  13471. }
  13472. else
  13473. {
  13474. sscanf(host,"%[^/]%s",host1, path1);
  13475. if(strlen(path) > 0)
  13476. sprintf(ftppath,"/%s", path);
  13477. else
  13478. sprintf(ftppath,"/%s", path1);
  13479. int ftppathlen=strlen(ftppath);
  13480. int i=1;
  13481. char filenametemp[50];
  13482. while(i < ftppathlen)
  13483. {
  13484. int len=ftppathlen-i;
  13485. if(ftppath[len]== 47) // '/' ascll code: 47
  13486. {
  13487. DEBUG_INFO("find '/' all right\n");
  13488. break;
  13489. }
  13490. i=i+1;
  13491. }
  13492. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13493. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13494. filenametemp[i+1] = 0;
  13495. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13496. if(port == 0)
  13497. port = 21;
  13498. do
  13499. {
  13500. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13501. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13502. sleep(3);
  13503. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  13504. if(!isSuccess)
  13505. {
  13506. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13507. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13508. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13509. sleep(retryIntervalInt);
  13510. }
  13511. else
  13512. {
  13513. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13514. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13515. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13516. }
  13517. retriesInt--;
  13518. }while((!isSuccess)&&(retriesInt >= 0));
  13519. }
  13520. end:
  13521. system("rm -f /mnt/*");
  13522. sleep(5);
  13523. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  13524. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13525. interLock.isGetLogGoing = OFF;
  13526. pthread_exit(NULL);
  13527. }
  13528. int handleGetLogRequest(char *uuid, char *payload)
  13529. {
  13530. mtrace();
  13531. int result = FAIL;
  13532. char fName[258];
  13533. time_t CurrentTime;
  13534. struct tm *tm;
  13535. pthread_t th_Status;
  13536. DEBUG_INFO("handleGetLogRequest...\n");
  13537. CurrentTime = time(NULL);
  13538. tm = localtime(&CurrentTime);
  13539. 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);
  13540. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  13541. if(interLock.isGetLogGoing)
  13542. {
  13543. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  13544. isCancelUploadLog = TRUE;
  13545. pthread_cancel(th_GetLog);
  13546. interLock.isGetLogGoing = OFF;
  13547. sleep(1);
  13548. isCancelUploadLog = OFF;
  13549. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_AcceptedCanceled]);
  13550. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13551. sleep(1);
  13552. }
  13553. else
  13554. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  13555. sendGetLogConfirmation(uuid);
  13556. if(!interLock.isGetLogGoing)
  13557. {
  13558. interLock.isGetLogGoing = ON;
  13559. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  13560. sleep(1);
  13561. }
  13562. else
  13563. {
  13564. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  13565. }
  13566. return result;
  13567. }
  13568. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  13569. {
  13570. mtrace();
  13571. int result = FAIL;
  13572. json_object *GetMonitoringReport;
  13573. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  13574. GetMonitoringReport = json_tokener_parse(payload);
  13575. if(!is_error(GetMonitoringReport))
  13576. {
  13577. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  13578. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  13579. // Required data
  13580. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  13581. {
  13582. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  13583. }
  13584. // Optional data
  13585. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  13586. {
  13587. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  13588. }
  13589. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  13590. {
  13591. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  13592. {
  13593. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  13594. {
  13595. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  13596. {
  13597. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  13598. {
  13599. 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")));
  13600. }
  13601. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13602. {
  13603. 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")));
  13604. }
  13605. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13606. {
  13607. 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)
  13608. {
  13609. 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"));
  13610. }
  13611. 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)
  13612. {
  13613. 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"));
  13614. }
  13615. }
  13616. }
  13617. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  13618. {
  13619. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13620. {
  13621. 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")));
  13622. }
  13623. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13624. {
  13625. 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")));
  13626. }
  13627. }
  13628. }
  13629. }
  13630. }
  13631. }
  13632. json_object_put(GetMonitoringReport);
  13633. /*
  13634. * TODO:
  13635. * 1. Response result
  13636. */
  13637. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13638. sendGetMonitoringReportConfirmation(uuid);
  13639. return result;
  13640. }
  13641. int handleGetReportRequest(char *uuid, char *payload)
  13642. {
  13643. mtrace();
  13644. int result = FAIL;
  13645. json_object *GetReport;
  13646. DEBUG_INFO("handleGetReportRequest...\n");
  13647. GetReport = json_tokener_parse(payload);
  13648. if(!is_error(GetReport))
  13649. {
  13650. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  13651. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  13652. // Required data
  13653. if(json_object_object_get(GetReport, "requestId") != NULL)
  13654. {
  13655. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  13656. }
  13657. // Optional data
  13658. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  13659. {
  13660. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  13661. }
  13662. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  13663. {
  13664. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  13665. {
  13666. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  13667. {
  13668. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  13669. {
  13670. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  13671. {
  13672. 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")));
  13673. }
  13674. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  13675. {
  13676. 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")));
  13677. }
  13678. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  13679. {
  13680. 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)
  13681. {
  13682. 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"));
  13683. }
  13684. 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)
  13685. {
  13686. 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"));
  13687. }
  13688. }
  13689. }
  13690. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  13691. {
  13692. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  13693. {
  13694. 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")));
  13695. }
  13696. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  13697. {
  13698. 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")));
  13699. }
  13700. }
  13701. }
  13702. }
  13703. }
  13704. }
  13705. json_object_put(GetReport);
  13706. /*
  13707. * TODO:
  13708. * 1. Response result
  13709. */
  13710. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13711. sendGetReportConfirmation(uuid);
  13712. return result;
  13713. }
  13714. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  13715. {
  13716. mtrace();
  13717. int result = FAIL;
  13718. int8_t gun_index = -1;
  13719. json_object *GetTransactionStatus;
  13720. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  13721. GetTransactionStatus = json_tokener_parse(payload);
  13722. if(!is_error(GetTransactionStatus))
  13723. {
  13724. /*
  13725. * TODO:
  13726. * 1. Check transaction locate which connector
  13727. */
  13728. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  13729. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  13730. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  13731. {
  13732. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  13733. }
  13734. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  13735. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  13736. }
  13737. json_object_put(GetTransactionStatus);
  13738. sendGetTransactionStatusConfirmation(uuid, gun_index);
  13739. return result;
  13740. }
  13741. int handleGetVariablesRequest(char *uuid, char *payload)
  13742. {
  13743. mtrace();
  13744. int result = FAIL;
  13745. int isUnknownComponent = TRUE;
  13746. json_object *GetVariables;
  13747. DEBUG_INFO("handleGetVariablesRequest...\n");
  13748. GetVariables = json_tokener_parse(payload);
  13749. if(!is_error(GetVariables))
  13750. {
  13751. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  13752. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  13753. // Required data
  13754. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  13755. {
  13756. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  13757. {
  13758. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  13759. {
  13760. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  13761. {
  13762. 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")));
  13763. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  13764. }
  13765. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  13766. {
  13767. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  13768. }*/
  13769. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  13770. {
  13771. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  13772. {
  13773. 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")));
  13774. }
  13775. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  13776. {
  13777. 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")));
  13778. }
  13779. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  13780. {
  13781. 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)
  13782. {
  13783. 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"));
  13784. }
  13785. 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)
  13786. {
  13787. 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"));
  13788. }
  13789. }
  13790. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  13791. }
  13792. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  13793. {
  13794. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  13795. {
  13796. 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")));
  13797. }
  13798. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  13799. {
  13800. 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")));
  13801. }
  13802. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  13803. }
  13804. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  13805. {
  13806. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  13807. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  13808. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  13809. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  13810. {
  13811. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  13812. isUnknownComponent = FALSE;
  13813. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  13814. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  13815. {
  13816. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  13817. break;
  13818. }
  13819. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  13820. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  13821. {
  13822. struct sysinfo s_info;
  13823. int error = sysinfo(&s_info);
  13824. if(error != 0)
  13825. {
  13826. DEBUG_WARN("System uptime get error: %d\n", error);
  13827. }
  13828. else
  13829. {
  13830. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  13831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  13832. }
  13833. }
  13834. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  13835. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  13836. {
  13837. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  13838. }
  13839. else
  13840. {
  13841. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  13842. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  13843. }
  13844. break;
  13845. }
  13846. else
  13847. {
  13848. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  13849. {
  13850. isUnknownComponent = FALSE;
  13851. }
  13852. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  13853. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  13854. }
  13855. }
  13856. if(isUnknownComponent == TRUE)
  13857. {
  13858. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  13859. }
  13860. }
  13861. }
  13862. }
  13863. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  13864. }
  13865. json_object_put(GetVariables);
  13866. return result;
  13867. }
  13868. int handleInstallCertificateRequest(char *uuid, char *payload)
  13869. {
  13870. mtrace();
  13871. int result = FAIL;
  13872. json_object *InstallCertificate;
  13873. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13874. InstallCertificate = json_tokener_parse(payload);
  13875. if(!is_error(InstallCertificate))
  13876. {
  13877. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  13878. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  13879. // Required data
  13880. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  13881. {
  13882. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13883. }
  13884. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  13885. {
  13886. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13887. }
  13888. }
  13889. json_object_put(InstallCertificate);
  13890. /*
  13891. * TODO:
  13892. * 1. Install certification preocess and response
  13893. */
  13894. if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]))
  13895. {
  13896. }
  13897. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]))
  13898. {
  13899. }
  13900. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]))
  13901. {
  13902. }
  13903. else
  13904. {
  13905. }
  13906. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13907. sendInstallCertificateConfirmation(uuid);
  13908. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13909. return result;
  13910. }
  13911. int handlePublishFirmwareRequest(char *uuid, char *payload)
  13912. {
  13913. mtrace();
  13914. int result = FAIL;
  13915. json_object *PublishFirmware;
  13916. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  13917. PublishFirmware = json_tokener_parse(payload);
  13918. if(!is_error(PublishFirmware))
  13919. {
  13920. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  13921. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  13922. // Required data
  13923. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  13924. {
  13925. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  13926. }
  13927. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  13928. {
  13929. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  13930. }
  13931. // Optional data
  13932. if(json_object_object_get(PublishFirmware, "location") != NULL)
  13933. {
  13934. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  13935. }
  13936. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  13937. {
  13938. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  13939. }
  13940. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  13941. {
  13942. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  13943. }
  13944. }
  13945. json_object_put(PublishFirmware);
  13946. /*
  13947. * TODO:
  13948. * 1. Publish firmware preocess and response
  13949. */
  13950. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13951. sendPublishFirmwareConfirmation(uuid);
  13952. return result;
  13953. }
  13954. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  13955. {
  13956. mtrace();
  13957. int result = FAIL;
  13958. int8_t connectorIdx = -1;
  13959. uint8_t tempIndex;
  13960. uint8_t isOverConnectorMax = FALSE;
  13961. uint8_t isPeriodOverMax = FALSE;
  13962. uint8_t isTxProfile = TRUE;
  13963. uint8_t isAllowStart = TRUE;
  13964. uint8_t filename[128]={0};
  13965. char cmdBuf[128];
  13966. FILE *filePtr;
  13967. json_object *RemoteStartTransaction;
  13968. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  13969. RemoteStartTransaction = json_tokener_parse(payload);
  13970. if(!is_error(RemoteStartTransaction))
  13971. {
  13972. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  13973. {
  13974. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  13975. {
  13976. connectorIdx = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  13977. }
  13978. else
  13979. {
  13980. isOverConnectorMax = TRUE;
  13981. DEBUG_WARN("Connector id shall not equal 0 and less than max connector id.\n");
  13982. }
  13983. }
  13984. else
  13985. {
  13986. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13987. {
  13988. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  13989. {
  13990. connectorIdx = (idx+1);
  13991. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdx);
  13992. break;
  13993. }
  13994. }
  13995. }
  13996. if(isOverConnectorMax == FALSE)
  13997. {
  13998. if(connectorIdx > 0)
  13999. {
  14000. DEBUG_INFO("Connector id: %d\n", connectorIdx);
  14001. memset(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1], 0, sizeof(struct RequestStartTransaction_20));
  14002. memcpy(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid));
  14003. // Required data
  14004. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  14005. {
  14006. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  14007. }
  14008. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  14009. {
  14010. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  14011. {
  14012. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  14013. }
  14014. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  14015. {
  14016. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  14017. }
  14018. }
  14019. // Optional data
  14020. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  14021. {
  14022. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  14023. {
  14024. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  14025. }
  14026. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  14027. {
  14028. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  14029. }
  14030. }
  14031. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  14032. {
  14033. // Check periods is over max configuration
  14034. 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))
  14035. {
  14036. isPeriodOverMax = TRUE;
  14037. }
  14038. // Check profile purpose is TxProfile
  14039. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14040. {
  14041. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  14042. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  14043. }
  14044. else
  14045. {
  14046. isTxProfile = FALSE;
  14047. }
  14048. }
  14049. //check Transaction active
  14050. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  14051. {
  14052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14053. {
  14054. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  14055. }
  14056. else
  14057. {
  14058. tempIndex = (connectorIdx-1);
  14059. }
  14060. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14061. {
  14062. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  14063. {
  14064. 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))
  14065. {
  14066. //Reserved
  14067. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  14068. }
  14069. 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))
  14070. {
  14071. //Reserved
  14072. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  14073. isAllowStart = FALSE;
  14074. }
  14075. else
  14076. {
  14077. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14078. {
  14079. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  14080. isAllowStart = FALSE;
  14081. }
  14082. }//END FOR ELSE
  14083. }
  14084. }// END FOR CHAdeMO_QUANTITY
  14085. }
  14086. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  14087. {
  14088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14089. {
  14090. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  14091. }
  14092. else
  14093. {
  14094. tempIndex = (connectorIdx-1);
  14095. }
  14096. for (int index = 0; index < CCS_QUANTITY; index++)
  14097. {
  14098. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14099. {
  14100. 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))
  14101. {
  14102. //Reserved
  14103. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  14104. }
  14105. 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))
  14106. {
  14107. //Reserved
  14108. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  14109. isAllowStart = FALSE;
  14110. }
  14111. else
  14112. {
  14113. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14114. {
  14115. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  14116. isAllowStart = FALSE;
  14117. }
  14118. }// END FOR ELSE
  14119. }
  14120. }// END FOR CCS_QUANTITY
  14121. }
  14122. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  14123. {
  14124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14125. {
  14126. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  14127. }
  14128. else
  14129. {
  14130. tempIndex = (connectorIdx-1);
  14131. }
  14132. for (int index = 0; index < GB_QUANTITY; index++)
  14133. {
  14134. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  14135. {
  14136. 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))
  14137. {
  14138. //Reserved
  14139. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  14140. }
  14141. 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))
  14142. {
  14143. //Reserved
  14144. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  14145. isAllowStart = FALSE;
  14146. }
  14147. else
  14148. {
  14149. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14150. {
  14151. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  14152. isAllowStart = FALSE;
  14153. }
  14154. }// END FOR ELSE
  14155. }
  14156. } // END FOR GB_QUANTITY
  14157. }
  14158. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  14159. {
  14160. tempIndex = (connectorIdx-1);
  14161. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14162. {
  14163. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  14164. {
  14165. 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))
  14166. {
  14167. //Reserved
  14168. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  14169. }
  14170. 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))
  14171. {
  14172. //Reserved
  14173. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  14174. isAllowStart = FALSE;
  14175. }
  14176. else
  14177. {
  14178. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14179. {
  14180. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  14181. isAllowStart = FALSE;
  14182. }
  14183. }// END FOR ELSE
  14184. }
  14185. } // END FOR GB_QUANTITY
  14186. }
  14187. else
  14188. {
  14189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14190. {
  14191. tempIndex = 2;
  14192. }
  14193. else
  14194. {
  14195. tempIndex = (connectorIdx-1);
  14196. }
  14197. for (int index = 0; index < AC_QUANTITY; index++)
  14198. {
  14199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  14200. {
  14201. 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))
  14202. {
  14203. //Reserved
  14204. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  14205. }
  14206. 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))
  14207. {
  14208. //Reserved
  14209. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  14210. isAllowStart = FALSE;
  14211. }
  14212. else
  14213. {
  14214. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14215. {
  14216. DEBUG_WARN("AC connector not allow start cause busy.\n");
  14217. isAllowStart = FALSE;
  14218. }
  14219. }//END FOR ELSE
  14220. }
  14221. }// END FOR AC_QUANTITY
  14222. }
  14223. }
  14224. else
  14225. {
  14226. DEBUG_INFO("Connector id does not specific.\n");
  14227. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14228. {
  14229. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  14230. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  14231. // Required data
  14232. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  14233. {
  14234. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  14235. }
  14236. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  14237. {
  14238. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  14239. {
  14240. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  14241. }
  14242. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  14243. {
  14244. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  14245. }
  14246. }
  14247. // Optional data
  14248. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  14249. {
  14250. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  14251. {
  14252. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  14253. }
  14254. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  14255. {
  14256. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  14257. }
  14258. }
  14259. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  14260. {
  14261. // Check periods is over max configuration
  14262. 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))
  14263. {
  14264. isPeriodOverMax = TRUE;
  14265. }
  14266. // Check profile purpose is TxProfile
  14267. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14268. {
  14269. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  14270. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14271. }
  14272. else
  14273. {
  14274. isTxProfile = FALSE;
  14275. }
  14276. }
  14277. }
  14278. }
  14279. }
  14280. // Profile replace or add info
  14281. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  14282. {
  14283. if(connectorIdx != -1)
  14284. {
  14285. if(strlen((char*)filename) > 0)
  14286. {
  14287. // Save profile to file
  14288. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  14289. system(cmdBuf);
  14290. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", connectorIdx);
  14291. filePtr = fopen((char*)filename, "w");
  14292. 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));
  14293. fclose(filePtr);
  14294. }
  14295. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  14296. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14297. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_transactionId);
  14298. result = PASS;
  14299. }
  14300. else
  14301. {
  14302. uint8_t isHasIdleConnector = FALSE;
  14303. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14304. {
  14305. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  14306. {
  14307. isHasIdleConnector = TRUE;
  14308. break;
  14309. }
  14310. }
  14311. if((isHasIdleConnector == TRUE) && !ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14312. {
  14313. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  14314. if(strlen((char*)filename) > 0)
  14315. {
  14316. // Save profile to file
  14317. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  14318. system(cmdBuf);
  14319. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  14320. filePtr = fopen((char*)filename, "w");
  14321. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  14322. fclose(filePtr);
  14323. }
  14324. refreshStartTimer(&clientTime.RemoteStartWait);
  14325. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  14326. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14327. {
  14328. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14329. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  14330. }
  14331. result = PASS;
  14332. }
  14333. else
  14334. {
  14335. DEBUG_INFO("There is not any connector is idle.\n");
  14336. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  14337. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14338. }
  14339. }
  14340. }
  14341. else
  14342. {
  14343. if(isOverConnectorMax != FALSE)
  14344. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  14345. if(isPeriodOverMax)
  14346. DEBUG_WARN("Profile periods quantity is over spec.\n");
  14347. if(!isTxProfile)
  14348. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  14349. if(!isAllowStart)
  14350. DEBUG_WARN("Target connector does not allow start.\n");
  14351. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((connectorIdx-1)<0?0:(connectorIdx-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  14352. }
  14353. }
  14354. json_object_put(RemoteStartTransaction);
  14355. sendRemoteStartTransactionConfirmation(uuid, ((connectorIdx-1)<0?0:(connectorIdx-1)));
  14356. return result;
  14357. }
  14358. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  14359. {
  14360. mtrace();
  14361. int result = FAIL;
  14362. int match = FALSE;
  14363. int GunNO = 0;
  14364. int tempIndex = 0;
  14365. char transactionIdStr[37];
  14366. int transactionIdIsNULL= TRUE;
  14367. json_object *RemoteStopTransaction;
  14368. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  14369. if(server_pending == TRUE)
  14370. {
  14371. return 0;
  14372. }
  14373. RemoteStopTransaction = json_tokener_parse(payload);
  14374. if(!is_error(RemoteStopTransaction))
  14375. {
  14376. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  14377. {
  14378. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  14379. transactionIdIsNULL = FALSE;
  14380. }
  14381. }
  14382. json_object_put(RemoteStopTransaction);
  14383. if(transactionIdIsNULL == FALSE)
  14384. {
  14385. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14386. {
  14387. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  14388. {
  14389. //check Transaction active
  14390. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14391. {
  14392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14393. {
  14394. tempIndex = ((gun_index==2) ? 1: 0);
  14395. }
  14396. else
  14397. {
  14398. tempIndex = gun_index;
  14399. }
  14400. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14401. {
  14402. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14403. {
  14404. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14405. {
  14406. match = TRUE;
  14407. GunNO = gun_index;
  14408. }
  14409. }
  14410. }// END FOR CHAdeMO_QUANTITY
  14411. }
  14412. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14413. {
  14414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14415. {
  14416. tempIndex = ((gun_index==2) ? 1: 0);
  14417. }
  14418. else
  14419. {
  14420. tempIndex = gun_index;
  14421. }
  14422. for (int index = 0; index < CCS_QUANTITY; index++)
  14423. {
  14424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14425. {
  14426. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14427. {
  14428. match = TRUE;
  14429. GunNO = gun_index;
  14430. }
  14431. }
  14432. }// END FOR CCS_QUANTITY
  14433. }
  14434. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14435. {
  14436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14437. {
  14438. tempIndex = ((gun_index==2) ? 1: 0);
  14439. }
  14440. else
  14441. {
  14442. tempIndex = gun_index;
  14443. }
  14444. for (int index = 0; index < GB_QUANTITY; index++)
  14445. {
  14446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14447. {
  14448. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14449. {
  14450. match = TRUE;
  14451. GunNO = gun_index;
  14452. }
  14453. }
  14454. }// END FOR GB_QUANTITY
  14455. }
  14456. else if(gunType[gun_index] == GUN_TYPE_DO)
  14457. {
  14458. tempIndex = gun_index;
  14459. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14460. {
  14461. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14462. {
  14463. 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
  14464. {
  14465. match = TRUE;
  14466. GunNO = gun_index;
  14467. }
  14468. }
  14469. }// END FOR GB_QUANTITY
  14470. }
  14471. else
  14472. {
  14473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14474. {
  14475. tempIndex = 2;
  14476. }
  14477. else
  14478. {
  14479. tempIndex = gun_index;
  14480. }
  14481. for (int index = 0; index < AC_QUANTITY; index++)
  14482. {
  14483. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14484. {
  14485. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  14486. {
  14487. match = TRUE;
  14488. GunNO = gun_index;
  14489. }
  14490. }
  14491. }// END FOR CHAdeMO_QUANTITY
  14492. } // END FOR AC ELSE
  14493. }// CHECK IF ResponseTransactionId == transactionIdInt
  14494. }//END FOR
  14495. if( match == TRUE)
  14496. {
  14497. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  14498. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  14499. }
  14500. else
  14501. {
  14502. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14503. }
  14504. }
  14505. else
  14506. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  14507. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  14508. return result;
  14509. }
  14510. int handleReserveNowRequest(char *uuid, char *payload)
  14511. {
  14512. mtrace();
  14513. int result = FAIL;
  14514. int connectorIdInt=0, reservationIdInt=0;
  14515. int tempIndex = 0;
  14516. json_object *ReserveNow;
  14517. DEBUG_INFO("handleReserveNowRequest ...\n");
  14518. ReserveNow = json_tokener_parse(payload);
  14519. if(!is_error(ReserveNow))
  14520. {
  14521. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  14522. {
  14523. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  14524. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  14525. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  14526. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  14527. }
  14528. // Required data
  14529. if(json_object_object_get(ReserveNow, "id") != NULL)
  14530. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "id"));
  14531. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  14532. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  14533. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  14534. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  14535. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  14536. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  14537. // Optional data
  14538. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  14539. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  14540. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  14541. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  14542. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  14543. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  14544. result = PASS;
  14545. }
  14546. json_object_put(ReserveNow);
  14547. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14548. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  14549. {
  14550. //check Transaction active
  14551. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  14552. {
  14553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14554. {
  14555. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14556. }
  14557. else
  14558. {
  14559. tempIndex = connectorIdInt -1;
  14560. }
  14561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14562. {
  14563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14564. {
  14565. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  14566. {
  14567. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  14568. {
  14569. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14570. {
  14571. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  14572. {
  14573. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14574. }
  14575. else
  14576. {
  14577. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14578. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14579. }
  14580. }
  14581. 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'))
  14582. {
  14583. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14584. }
  14585. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14586. {
  14587. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14588. }
  14589. else
  14590. {
  14591. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14592. }
  14593. }
  14594. 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
  14595. {
  14596. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14597. }
  14598. }
  14599. else
  14600. {
  14601. //replace reservation
  14602. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14603. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14604. }
  14605. }
  14606. } // END FOR CHAdeMO_QUANTITY
  14607. }
  14608. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  14609. {
  14610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14611. {
  14612. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14613. }
  14614. else
  14615. {
  14616. tempIndex = connectorIdInt -1;
  14617. }
  14618. for (int index = 0; index < CCS_QUANTITY; index++)
  14619. {
  14620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14621. {
  14622. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  14623. {
  14624. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14625. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  14626. {
  14627. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14628. {
  14629. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  14630. {
  14631. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14632. }
  14633. else
  14634. {
  14635. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14636. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14637. }
  14638. }
  14639. 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'))
  14640. {
  14641. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14642. }
  14643. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  14644. {
  14645. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14646. }
  14647. else
  14648. {
  14649. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14650. }
  14651. }
  14652. 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
  14653. {
  14654. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14655. }
  14656. }
  14657. else
  14658. {
  14659. //replace reservation
  14660. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14661. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14662. }
  14663. }
  14664. } // END FOR CCS_QUANTITY
  14665. }
  14666. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  14667. {
  14668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14669. {
  14670. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14671. }
  14672. else
  14673. {
  14674. tempIndex = connectorIdInt -1;
  14675. }
  14676. for (int index = 0; index < GB_QUANTITY; index++)
  14677. {
  14678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14679. {
  14680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  14681. {
  14682. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14683. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  14684. {
  14685. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14686. {
  14687. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  14688. {
  14689. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14690. }
  14691. else
  14692. {
  14693. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14694. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14695. }
  14696. }
  14697. 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'))
  14698. {
  14699. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14700. }
  14701. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14702. {
  14703. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14704. }
  14705. else
  14706. {
  14707. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14708. }
  14709. }
  14710. 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
  14711. {
  14712. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14713. }
  14714. }
  14715. else
  14716. {
  14717. //replace reservation
  14718. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14719. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14720. }
  14721. }
  14722. }// END FOR GB_QUANTITY
  14723. }
  14724. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  14725. {
  14726. tempIndex = connectorIdInt -1;
  14727. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14728. {
  14729. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14730. {
  14731. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  14732. {
  14733. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  14734. 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
  14735. {
  14736. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14737. {
  14738. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  14739. {
  14740. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14741. }
  14742. else
  14743. {
  14744. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14745. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14746. }
  14747. }
  14748. 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'))
  14749. {
  14750. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14751. }
  14752. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14753. {
  14754. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14755. }
  14756. else
  14757. {
  14758. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14759. }
  14760. }
  14761. 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
  14762. {
  14763. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14764. }
  14765. }
  14766. else
  14767. {
  14768. //replace reservation
  14769. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14770. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14771. }
  14772. }
  14773. }// END FOR DO_QUANTITY
  14774. }
  14775. else
  14776. {
  14777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14778. {
  14779. tempIndex = 2;
  14780. }
  14781. else
  14782. {
  14783. tempIndex = (connectorIdInt -1);
  14784. }
  14785. for (int index = 0; index < AC_QUANTITY; index++)
  14786. {
  14787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14788. {
  14789. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  14790. {
  14791. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  14792. {
  14793. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14794. {
  14795. 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))
  14796. {
  14797. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14798. }
  14799. else
  14800. {
  14801. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14802. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14803. }
  14804. }
  14805. 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'))
  14806. {
  14807. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14808. }
  14809. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  14810. {
  14811. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14812. }
  14813. else
  14814. {
  14815. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14816. }
  14817. }
  14818. 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
  14819. {
  14820. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14821. }
  14822. }
  14823. else
  14824. {
  14825. //replace reservation
  14826. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  14827. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14828. }
  14829. }
  14830. } // END FOR AC_QUANTITY
  14831. }
  14832. }
  14833. else if(connectorIdInt == 0)
  14834. {
  14835. //check Transaction active
  14836. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14837. {
  14838. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  14839. {
  14840. 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'))
  14841. {
  14842. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14843. goto end;
  14844. }
  14845. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14846. {
  14847. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14848. goto end;
  14849. }
  14850. 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
  14851. {
  14852. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14853. goto end;
  14854. }
  14855. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14856. {
  14857. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14858. goto end;
  14859. }
  14860. }
  14861. }// END FOR CHAdeMO_QUANTITY
  14862. for (int index = 0; index < CCS_QUANTITY; index++)
  14863. {
  14864. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  14865. {
  14866. 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'))
  14867. {
  14868. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14869. goto end;
  14870. }
  14871. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  14872. {
  14873. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14874. goto end;
  14875. }
  14876. 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
  14877. {
  14878. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14879. goto end;
  14880. }
  14881. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14882. {
  14883. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14884. goto end;
  14885. }
  14886. }
  14887. } // END FOR CCS_QUANTITY
  14888. for (int index = 0; index < GB_QUANTITY; index++)
  14889. {
  14890. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  14891. {
  14892. 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'))
  14893. {
  14894. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14895. goto end;
  14896. }
  14897. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14898. {
  14899. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14900. goto end;
  14901. }
  14902. 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
  14903. {
  14904. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14905. goto end;
  14906. }
  14907. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14908. {
  14909. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14910. goto end;
  14911. }
  14912. }
  14913. } // END FOR GB_QUANTITY
  14914. for (int index = 0; index < AC_QUANTITY; index++)
  14915. {
  14916. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  14917. {
  14918. 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'))
  14919. {
  14920. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  14921. goto end;
  14922. }
  14923. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  14924. {
  14925. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14926. goto end;
  14927. }
  14928. 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
  14929. {
  14930. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  14931. goto end;
  14932. }
  14933. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14934. {
  14935. 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))
  14936. {
  14937. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  14938. goto end;
  14939. }
  14940. }
  14941. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  14942. {
  14943. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14944. goto end;
  14945. }
  14946. }
  14947. }// END FOR AC_QUANTITY
  14948. //The connectorId is 0
  14949. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  14950. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  14951. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  14952. result = TRUE;
  14953. return result;
  14954. }
  14955. else
  14956. {
  14957. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  14958. }
  14959. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  14960. {
  14961. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  14962. result = TRUE;
  14963. return result;
  14964. }
  14965. end:
  14966. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  14967. return result;
  14968. }
  14969. int handleResetRequest(char *uuid, char *payload)
  14970. {
  14971. mtrace();
  14972. int result = FAIL;
  14973. json_object *Reset = json_object_new_object();
  14974. DEBUG_INFO("handleResetRequest...\n");
  14975. Reset = json_tokener_parse(payload);
  14976. ShmOCPP20Data->Reset.evseId = 0;
  14977. if(!is_error(Reset))
  14978. {
  14979. // Required data
  14980. if(json_object_object_get(Reset, "type") != NULL)
  14981. {
  14982. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  14983. }
  14984. if(json_object_object_get(Reset, "evseId") != NULL)
  14985. {
  14986. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  14987. }
  14988. }
  14989. json_object_put(Reset);
  14990. if((ShmOCPP20Data->Reset.evseId == 0) && ((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0)))
  14991. {
  14992. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  14993. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  14994. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  14995. result = PASS;
  14996. }
  14997. else
  14998. {
  14999. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  15000. }
  15001. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  15002. sendResetConfirmation(uuid);
  15003. return result;
  15004. }
  15005. int handleSendLocalListRequest(char *uuid, char *payload)
  15006. {
  15007. mtrace();
  15008. int result = FAIL;
  15009. int checkState_Faulted = FALSE;
  15010. json_object *SendLocalList;
  15011. DEBUG_INFO("handleSendLocalListRequest...\n");
  15012. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  15013. {
  15014. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15015. goto end;
  15016. }
  15017. SendLocalList = json_tokener_parse(payload);
  15018. if(!is_error(SendLocalList))
  15019. {
  15020. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  15021. // Required data
  15022. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  15023. {
  15024. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  15025. }
  15026. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  15027. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  15028. // Optional data
  15029. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  15030. {
  15031. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  15032. {
  15033. // Required data
  15034. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  15035. {
  15036. 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")));
  15037. 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")));
  15038. }
  15039. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  15040. {
  15041. 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")));
  15042. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  15043. 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")));
  15044. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  15045. 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"));
  15046. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  15047. {
  15048. 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")));
  15049. 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")));
  15050. }
  15051. }
  15052. }
  15053. }
  15054. }
  15055. json_object_put(SendLocalList);
  15056. //check Charge Point state
  15057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15058. {
  15059. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15060. {
  15061. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15062. }
  15063. }
  15064. for (int index = 0; index < CCS_QUANTITY; index++)
  15065. {
  15066. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15067. {
  15068. checkState_Faulted = TRUE; //OCPP Status
  15069. }
  15070. }
  15071. for (int index = 0; index < GB_QUANTITY; index++)
  15072. {
  15073. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15074. {
  15075. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15076. }
  15077. }
  15078. for (int index = 0; index < AC_QUANTITY; index++)
  15079. {
  15080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15081. {
  15082. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15083. }
  15084. }
  15085. if(checkState_Faulted == TRUE)
  15086. {
  15087. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15088. goto end;
  15089. }
  15090. // Check update type
  15091. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  15092. {
  15093. //Local list full update
  15094. DEBUG_INFO("Local list full update.\n");
  15095. DB_getListVerion();
  15096. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  15097. {
  15098. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15099. goto end;
  15100. }*/
  15101. DB_cleanLocalList();
  15102. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  15103. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  15104. }
  15105. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  15106. {
  15107. //Local list different update
  15108. DEBUG_INFO("Local list different update.\n");
  15109. DB_getListVerion();
  15110. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  15111. {
  15112. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  15113. goto end;
  15114. }
  15115. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  15116. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  15117. }
  15118. else
  15119. {
  15120. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15121. goto end;
  15122. }
  15123. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  15124. end:
  15125. sendSendLocalListConfirmation(uuid);
  15126. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15127. return result;
  15128. }
  15129. int handleSetChargingProfileRequest(char *uuid, char *payload)
  15130. {
  15131. mtrace();
  15132. int result = FAIL;
  15133. struct SetChargingProfile_20 SetProfileReq = {0};
  15134. uint8_t isLostConnectorId = FALSE;
  15135. uint8_t isPeriodOverMax = FALSE;
  15136. uint8_t isStackOverMax = FALSE;
  15137. uint8_t isProfileOverMax = FALSE;
  15138. uint8_t isConnectorMismatch = FALSE;
  15139. uint8_t isTransactiodIdMismatch = FALSE;
  15140. uint8_t isInvalidLimit = FALSE;
  15141. uint8_t isWrongFormat = FALSE;
  15142. uint8_t replaceableProfileCnt = 0;
  15143. uint8_t existProfileQuantity = 0;
  15144. uint8_t filename[128]={0};
  15145. uint8_t dataLine[4096]={0};
  15146. FILE *filePtr;
  15147. json_object *SetChargingProfile;
  15148. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  15149. SetChargingProfile = json_tokener_parse(payload);
  15150. if(!is_error(SetChargingProfile))
  15151. {
  15152. // Required data
  15153. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  15154. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  15155. else
  15156. isLostConnectorId = TRUE;
  15157. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  15158. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  15159. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  15160. {
  15161. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15162. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15163. {
  15164. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  15165. }
  15166. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  15167. {
  15168. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15169. }
  15170. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  15171. {
  15172. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  15173. }
  15174. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  15175. {
  15176. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  15177. }
  15178. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  15179. {
  15180. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  15181. }
  15182. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  15183. {
  15184. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  15185. }
  15186. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  15187. {
  15188. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  15189. }
  15190. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  15191. {
  15192. int chargingScheduleCount = 0;
  15193. int chargingSchedulePeriodCount = 0;
  15194. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  15195. {
  15196. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  15197. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  15198. {
  15199. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  15200. {
  15201. 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")));
  15202. }
  15203. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  15204. {
  15205. 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"));
  15206. }
  15207. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  15208. {
  15209. 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"));
  15210. }
  15211. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  15212. {
  15213. 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")));
  15214. }
  15215. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  15216. {
  15217. 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"));
  15218. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  15219. {
  15220. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  15221. {
  15222. 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)
  15223. {
  15224. 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"));
  15225. }
  15226. 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)
  15227. {
  15228. 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"));
  15229. }
  15230. 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)
  15231. {
  15232. 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"));
  15233. }
  15234. 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)
  15235. {
  15236. 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"));
  15237. }
  15238. // Check invalid limit
  15239. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  15240. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  15241. {
  15242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  15243. {
  15244. 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)))) ||
  15245. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  15246. {
  15247. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  15248. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  15249. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  15250. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  15251. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  15252. isInvalidLimit = TRUE;
  15253. }
  15254. }
  15255. else
  15256. {
  15257. 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) ||
  15258. (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)))
  15259. {
  15260. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  15261. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  15262. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  15263. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  15264. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  15265. isInvalidLimit = TRUE;
  15266. }
  15267. }
  15268. }
  15269. }
  15270. }
  15271. else
  15272. {
  15273. isPeriodOverMax = TRUE;
  15274. }
  15275. }
  15276. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff") != NULL)
  15277. {
  15278. 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)
  15279. {
  15280. 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"));
  15281. }
  15282. 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)
  15283. {
  15284. 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")));
  15285. }
  15286. 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)
  15287. {
  15288. 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"));
  15289. }
  15290. 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)
  15291. {
  15292. 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"));
  15293. if(cntEntry<=1024)
  15294. {
  15295. for(int idxEntry=0; idxEntry<cntEntry; idxEntry++)
  15296. {
  15297. 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)
  15298. {
  15299. 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"));
  15300. }
  15301. 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)
  15302. {
  15303. 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)
  15304. 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"));
  15305. 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)
  15306. 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"));
  15307. }
  15308. 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)
  15309. {
  15310. 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"));
  15311. if(cntConCost<=3)
  15312. {
  15313. for(uint8_t idxConCost=0; idxConCost<cntConCost; idxConCost++)
  15314. {
  15315. 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)
  15316. 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"));
  15317. 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)
  15318. {
  15319. 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"));
  15320. if(cntConCost<=3)
  15321. {
  15322. for(uint8_t idxCost=0; idxCost<cntCost; idxCost++)
  15323. {
  15324. 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)
  15325. 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")));
  15326. 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)
  15327. 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"));
  15328. 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)
  15329. 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"));
  15330. }
  15331. }
  15332. }
  15333. }
  15334. }
  15335. 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"));
  15336. }
  15337. }
  15338. }
  15339. }
  15340. }
  15341. }
  15342. }
  15343. else
  15344. {
  15345. isWrongFormat = TRUE;
  15346. }
  15347. }
  15348. // Check periods is over max configuration
  15349. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  15350. {
  15351. if(SetProfileReq.evseId == 0)
  15352. {
  15353. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  15354. filePtr = fopen((char*)filename, "r");
  15355. if (!filePtr)
  15356. {
  15357. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  15358. filePtr = fopen((char*)filename, "w+");
  15359. }
  15360. else
  15361. {
  15362. //Check Charging Profile Count
  15363. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15364. char *line = NULL;
  15365. size_t len = 0;
  15366. while(getline(&line, &len, filePtr) != -1)
  15367. {
  15368. json_object *obj = NULL;
  15369. obj = json_tokener_parse(line);
  15370. if(is_error(obj))
  15371. {
  15372. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  15373. }
  15374. else
  15375. {
  15376. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15377. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15378. {
  15379. existProfileQuantity += 1;
  15380. }
  15381. else
  15382. replaceableProfileCnt += 1;
  15383. }
  15384. //DEBUG_INFO("word=%s\n",word);
  15385. /*if(strstr((char*)dataLine, "id")!= NULL)
  15386. {
  15387. existProfileQuantity += 1;
  15388. }*/
  15389. }
  15390. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15391. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15392. {
  15393. isStackOverMax = TRUE;
  15394. }
  15395. }
  15396. fclose(filePtr);
  15397. }
  15398. else
  15399. isConnectorMismatch = TRUE;
  15400. }
  15401. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  15402. {
  15403. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  15404. isConnectorMismatch = TRUE;
  15405. if(!isConnectorMismatch)
  15406. {
  15407. if(SetProfileReq.evseId == 0)
  15408. {
  15409. int tmpExistProfileQuantity;
  15410. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  15411. {
  15412. tmpExistProfileQuantity = 0;
  15413. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15414. filePtr = fopen((char*)filename, "r");
  15415. if (!filePtr)
  15416. {
  15417. DEBUG_INFO("%s not exist, create it.\n", filename);
  15418. filePtr = fopen((char*)filename, "w+");
  15419. }
  15420. else
  15421. {
  15422. //Check Charging Profile Count
  15423. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15424. char *line = NULL;
  15425. size_t len = 0;
  15426. while(getline(&line, &len, filePtr) != -1)
  15427. {
  15428. json_object *obj = NULL;
  15429. obj = json_tokener_parse(line);
  15430. if(is_error(obj))
  15431. {
  15432. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  15433. }
  15434. else
  15435. {
  15436. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15437. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15438. {
  15439. tmpExistProfileQuantity += 1;
  15440. }
  15441. else
  15442. replaceableProfileCnt += 1;
  15443. }
  15444. //DEBUG_INFO("word=%s\n",word);
  15445. /*if(strstr((char*)dataLine, "id")!= NULL)
  15446. {
  15447. tmpExistProfileQuantity += 1;
  15448. }*/
  15449. }
  15450. }
  15451. fclose(filePtr);
  15452. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15453. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15454. {
  15455. isStackOverMax = TRUE;
  15456. }
  15457. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  15458. }
  15459. }
  15460. else
  15461. {
  15462. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15463. filePtr = fopen((char*)filename, "r");
  15464. if (!filePtr)
  15465. {
  15466. DEBUG_INFO("%s not exist, create it.\n", filename);
  15467. filePtr = fopen((char*)filename, "w+");
  15468. }
  15469. else
  15470. {
  15471. //Check Charging Profile Count
  15472. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15473. char *line = NULL;
  15474. size_t len = 0;
  15475. while(getline(&line, &len, filePtr) != -1)
  15476. {
  15477. json_object *obj = NULL;
  15478. obj = json_tokener_parse(line);
  15479. if(is_error(obj))
  15480. {
  15481. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  15482. }
  15483. else
  15484. {
  15485. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15486. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15487. {
  15488. existProfileQuantity += 1;
  15489. }
  15490. else
  15491. replaceableProfileCnt += 1;
  15492. }
  15493. //DEBUG_INFO("word=%s\n",word);
  15494. /*if(strstr((char*)dataLine, "id")!= NULL)
  15495. {
  15496. existProfileQuantity += 1;
  15497. }*/
  15498. }
  15499. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15500. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15501. {
  15502. isStackOverMax = TRUE;
  15503. }
  15504. }
  15505. fclose(filePtr);
  15506. }
  15507. }
  15508. }
  15509. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15510. {
  15511. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  15512. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15513. else
  15514. isConnectorMismatch = TRUE;
  15515. if(!isConnectorMismatch)
  15516. {
  15517. filePtr = fopen((char*)filename, "r");
  15518. if (!filePtr)
  15519. {
  15520. DEBUG_INFO("%s not exist, create it.\n", filename);
  15521. filePtr = fopen((char*)filename, "w+");
  15522. }
  15523. else
  15524. {
  15525. //Check Charging Profile Count
  15526. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  15527. char *line = NULL;
  15528. size_t len = 0;
  15529. while(getline(&line, &len, filePtr) != -1)
  15530. {
  15531. json_object *obj = NULL;
  15532. obj = json_tokener_parse(line);
  15533. if(is_error(obj))
  15534. {
  15535. DEBUG_ERROR("Parse TxProfile from file error.\n");
  15536. }
  15537. else
  15538. {
  15539. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  15540. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  15541. {
  15542. existProfileQuantity += 1;
  15543. }
  15544. else
  15545. replaceableProfileCnt += 1;
  15546. }
  15547. //DEBUG_INFO("word=%s\n",word);
  15548. /*if(strstr((char*)dataLine, "id")!= NULL)
  15549. {
  15550. existProfileQuantity += 1;
  15551. }*/
  15552. }
  15553. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  15554. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  15555. {
  15556. isStackOverMax = TRUE;
  15557. }
  15558. }
  15559. fclose(filePtr);
  15560. if(strcmp((char*)SetProfileReq.chargingProfile.transactionId, (char*)ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId) != 0)
  15561. isTransactiodIdMismatch = TRUE;
  15562. }
  15563. }
  15564. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  15565. {
  15566. /*
  15567. * TODO:
  15568. *
  15569. */
  15570. }
  15571. else
  15572. {}
  15573. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  15574. {
  15575. FILE *fp;
  15576. char dataLine[4096]={0};
  15577. char fnametemp[128]={0};
  15578. int tmpProfileQuantity;
  15579. //Check ChargePointMaxProfile.json exit
  15580. existProfileQuantity = 0;
  15581. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  15582. {
  15583. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  15584. //Check Charging Profile Count
  15585. tmpProfileQuantity = 0;
  15586. while(fscanf(fp, "%s", dataLine) != EOF)
  15587. {
  15588. if(strstr(dataLine, "id")!= NULL)
  15589. {
  15590. existProfileQuantity += 1;
  15591. tmpProfileQuantity += 1;
  15592. }
  15593. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15594. }
  15595. fclose(fp);
  15596. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  15597. }
  15598. //Check TxDefaultProfile_%d.json
  15599. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  15600. {
  15601. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  15602. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15603. if((access(fnametemp,F_OK))!=-1)
  15604. {
  15605. fp = fopen(fnametemp, "r");
  15606. //Check Charging Profile Count
  15607. tmpProfileQuantity = 0;
  15608. while(fscanf(fp, "%s", dataLine) != EOF)
  15609. {
  15610. //DEBUG_INFO("word=%s\n",word);
  15611. if(strstr(dataLine, "id")!= NULL)
  15612. {
  15613. existProfileQuantity += 1;
  15614. tmpProfileQuantity += 1;
  15615. }
  15616. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15617. }
  15618. fclose(fp);
  15619. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  15620. }
  15621. }
  15622. //Check TxProfile_%d.json
  15623. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  15624. {
  15625. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  15626. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  15627. if((access(fnametemp,F_OK))!=-1)
  15628. {
  15629. fp = fopen(fnametemp, "r");
  15630. //Check Charging Profile Count
  15631. tmpProfileQuantity = 0;
  15632. while(fscanf(fp, "%s", dataLine) != EOF)
  15633. {
  15634. if(strstr(dataLine, "id")!= NULL)
  15635. {
  15636. existProfileQuantity += 1;
  15637. tmpProfileQuantity += 1;
  15638. }
  15639. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  15640. }
  15641. fclose(fp);
  15642. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  15643. }
  15644. }
  15645. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  15646. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  15647. // To check total Profile quantity
  15648. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  15649. {
  15650. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  15651. isProfileOverMax = TRUE;
  15652. }
  15653. else
  15654. {
  15655. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  15656. isProfileOverMax = TRUE;
  15657. }
  15658. }
  15659. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  15660. }
  15661. // Profile replace or add info
  15662. if(!isLostConnectorId && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  15663. {
  15664. FILE *infile;
  15665. FILE *outfile;
  15666. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  15667. char rmFileCmd[128];
  15668. int tempchargingProfileIdInt;
  15669. int tempchargingProfileStackLevelInt;
  15670. int chkChar;
  15671. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  15672. {
  15673. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  15674. {
  15675. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  15676. }
  15677. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  15678. {
  15679. if(SetProfileReq.evseId==0)
  15680. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  15681. else
  15682. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15683. }
  15684. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  15685. {
  15686. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  15687. }
  15688. else
  15689. {
  15690. /*
  15691. * TODO:
  15692. *
  15693. */
  15694. }
  15695. infile = fopen ((char*)filename, "r");
  15696. outfile = fopen ((char*)tmpProfileName, "w");
  15697. chkChar = fgetc(infile);
  15698. rewind(infile);
  15699. if(chkChar == EOF)
  15700. {
  15701. // Profile is empty
  15702. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15703. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15704. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15705. fclose(infile);
  15706. fclose(outfile);
  15707. sprintf(rmFileCmd,"rm -f %s",filename);
  15708. system(rmFileCmd);
  15709. rename((char*)tmpProfileName, (char*)filename);
  15710. }
  15711. else
  15712. {
  15713. // Profile is not empty
  15714. int ChargingProfileAdded = FALSE;
  15715. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  15716. {
  15717. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  15718. json_object *tmpChargingProfile;
  15719. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  15720. if(!is_error(tmpChargingProfile))
  15721. {
  15722. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  15723. {
  15724. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  15725. {
  15726. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  15727. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  15728. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  15729. }
  15730. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15731. {
  15732. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  15733. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  15734. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  15735. }
  15736. }
  15737. }
  15738. json_object_put(tmpChargingProfile);
  15739. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  15740. {
  15741. if(ChargingProfileAdded == FALSE)
  15742. {
  15743. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15744. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15745. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15746. ChargingProfileAdded = TRUE;
  15747. }
  15748. }
  15749. else
  15750. {
  15751. fprintf(outfile,"%s\n",dataLine);
  15752. if(ChargingProfileAdded == FALSE)
  15753. {
  15754. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  15755. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  15756. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  15757. ChargingProfileAdded = TRUE;
  15758. }
  15759. }
  15760. } // end of while loop
  15761. fclose(infile);
  15762. fclose(outfile);
  15763. sprintf(rmFileCmd,"rm -f %s",filename);
  15764. system(rmFileCmd);
  15765. rename((char*)tmpProfileName, (char*)filename);
  15766. }
  15767. }
  15768. sleep(1);
  15769. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  15770. result = PASS;
  15771. }
  15772. else
  15773. {
  15774. if(isLostConnectorId)
  15775. DEBUG_WARN("Connector id is wrong.\n");
  15776. if(isConnectorMismatch)
  15777. DEBUG_WARN("Connector id is mismatch.\n");
  15778. if(isPeriodOverMax)
  15779. DEBUG_WARN("Profile periods quantity is over spec.\n");
  15780. if(isProfileOverMax)
  15781. DEBUG_WARN("Profile quantity is over spec.\n");
  15782. if(isTransactiodIdMismatch)
  15783. DEBUG_WARN("Transaction id is mismatch.\n");
  15784. if(isInvalidLimit)
  15785. DEBUG_WARN("Limit value is invalid.\n");
  15786. if(isStackOverMax)
  15787. DEBUG_WARN("Profile stack is over spec.\n");
  15788. if(isWrongFormat)
  15789. DEBUG_WARN("Profile format is wrong.\n");
  15790. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  15791. }
  15792. }
  15793. json_object_put(SetChargingProfile);
  15794. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  15795. {
  15796. if(SetProfileReq.evseId == 0)
  15797. {
  15798. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15799. {
  15800. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  15801. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  15802. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  15803. }
  15804. }
  15805. else
  15806. {
  15807. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  15808. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  15809. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  15810. }
  15811. }
  15812. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  15813. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15814. return result;
  15815. }
  15816. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  15817. {
  15818. mtrace();
  15819. int result = FAIL;
  15820. json_object *SetDisplayMessage;
  15821. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  15822. SetDisplayMessage = json_tokener_parse(payload);
  15823. if(!is_error(SetDisplayMessage))
  15824. {
  15825. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  15826. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  15827. // Required data
  15828. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  15829. {
  15830. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  15831. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  15832. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  15833. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  15834. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  15835. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  15836. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  15837. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  15838. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  15839. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  15840. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  15841. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  15842. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  15843. {
  15844. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  15845. 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")));
  15846. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  15847. 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")));
  15848. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  15849. 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")));
  15850. }
  15851. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  15852. {
  15853. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  15854. 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")));
  15855. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  15856. 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")));
  15857. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  15858. {
  15859. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  15860. 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"));
  15861. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  15862. 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"));
  15863. }
  15864. }
  15865. }
  15866. }
  15867. json_object_put(SetDisplayMessage);
  15868. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  15869. sendSetDisplayMessagesConfirmation(uuid);
  15870. // Announce CSU there is display request come from server
  15871. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  15872. return result;
  15873. }
  15874. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  15875. {
  15876. mtrace();
  15877. int result = FAIL;
  15878. json_object *SetMonitoringBase;
  15879. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  15880. SetMonitoringBase = json_tokener_parse(payload);
  15881. if(!is_error(SetMonitoringBase))
  15882. {
  15883. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  15884. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  15885. // Required data
  15886. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  15887. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  15888. }
  15889. json_object_put(SetMonitoringBase);
  15890. /*
  15891. * TODO:
  15892. * 1. Configure monitor base and response
  15893. */
  15894. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  15895. sendSetMonitoringBaseConfirmation(uuid);
  15896. return result;
  15897. }
  15898. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  15899. {
  15900. mtrace();
  15901. int result = FAIL;
  15902. json_object *SetMonitoringLevel;
  15903. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  15904. SetMonitoringLevel = json_tokener_parse(payload);
  15905. if(!is_error(SetMonitoringLevel))
  15906. {
  15907. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  15908. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  15909. // Required data
  15910. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  15911. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  15912. }
  15913. json_object_put(SetMonitoringLevel);
  15914. /*
  15915. * TODO:
  15916. * Configure monitor status and response
  15917. */
  15918. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  15919. sendSetMonitoringLevelConfirmation(uuid);
  15920. return result;
  15921. }
  15922. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  15923. {
  15924. mtrace();
  15925. int result = FAIL;
  15926. json_object *SetNetworkProfile;
  15927. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  15928. SetNetworkProfile = json_tokener_parse(payload);
  15929. if(!is_error(SetNetworkProfile))
  15930. {
  15931. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  15932. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  15933. // Required data
  15934. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  15935. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  15936. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  15937. {
  15938. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  15939. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  15940. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  15941. {
  15942. if(strcmp(json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")), "JSON") == 0)
  15943. {
  15944. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  15945. }
  15946. else
  15947. {
  15948. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  15949. goto end;
  15950. }
  15951. }
  15952. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  15953. {
  15954. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  15955. if((strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"wss", 3) == 0) || (strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"ws", 2) == 0))
  15956. {
  15957. char protocol[10], host[128], path[512], port[10];
  15958. int check = sscanf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"%[^:]:%*2[/]%[^:]:%[^/]/%199[^\n]", protocol, host, port, path);
  15959. if(check >= 3)
  15960. {
  15961. DEBUG_INFO("URL: %s\n", ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl);
  15962. DEBUG_INFO("protocol: %s\n",protocol);
  15963. DEBUG_INFO("host: %s\n",host);
  15964. DEBUG_INFO("port: %s\n",port);
  15965. DEBUG_INFO("path: %s\n",path);
  15966. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  15967. }
  15968. else
  15969. {
  15970. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  15971. goto end;
  15972. }
  15973. }
  15974. else
  15975. {
  15976. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  15977. goto end;
  15978. }
  15979. }
  15980. else
  15981. {
  15982. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  15983. goto end;
  15984. }
  15985. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  15986. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  15987. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  15988. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  15989. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  15990. {
  15991. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  15992. 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")));
  15993. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  15994. 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")));
  15995. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  15996. 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")));
  15997. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  15998. 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")));
  15999. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  16000. 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")));
  16001. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  16002. 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")));
  16003. }
  16004. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  16005. {
  16006. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  16007. {
  16008. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  16009. 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")));
  16010. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  16011. }
  16012. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  16013. {
  16014. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  16015. 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")));
  16016. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  16017. }
  16018. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  16019. {
  16020. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  16021. 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")));
  16022. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  16023. }
  16024. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  16025. 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"));
  16026. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  16027. 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")));
  16028. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  16029. 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"));
  16030. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  16031. 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")));
  16032. }
  16033. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  16034. }
  16035. }
  16036. json_object_put(SetNetworkProfile);
  16037. /*
  16038. * TODO:
  16039. * 1. Process network configuration and response
  16040. */
  16041. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  16042. {
  16043. }
  16044. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  16045. {
  16046. }
  16047. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  16048. {
  16049. }
  16050. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  16051. {
  16052. }
  16053. else
  16054. {
  16055. }
  16056. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  16057. {
  16058. }
  16059. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  16060. {
  16061. }
  16062. else
  16063. {
  16064. }
  16065. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  16066. {
  16067. }
  16068. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  16069. {
  16070. }
  16071. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  16072. {
  16073. }
  16074. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  16075. {
  16076. }
  16077. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  16078. {
  16079. }
  16080. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  16081. {
  16082. }
  16083. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  16084. {
  16085. }
  16086. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  16087. {
  16088. }
  16089. else
  16090. {
  16091. }
  16092. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  16093. {
  16094. }
  16095. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  16096. {
  16097. }
  16098. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  16099. {
  16100. }
  16101. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  16102. {
  16103. }
  16104. else
  16105. {
  16106. }
  16107. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  16108. {
  16109. }
  16110. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  16111. {
  16112. }
  16113. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  16114. {
  16115. }
  16116. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  16117. {
  16118. }
  16119. else
  16120. {
  16121. }
  16122. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  16123. end:
  16124. sendSetNetworkProfileConfirmation(uuid);
  16125. return result;
  16126. }
  16127. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  16128. {
  16129. mtrace();
  16130. int result = FAIL;
  16131. json_object *SetVariableMonitoring;
  16132. uint8_t variableQuantity = 0;
  16133. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  16134. SetVariableMonitoring = json_tokener_parse(payload);
  16135. if(!is_error(SetVariableMonitoring))
  16136. {
  16137. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  16138. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  16139. // Required data
  16140. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  16141. {
  16142. variableQuantity++;
  16143. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  16144. {
  16145. 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"));
  16146. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  16147. }
  16148. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  16149. {
  16150. 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"));
  16151. }
  16152. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  16153. {
  16154. 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")));
  16155. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16156. }
  16157. else
  16158. {
  16159. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  16160. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16161. }
  16162. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  16163. {
  16164. 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"));
  16165. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  16166. }
  16167. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  16168. {
  16169. 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"));
  16170. }
  16171. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  16172. {
  16173. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  16174. {
  16175. 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")));
  16176. }
  16177. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  16178. {
  16179. 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")));
  16180. }
  16181. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  16182. {
  16183. 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)
  16184. {
  16185. 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"));
  16186. }
  16187. 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)
  16188. {
  16189. 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"));
  16190. }
  16191. }
  16192. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  16193. }
  16194. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  16195. {
  16196. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  16197. {
  16198. 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")));
  16199. }
  16200. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  16201. {
  16202. 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")));
  16203. }
  16204. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  16205. }
  16206. /*
  16207. * TODO
  16208. * Set Variables and save to DB
  16209. */
  16210. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  16211. }
  16212. }
  16213. json_object_put(SetVariableMonitoring);
  16214. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  16215. return result;
  16216. }
  16217. int handleSetVariablesRequest(char *uuid, char *payload)
  16218. {
  16219. mtrace();
  16220. uint8_t result = FAIL;
  16221. uint8_t isUnknownComponent = TRUE;
  16222. uint8_t isNeedReconnect = FALSE;
  16223. json_object *SetVariables;
  16224. DEBUG_INFO("handleSetVariablesRequest...\n");
  16225. SetVariables = json_tokener_parse(payload);
  16226. if(!is_error(SetVariables))
  16227. {
  16228. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  16229. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  16230. // Required data
  16231. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  16232. {
  16233. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  16234. {
  16235. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  16236. {
  16237. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  16238. {
  16239. 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")));
  16240. }
  16241. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  16242. {
  16243. 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")));
  16244. }
  16245. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  16246. {
  16247. 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)
  16248. {
  16249. 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"));
  16250. }
  16251. 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)
  16252. {
  16253. 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"));
  16254. }
  16255. }
  16256. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  16257. }
  16258. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  16259. {
  16260. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  16261. {
  16262. 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")));
  16263. }
  16264. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  16265. {
  16266. 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")));
  16267. }
  16268. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  16269. }
  16270. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  16271. {
  16272. 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")));
  16273. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  16274. }
  16275. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  16276. {
  16277. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  16278. }
  16279. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  16280. {
  16281. 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")));
  16282. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  16283. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  16284. {
  16285. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  16286. (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) &&
  16287. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  16288. (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))
  16289. {
  16290. isUnknownComponent = FALSE;
  16291. //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);
  16292. if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_decimal]) == 0)
  16293. {
  16294. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,TRUE)!=YES)
  16295. {
  16296. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16297. break;
  16298. }
  16299. }
  16300. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_integer]) == 0)
  16301. {
  16302. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, FALSE)!=YES)
  16303. {
  16304. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16305. break;
  16306. }
  16307. }
  16308. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_dateTime]) == 0)
  16309. {
  16310. if(isMatchTimeFormat(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)!=YES)
  16311. {
  16312. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16313. break;
  16314. }
  16315. }
  16316. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_boolean]) == 0)
  16317. {
  16318. // To make sure all boolean value is in uppercase
  16319. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true") != NULL) ||
  16320. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"True") != NULL) ||
  16321. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"TRUE") != NULL))
  16322. {
  16323. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true");
  16324. }
  16325. else if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false") != NULL) ||
  16326. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"False") != NULL) ||
  16327. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"FALSE") != NULL))
  16328. {
  16329. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false");
  16330. }
  16331. else
  16332. {
  16333. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16334. break;
  16335. }
  16336. }
  16337. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  16338. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  16339. {
  16340. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  16341. break;
  16342. }
  16343. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  16344. {
  16345. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16346. break;
  16347. }
  16348. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AuthCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Enabled") != NULL))
  16349. {
  16350. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16351. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16352. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16353. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16354. {
  16355. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16356. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16357. if(strstr((char*)tmp, "true") != NULL)
  16358. {
  16359. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
  16360. }
  16361. else
  16362. {
  16363. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
  16364. }
  16365. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16366. }
  16367. else
  16368. {
  16369. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16370. break;
  16371. }
  16372. }
  16373. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  16374. {
  16375. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  16376. }
  16377. else
  16378. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16379. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  16380. {
  16381. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  16382. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16383. else
  16384. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16385. }
  16386. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  16387. {
  16388. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16389. {
  16390. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16391. }
  16392. else
  16393. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  16394. }
  16395. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  16396. {
  16397. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16398. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16399. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16400. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16401. {
  16402. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16403. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16404. }
  16405. else
  16406. {
  16407. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  16408. break;
  16409. }
  16410. }
  16411. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  16412. {
  16413. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16414. {
  16415. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16416. }
  16417. else
  16418. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16419. }
  16420. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "CharingProfileRefreshInterval") != NULL))
  16421. {
  16422. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16423. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16424. else
  16425. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16426. }
  16427. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  16428. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  16429. {
  16430. isNeedReconnect = TRUE;
  16431. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16432. //SetOcppConnStatus(FALSE);
  16433. }
  16434. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  16435. {
  16436. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16437. {
  16438. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16439. }
  16440. else
  16441. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16442. }
  16443. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  16444. {
  16445. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  16446. {
  16447. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16448. }
  16449. else
  16450. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16451. }
  16452. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  16453. {
  16454. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  16455. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  16456. tmp[idx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  16457. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  16458. {
  16459. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  16460. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  16461. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  16462. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16463. }
  16464. }
  16465. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  16466. {
  16467. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  16468. {
  16469. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16470. }
  16471. else
  16472. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16473. }
  16474. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "OffLineMaxChargingPower") != NULL))
  16475. {
  16476. if(atoi((const char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > modelnameInfo.ratedPower)
  16477. {
  16478. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  16479. }
  16480. else
  16481. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  16482. }
  16483. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  16484. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  16485. {
  16486. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  16487. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  16488. }
  16489. break;
  16490. }
  16491. else
  16492. {
  16493. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  16494. {
  16495. isUnknownComponent = FALSE;
  16496. }
  16497. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  16498. }
  16499. }
  16500. if(isUnknownComponent == TRUE)
  16501. {
  16502. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  16503. }
  16504. }
  16505. }
  16506. }
  16507. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  16508. if(isNeedReconnect)
  16509. {
  16510. SetOcppConnStatus(FALSE);
  16511. }
  16512. }
  16513. json_object_put(SetVariables);
  16514. return result;
  16515. }
  16516. int handleTriggerMessageRequest(char *uuid, char *payload)
  16517. {
  16518. mtrace();
  16519. int result = FAIL;
  16520. int connectorIdIsNULL = FALSE;
  16521. int connectorIdInt =0;
  16522. json_object *TriggerMessage;
  16523. DEBUG_INFO("handleTriggerMessageRequest\n");
  16524. TriggerMessage = json_tokener_parse(payload);
  16525. if(!is_error(TriggerMessage))
  16526. {
  16527. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  16528. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  16529. // Required data
  16530. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  16531. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  16532. // Optional data
  16533. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  16534. {
  16535. // Required data
  16536. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  16537. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  16538. // Optional data
  16539. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  16540. {
  16541. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  16542. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  16543. }
  16544. else
  16545. connectorIdIsNULL = TRUE;
  16546. }
  16547. else
  16548. connectorIdIsNULL = TRUE;
  16549. }
  16550. json_object_put(TriggerMessage);
  16551. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  16552. {
  16553. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  16554. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  16555. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  16556. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  16557. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  16558. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  16559. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  16560. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  16561. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  16562. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  16563. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  16564. {
  16565. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  16566. sendTriggerMessageConfirmation(uuid);
  16567. return TRUE;
  16568. }
  16569. else
  16570. {
  16571. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  16572. sendTriggerMessageConfirmation(uuid);
  16573. }
  16574. }
  16575. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  16576. {
  16577. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  16578. sendTriggerMessageConfirmation(uuid);
  16579. return TRUE;
  16580. }
  16581. //==========================
  16582. // Trigger message
  16583. //==========================
  16584. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  16585. {
  16586. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  16587. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  16588. {
  16589. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  16590. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16591. }
  16592. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16593. }
  16594. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  16595. {
  16596. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  16597. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  16598. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  16599. }
  16600. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  16601. {
  16602. if(server_sign)
  16603. {
  16604. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  16605. sendTriggerMessageConfirmation(uuid);
  16606. return TRUE;
  16607. }
  16608. else
  16609. {
  16610. if(DB_updateBootType(BootReasonEnumType_Triggered))
  16611. server_sign = FALSE;
  16612. }
  16613. }
  16614. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  16615. {
  16616. refreshStartTimer(&clientTime.Heartbeat);
  16617. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  16618. }
  16619. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  16620. {
  16621. if(connectorIdIsNULL == FALSE)
  16622. {
  16623. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  16624. {
  16625. cpinitateMsg.bits[connectorIdInt-1].TriggerMeterValueReq = ON;
  16626. }
  16627. }
  16628. else
  16629. {
  16630. for(int idx=0;idx< gunTotalNumber;idx++)
  16631. {
  16632. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  16633. }
  16634. }
  16635. }
  16636. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  16637. {
  16638. if(connectorIdIsNULL == FALSE)
  16639. {
  16640. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  16641. {
  16642. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = ON;
  16643. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  16644. }
  16645. }
  16646. else
  16647. {
  16648. for(int idx=0;idx< gunTotalNumber;idx++)
  16649. {
  16650. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  16651. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  16652. }
  16653. }
  16654. }
  16655. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  16656. {
  16657. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16658. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  16659. {
  16660. 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\" &");
  16661. }
  16662. }
  16663. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  16664. {
  16665. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16666. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  16667. {
  16668. 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\" &");
  16669. }
  16670. }
  16671. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  16672. {
  16673. if(connectorIdIsNULL == FALSE)
  16674. {
  16675. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  16676. {
  16677. //ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  16678. cpinitateMsg.bits[connectorIdInt -1].TriggerTransactionEventReq = ON;
  16679. }
  16680. }
  16681. else
  16682. {
  16683. for(int idx=0;idx< gunTotalNumber;idx++)
  16684. {
  16685. //ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  16686. cpinitateMsg.bits[idx].TriggerTransactionEventReq = ON;
  16687. }
  16688. }
  16689. }
  16690. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  16691. {
  16692. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  16693. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  16694. {
  16695. 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\" &");
  16696. }
  16697. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  16698. {
  16699. 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\" &");
  16700. }
  16701. }
  16702. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  16703. {
  16704. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  16705. }
  16706. return result;
  16707. }
  16708. int handleUnlockConnectorRequest(char *uuid, char *payload)
  16709. {
  16710. mtrace();
  16711. int result = FAIL;
  16712. int connectorIdInt =0;
  16713. int tempIndex = 0;
  16714. json_object *UnlockConnector;
  16715. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  16716. UnlockConnector = json_tokener_parse(payload);
  16717. if(!is_error(UnlockConnector))
  16718. {
  16719. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  16720. {
  16721. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  16722. }
  16723. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  16724. {
  16725. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  16726. }
  16727. }
  16728. json_object_put(UnlockConnector);
  16729. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  16730. if(gunTotalNumber == 0)
  16731. {
  16732. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  16733. goto end;
  16734. }
  16735. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  16736. {
  16737. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  16738. goto end;
  16739. }
  16740. else
  16741. {
  16742. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  16743. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  16744. //check Transaction active
  16745. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  16746. {
  16747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16748. {
  16749. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16750. }
  16751. else
  16752. {
  16753. tempIndex = connectorIdInt -1;
  16754. }
  16755. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16756. {
  16757. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  16758. {
  16759. //stop Transaction
  16760. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16761. }
  16762. }
  16763. }
  16764. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  16765. {
  16766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16767. {
  16768. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16769. }
  16770. else
  16771. {
  16772. tempIndex = connectorIdInt -1;
  16773. }
  16774. for (int index = 0; index < CCS_QUANTITY; index++)
  16775. {
  16776. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  16777. {
  16778. //stop Transaction
  16779. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16780. }
  16781. }
  16782. }
  16783. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  16784. {
  16785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16786. {
  16787. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  16788. }
  16789. else
  16790. {
  16791. tempIndex = connectorIdInt -1;
  16792. }
  16793. for (int index = 0; index < GB_QUANTITY; index++)
  16794. {
  16795. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  16796. {
  16797. //stop Transaction
  16798. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16799. }
  16800. }
  16801. }
  16802. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  16803. {
  16804. tempIndex = connectorIdInt -1;
  16805. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16806. {
  16807. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  16808. {
  16809. //stop Transaction
  16810. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16811. }
  16812. }
  16813. }
  16814. else
  16815. {
  16816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16817. {
  16818. tempIndex = 2;
  16819. }
  16820. else
  16821. {
  16822. tempIndex = connectorIdInt-1;
  16823. }
  16824. for (int index = 0; index < AC_QUANTITY; index++)
  16825. {
  16826. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  16827. {
  16828. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  16829. }
  16830. }
  16831. }
  16832. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  16833. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  16834. result = TRUE;
  16835. return result;
  16836. }
  16837. end:
  16838. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorConf = ON;
  16839. return result;
  16840. }
  16841. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  16842. {
  16843. mtrace();
  16844. int result = FAIL;
  16845. json_object *UnpublishFirmware;
  16846. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  16847. UnpublishFirmware = json_tokener_parse(payload);
  16848. if(!is_error(UnpublishFirmware))
  16849. {
  16850. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  16851. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  16852. // Required data
  16853. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  16854. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  16855. }
  16856. json_object_put(UnpublishFirmware);
  16857. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  16858. /*
  16859. * TODO:
  16860. * 1. Check unpublished status
  16861. */
  16862. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  16863. sendUnpublishFirmwareConfirmation(uuid);
  16864. return result;
  16865. }
  16866. static char UpdateFirmwarepayloadData[512]={0};
  16867. void *UpdateFirmwareProcess(void *data)
  16868. {
  16869. pthread_detach(pthread_self());
  16870. mtrace();
  16871. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  16872. int port=0;
  16873. int isSuccess = 0;
  16874. char ftpbuf[1024];
  16875. char temp[1024];
  16876. char * pch;
  16877. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  16878. json_object *UpdateFirmware;
  16879. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  16880. if(!is_error(UpdateFirmware))
  16881. {
  16882. // Required data
  16883. if(json_object_object_get(UpdateFirmware, "requestId"))
  16884. {
  16885. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  16886. }
  16887. if(json_object_object_get(UpdateFirmware, "firmware"))
  16888. {
  16889. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  16890. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  16891. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  16892. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  16893. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  16894. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  16895. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  16896. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  16897. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  16898. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  16899. }
  16900. // Optional data
  16901. if(json_object_object_get(UpdateFirmware, "retries"))
  16902. {
  16903. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  16904. }
  16905. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  16906. {
  16907. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  16908. }
  16909. }
  16910. json_object_put(UpdateFirmware);
  16911. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  16912. memset(path, 0, ARRAY_SIZE(path));
  16913. // Wait retrieveData
  16914. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  16915. {
  16916. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16917. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  16918. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16919. do
  16920. {
  16921. sleep(1);
  16922. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  16923. }
  16924. system("rm -f /mnt/*");
  16925. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  16926. {
  16927. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  16928. sprintf(ftppath,"/%s", path);
  16929. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  16930. DEBUG_INFO("protocol: %s\n",protocol);
  16931. DEBUG_INFO("host: %s\n",host);
  16932. DEBUG_INFO("path: %s\n",path);
  16933. DEBUG_INFO("ftppath: %s\n",ftppath);
  16934. int ftppathlen=strlen(ftppath);
  16935. int i=1;
  16936. char filenametemp[50];
  16937. while(i < ftppathlen)
  16938. {
  16939. int len=ftppathlen-i;
  16940. if(ftppath[len]== 47) // '/' ascll code: 47
  16941. {
  16942. DEBUG_INFO("compare '/' all right\n");
  16943. break;
  16944. }
  16945. i=i+1;
  16946. }
  16947. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  16948. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  16949. filenametemp[i+1] = 0;
  16950. do
  16951. {
  16952. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16953. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  16954. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16955. sleep(3);
  16956. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16957. if(!isSuccess)
  16958. {
  16959. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16960. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  16961. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16962. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  16963. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16964. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  16965. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16966. }
  16967. else
  16968. {
  16969. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  16970. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  16971. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  16972. }
  16973. ShmOCPP20Data->UpdateFirmware.retries--;
  16974. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  16975. }
  16976. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  16977. {
  16978. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16979. memset(temp, 0, ARRAY_SIZE(temp));
  16980. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  16981. int ftppathlen=strlen(ftpbuf);
  16982. int i=1;
  16983. char filenametemp[50];
  16984. while(i < ftppathlen)
  16985. {
  16986. int len=ftppathlen-i;
  16987. if(ftpbuf[len]== 47) // '/' ascll code: 47
  16988. {
  16989. DEBUG_INFO(" compare '/' all right\n");
  16990. break;
  16991. }
  16992. i=i+1;
  16993. }
  16994. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  16995. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  16996. filenametemp[i+1] = 0;
  16997. strncpy(temp, ftpbuf, ftppathlen-i+1);
  16998. pch=strchr(temp,'@');
  16999. if(pch==NULL)
  17000. {
  17001. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17002. protocol, host, &port, path);
  17003. strcpy(user,"anonymous");
  17004. strcpy(password,"");
  17005. }
  17006. else
  17007. {
  17008. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  17009. protocol, user, password, host, &port, path);
  17010. }
  17011. sscanf(host,"%[^/]%s",host1, path1);
  17012. sprintf(ftppath,"%s", path1);
  17013. if(port == 0)
  17014. {
  17015. port = 21;
  17016. }
  17017. do
  17018. {
  17019. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17020. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  17021. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17022. sleep(3);
  17023. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17024. if(!isSuccess)
  17025. {
  17026. //BulldogUtil.sleepMs(interval*1000);
  17027. DEBUG_INFO("Update firmware request and download file fail.\n");
  17028. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17029. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17030. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17031. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  17032. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17033. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17034. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17035. }
  17036. else
  17037. {
  17038. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17039. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  17040. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17041. }
  17042. ShmOCPP20Data->UpdateFirmware.retries--;
  17043. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  17044. }
  17045. else
  17046. {
  17047. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17048. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17049. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17050. sleep(1);
  17051. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17052. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17053. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17054. }
  17055. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  17056. interLock.isUpdateFirmwareGoing = OFF;
  17057. pthread_exit(NULL);
  17058. }
  17059. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  17060. {
  17061. mtrace();
  17062. int result = FAIL;
  17063. pthread_t t;
  17064. sendUpdateFirmwareConfirmation(uuid);
  17065. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  17066. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  17067. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  17068. if(!interLock.isUpdateFirmwareGoing)
  17069. {
  17070. interLock.isUpdateFirmwareGoing = ON;
  17071. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  17072. sleep(1);
  17073. }
  17074. else
  17075. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  17076. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  17077. return result;
  17078. }
  17079. int handleUnknownRequest(char *uuid, char *payload)
  17080. {
  17081. mtrace();
  17082. int result = FAIL;
  17083. DEBUG_INFO("handleUnknownRequest...\n");
  17084. sendUnknownConfirmation(uuid);
  17085. result = PASS;
  17086. return result;
  17087. }
  17088. //==========================================
  17089. // Handle server response routine
  17090. //==========================================
  17091. void handleAuthorizeResponse(char *payload, int gun_index)
  17092. {
  17093. mtrace();
  17094. DEBUG_INFO("handleAuthorizeResponse...\n");
  17095. json_object *Authorize;
  17096. Authorize = json_tokener_parse(payload);
  17097. if(!is_error(Authorize))
  17098. {
  17099. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  17100. {
  17101. // Required data
  17102. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  17103. // Optional data
  17104. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  17105. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  17106. else
  17107. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  17108. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority") != NULL)
  17109. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  17110. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1") != NULL)
  17111. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  17112. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "evseId") != NULL)
  17113. {
  17114. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTokenInfo"), "evseId"));idx++)
  17115. {
  17116. 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));
  17117. }
  17118. }
  17119. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2") != NULL)
  17120. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  17121. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken") != NULL)
  17122. {
  17123. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  17124. 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")));
  17125. else
  17126. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  17127. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  17128. 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")));
  17129. }
  17130. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage") != NULL)
  17131. {
  17132. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  17133. 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")));
  17134. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  17135. 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")));
  17136. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  17137. 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")));
  17138. }
  17139. }
  17140. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  17141. {
  17142. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  17143. }
  17144. }
  17145. json_object_put(Authorize);
  17146. //Update idTag information to authorization cache if supported
  17147. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  17148. /*(strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  17149. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&*/
  17150. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  17151. {
  17152. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  17153. }
  17154. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  17155. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  17156. authorizeRetryTimes = 0;
  17157. }
  17158. void handleBootNotificationResponse(char *payload, int gun_index)
  17159. {
  17160. mtrace();
  17161. char statusStr[12]={0};
  17162. char currentTimeStr[30]={0};
  17163. int intervalInt = 0;
  17164. DEBUG_INFO("handleBootNotificationResponse...\n");
  17165. json_object *BootNotification;
  17166. BootNotification = json_tokener_parse(payload);
  17167. if(!is_error(BootNotification))
  17168. {
  17169. // Required data
  17170. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  17171. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  17172. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  17173. }
  17174. json_object_put(BootNotification);
  17175. DEBUG_INFO("statusStr: %s\n", statusStr);
  17176. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  17177. BootNotificationInterval = intervalInt;
  17178. //write back to ShmOCPP20Data->BootNotification
  17179. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  17180. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  17181. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  17182. {
  17183. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  17184. {
  17185. //Do nothing because the value is out of range.
  17186. }
  17187. else
  17188. {
  17189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  17190. HeartBeatWaitTime = intervalInt;
  17191. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  17192. }
  17193. server_sign = TRUE;
  17194. server_pending =FALSE;
  17195. DB_updateBootType(BootReasonEnumType_PowerUp);
  17196. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  17197. }
  17198. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  17199. {
  17200. server_pending = TRUE;
  17201. }
  17202. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  17203. srand(time(NULL));
  17204. refreshStartTimer(&clientTime.Heartbeat);
  17205. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  17206. SetOcppConnStatus(TRUE);
  17207. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  17208. }
  17209. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  17210. {
  17211. mtrace();
  17212. json_object *ClearedChargingLimit;
  17213. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  17214. ClearedChargingLimit = json_tokener_parse(payload);
  17215. if(!is_error(ClearedChargingLimit))
  17216. {
  17217. // Required data
  17218. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  17219. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  17220. }
  17221. json_object_put(ClearedChargingLimit);
  17222. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  17223. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  17224. }
  17225. void handleDataTransferResponse(char *payload, int gun_index)
  17226. {
  17227. mtrace();
  17228. json_object *DataTrans;
  17229. DEBUG_INFO("handleDataTransferResponse...\n");
  17230. DataTrans = json_tokener_parse(payload);
  17231. if(!is_error(DataTrans))
  17232. {
  17233. // Required data
  17234. if(json_object_object_get(DataTrans,"status") != NULL)
  17235. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  17236. // Optional data
  17237. if(json_object_object_get(DataTrans,"data") != NULL)
  17238. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  17239. }
  17240. json_object_put(DataTrans);
  17241. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  17242. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  17243. }
  17244. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  17245. {
  17246. mtrace();
  17247. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  17248. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  17249. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  17250. }
  17251. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  17252. {
  17253. mtrace();
  17254. json_object *Get15118EVCertificate;
  17255. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  17256. Get15118EVCertificate = json_tokener_parse(payload);
  17257. if(!is_error(Get15118EVCertificate))
  17258. {
  17259. // Required data
  17260. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  17261. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  17262. // Optional data
  17263. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  17264. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  17265. }
  17266. json_object_put(Get15118EVCertificate);
  17267. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  17268. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  17269. }
  17270. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  17271. {
  17272. mtrace();
  17273. json_object *GetCertificateStatus;
  17274. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  17275. GetCertificateStatus = json_tokener_parse(payload);
  17276. if(!is_error(GetCertificateStatus))
  17277. {
  17278. // Required data
  17279. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  17280. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  17281. // Optional data
  17282. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  17283. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  17284. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  17285. {
  17286. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  17287. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  17288. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  17289. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  17290. }
  17291. }
  17292. json_object_put(GetCertificateStatus);
  17293. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  17294. {
  17295. /*
  17296. * TODO:
  17297. * 1. If get certificate response accepted process something here
  17298. */
  17299. }
  17300. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  17301. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  17302. }
  17303. void handleHeartbeatResponse(char *payload, int gun_index)
  17304. {
  17305. mtrace();
  17306. DEBUG_INFO("handleHeartbeatResponse...\n");
  17307. json_object *Heartbeat;
  17308. Heartbeat = json_tokener_parse(payload);
  17309. if(!is_error(Heartbeat))
  17310. {
  17311. // Required data
  17312. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  17313. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  17314. }
  17315. json_object_put(Heartbeat);
  17316. if(FirstHeartBeat == OFF)
  17317. {
  17318. FirstHeartBeat = ON;
  17319. DEBUG_INFO("FirstHeartBeat \n");
  17320. }
  17321. HeartBeatWithNOResponse = 0;
  17322. refreshStartTimer(&clientTime.Heartbeat);
  17323. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  17324. }
  17325. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  17326. {
  17327. mtrace();
  17328. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  17329. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  17330. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  17331. }
  17332. void handleMeterValuesResponse(char *payload, int gun_index)
  17333. {
  17334. mtrace();
  17335. DEBUG_INFO("handleMeterValuesResponse...\n");
  17336. isQueueSendable = ON;
  17337. }
  17338. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  17339. {
  17340. mtrace();
  17341. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  17342. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  17343. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  17344. }
  17345. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  17346. {
  17347. mtrace();
  17348. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  17349. }
  17350. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  17351. {
  17352. mtrace();
  17353. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  17354. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  17355. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  17356. }
  17357. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  17358. {
  17359. mtrace();
  17360. json_object *NotifyEVChargingNeeds;
  17361. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  17362. NotifyEVChargingNeeds = json_tokener_parse(payload);
  17363. if(!is_error(NotifyEVChargingNeeds))
  17364. {
  17365. // Required data
  17366. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  17367. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  17368. }
  17369. json_object_put(NotifyEVChargingNeeds);
  17370. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  17371. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  17372. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  17373. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsConf = ON;
  17374. }
  17375. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  17376. {
  17377. mtrace();
  17378. json_object *NotifyEVChargingSchedule;
  17379. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  17380. NotifyEVChargingSchedule = json_tokener_parse(payload);
  17381. if(!is_error(NotifyEVChargingSchedule))
  17382. {
  17383. // Required data
  17384. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  17385. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  17386. }
  17387. json_object_put(NotifyEVChargingSchedule);
  17388. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  17389. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleConf = ON;
  17390. }
  17391. void handleNotifyEventResponse(char *payload, int gun_index)
  17392. {
  17393. mtrace();
  17394. DEBUG_INFO("handleNotifyEventResponse...\n");
  17395. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  17396. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  17397. }
  17398. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  17399. {
  17400. mtrace();
  17401. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  17402. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  17403. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  17404. }
  17405. void handleNotifyReportResponse(char *payload, int gun_index)
  17406. {
  17407. mtrace();
  17408. DEBUG_INFO("handleNotifyReportResponse...\n");
  17409. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  17410. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  17411. }
  17412. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  17413. {
  17414. mtrace();
  17415. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  17416. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  17417. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  17418. }
  17419. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  17420. {
  17421. mtrace();
  17422. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  17423. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  17424. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  17425. }
  17426. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  17427. {
  17428. mtrace();
  17429. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  17430. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  17431. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  17432. }
  17433. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  17434. {
  17435. mtrace();
  17436. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  17437. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  17438. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  17439. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  17440. }
  17441. void handleSignCertificateResponse(char *payload, int gun_index)
  17442. {
  17443. mtrace();
  17444. json_object *SignCertificate;
  17445. DEBUG_INFO("handleSignCertificateResponse...\n");
  17446. SignCertificate = json_tokener_parse(payload);
  17447. if(!is_error(SignCertificate))
  17448. {
  17449. // Required data
  17450. if(json_object_object_get(SignCertificate,"status") != NULL)
  17451. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  17452. // Optional data
  17453. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  17454. {
  17455. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  17456. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  17457. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  17458. }
  17459. }
  17460. json_object_put(SignCertificate);
  17461. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  17462. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  17463. }
  17464. void handleStatusNotificationResponse(char *payload, int gun_index)
  17465. {
  17466. mtrace();
  17467. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  17468. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  17469. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  17470. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  17471. }
  17472. void handleTransactionEventResponse(char *payload, int gun_index)
  17473. {
  17474. mtrace();
  17475. json_object *TransactionEven;
  17476. DEBUG_INFO("handleTransactionEventResponse...\n");
  17477. TransactionEven = json_tokener_parse(payload);
  17478. if(!is_error(TransactionEven))
  17479. {
  17480. // Required data
  17481. // Optional data
  17482. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  17483. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  17484. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  17485. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  17486. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  17487. {
  17488. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  17489. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  17490. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  17491. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  17492. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  17493. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  17494. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  17495. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  17496. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  17497. {
  17498. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  17499. 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")));
  17500. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  17501. 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")));
  17502. }
  17503. }
  17504. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  17505. {
  17506. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  17507. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  17508. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  17509. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  17510. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  17511. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  17512. }
  17513. }
  17514. json_object_put(TransactionEven);
  17515. isQueueSendable = ON;
  17516. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  17517. }
  17518. //==========================================
  17519. // Handle Error routine
  17520. //==========================================
  17521. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  17522. {
  17523. mtrace();
  17524. #ifdef SystemLogMessage
  17525. DEBUG_INFO("errorCode: %s\n", errorCode);
  17526. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  17527. DEBUG_INFO("errorDetails: %s\n", payload);
  17528. #endif
  17529. }
  17530. //===============================================
  17531. // Common routine
  17532. //===============================================
  17533. int initialConfigurationTable(void)
  17534. {
  17535. DEBUG_INFO("initialConfigurationTable...\n");
  17536. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  17537. DB_variableIsCreate();
  17538. DB_variableLoadFromDb();
  17539. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  17540. {
  17541. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  17542. DB_variableClear();
  17543. DB_variableIsCreate();
  17544. DB_variableLoadFromDb();
  17545. }
  17546. DB_getNetworkProfileFromDb();
  17547. return 0;
  17548. }
  17549. int TransactionMessageAttemptsGet(void)
  17550. {
  17551. return TransactionMessageAttemptsValue;
  17552. }
  17553. int FirstHeartBeatResponse(void)
  17554. {
  17555. return FirstHeartBeat;
  17556. }
  17557. int TransactionMessageRetryIntervalGet(void)
  17558. {
  17559. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17560. }
  17561. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17562. {
  17563. int result = TRUE;
  17564. char rmFileCmd[100]={0};
  17565. char FilePath[100]={0};
  17566. char ftpbuf[200];
  17567. int systemresult;
  17568. sprintf(FilePath,"/mnt/%s",filename);
  17569. system("ping 8.8.8.8 &");
  17570. if((access(FilePath,F_OK))!=-1)
  17571. {
  17572. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17573. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17574. system(rmFileCmd);
  17575. }
  17576. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17577. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17578. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17579. systemresult = system(ftpbuf);
  17580. if(systemresult != 0)
  17581. {
  17582. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  17583. result = FALSE;
  17584. }
  17585. system("pkill ping");
  17586. return result;
  17587. }
  17588. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17589. {
  17590. int result = TRUE;
  17591. char rmFileCmd[100]={0};
  17592. char FilePath[100]={0};
  17593. char ftpbuf[200];
  17594. int systemresult;
  17595. sprintf(FilePath,"/mnt/%s",filename);
  17596. system("ping 8.8.8.8 &");
  17597. if((access(FilePath,F_OK))!=-1)
  17598. {
  17599. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17600. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17601. system(rmFileCmd);
  17602. }
  17603. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17604. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17605. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17606. systemresult = system(ftpbuf);
  17607. if(systemresult != 0)
  17608. {
  17609. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17610. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17611. systemresult = system(ftpbuf);
  17612. if(systemresult != 0)
  17613. {
  17614. DEBUG_WARN("FTP download fail!\n");
  17615. result = FALSE;
  17616. }
  17617. }
  17618. system("pkill ping");
  17619. return result;
  17620. }
  17621. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17622. {
  17623. char rmFileCmd[100]={0};
  17624. char FilePath[100]={0};
  17625. char buf[512];
  17626. int systemresult = 0;
  17627. //DEBUG_INFO("filename=%s\n",filename);
  17628. //DEBUG_INFO("url=%s\n",url);
  17629. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17630. if((access(FilePath,F_OK))!=-1)
  17631. {
  17632. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17633. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17634. system(rmFileCmd);
  17635. }
  17636. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17637. if(fp == NULL)
  17638. {
  17639. DEBUG_INFO("log is NULL\n");
  17640. return FALSE;
  17641. }
  17642. else
  17643. {
  17644. fprintf(fp, "%s\n", url);
  17645. fprintf(fp, "%s\n", filename);
  17646. fclose(fp);
  17647. }
  17648. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17649. if(phpFP == NULL)
  17650. {
  17651. DEBUG_INFO("PHP upload fail.\n");
  17652. return FALSE;
  17653. }
  17654. else
  17655. {
  17656. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17657. {
  17658. if(strstr(buf, "result") != NULL)
  17659. {
  17660. sscanf(buf, "result: %d", &systemresult);
  17661. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17662. }
  17663. }
  17664. pclose(phpFP);
  17665. }
  17666. if(systemresult != 1)
  17667. {
  17668. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17669. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17670. if(phpFP == NULL)
  17671. {
  17672. DEBUG_WARN("PHP PUT upload fail.\n");
  17673. return FALSE;
  17674. }
  17675. else
  17676. {
  17677. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17678. {
  17679. if(strstr(buf, "result") != NULL)
  17680. {
  17681. sscanf(buf, "result: %d", &systemresult);
  17682. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17683. }
  17684. }
  17685. pclose(phpFP);
  17686. }
  17687. }
  17688. if(systemresult != 1)
  17689. {
  17690. DEBUG_WARN("PHP PUT upload fail.\n");
  17691. return FALSE;
  17692. }
  17693. return TRUE;
  17694. }
  17695. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17696. {
  17697. int result = FALSE;
  17698. char ftpbuf[200];
  17699. int systemresult;
  17700. /*
  17701. // Domaind name transfer to IP address
  17702. struct hostent* server;
  17703. char *IPbuffer;
  17704. server = gethostbyname(location);
  17705. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17706. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17707. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17708. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17709. systemresult = system(ftpbuf);
  17710. if(systemresult != 0)
  17711. {
  17712. DEBUG_INFO("ftpput error!\n");
  17713. }
  17714. else
  17715. {
  17716. result = TRUE;
  17717. DEBUG_INFO("ftpput OK!\n");
  17718. }
  17719. return result;
  17720. }
  17721. //=========================================
  17722. // Routine
  17723. //=========================================
  17724. int GetOcppServerURL()
  17725. {
  17726. int result = FALSE;
  17727. struct yuarel url;
  17728. char urlStr[512];
  17729. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17730. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17731. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17732. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  17733. {
  17734. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  17735. if(yuarel_parse(&url, urlStr) != -1)
  17736. {
  17737. sprintf(OcppProtocol, "%s", url.scheme);
  17738. sprintf(OcppHost, "%s", url.host);
  17739. if(url.path == NULL)
  17740. OcppTempPath[0] = '\0';
  17741. else
  17742. sprintf(OcppTempPath, "%s", url.path);
  17743. if(url.port == 0)
  17744. {
  17745. if(strcmp(OcppProtocol, "wss") == 0)
  17746. OcppPort = 443;
  17747. else
  17748. OcppPort = 80;
  17749. }
  17750. else
  17751. OcppPort = url.port;
  17752. result = TRUE;
  17753. }
  17754. }
  17755. else
  17756. {
  17757. strcpy(OcppHost,"");
  17758. }
  17759. return result;
  17760. }
  17761. int GetOcppPath()
  17762. {
  17763. int result = FALSE;
  17764. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17765. {
  17766. if(OcppTempPath == NULL)
  17767. {
  17768. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17769. }
  17770. else
  17771. {
  17772. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17773. }
  17774. result = TRUE;
  17775. }
  17776. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  17777. {
  17778. if(OcppTempPath == NULL)
  17779. {
  17780. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  17781. }
  17782. else
  17783. {
  17784. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  17785. }
  17786. result = TRUE;
  17787. }
  17788. else
  17789. {
  17790. strcpy(OcppPath,"");
  17791. }
  17792. return result;
  17793. }
  17794. int GetOcppPort()
  17795. {
  17796. return OcppPort;
  17797. }
  17798. int GetOcppConnStatus(void)
  17799. {
  17800. return ShmOCPP20Data->OcppConnStatus;
  17801. }
  17802. void SetOcppConnStatus(uint8_t status)
  17803. {
  17804. ShmOCPP20Data->OcppConnStatus = status;
  17805. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17806. }
  17807. int GetHeartBeatWithNOResponse(void)
  17808. {
  17809. return HeartBeatWithNOResponse;
  17810. }
  17811. void SetHeartBeatWithNOResponse(void)
  17812. {
  17813. HeartBeatWithNOResponse = 0;
  17814. }
  17815. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17816. void storeTempStopTransaction(int gun_index)
  17817. {
  17818. char TempStopTransaction[256];
  17819. char message[1024*20]={0};
  17820. char guid[37]={0};
  17821. json_object *TransactionEvent = json_object_new_object();
  17822. json_object *transactionInfo = json_object_new_object();
  17823. json_object *idToken = json_object_new_object();
  17824. json_object *evse = json_object_new_object();
  17825. json_object *meterValues = json_object_new_array();
  17826. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  17827. DEBUG_INFO("storeTempStopTransaction...\n");
  17828. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  17829. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  17830. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  17831. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  17832. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  17833. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  17834. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  17835. // Message
  17836. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  17837. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  17838. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  17839. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  17840. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  17841. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  17842. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  17843. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  17844. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  17845. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  17846. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  17847. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  17848. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  17849. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  17850. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  17851. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  17852. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  17853. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  17854. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  17855. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  17856. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  17857. {
  17858. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  17859. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  17860. json_object_object_add(TransactionEvent, "idToken", idToken);
  17861. }
  17862. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  17863. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  17864. json_object_object_add(TransactionEvent, "evse", evse);
  17865. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  17866. {
  17867. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  17868. {
  17869. json_object *meterValue = json_object_new_object();
  17870. json_object *sampledValues = json_object_new_array();
  17871. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  17872. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  17873. {
  17874. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  17875. ((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)))
  17876. {
  17877. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)
  17878. {
  17879. json_object *sampledValue = json_object_new_object();
  17880. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  17881. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  17882. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  17883. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  17884. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  17885. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  17886. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  17887. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  17888. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  17889. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  17890. {
  17891. json_object *unitOfMeasure = json_object_new_object();
  17892. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  17893. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  17894. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  17895. }
  17896. json_object_array_add(sampledValues, sampledValue);
  17897. }
  17898. }
  17899. }
  17900. json_object_object_add(meterValue, "sampledValue", sampledValues);
  17901. json_object_array_add(meterValues, meterValue);
  17902. }
  17903. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  17904. }
  17905. random_uuid(guid);
  17906. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  17907. , guid
  17908. , "TransactionEvent"
  17909. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  17910. json_object_put(TransactionEvent);
  17911. // open file for writing
  17912. FILE *outfile;
  17913. outfile = fopen (TempStopTransaction, "w+");
  17914. //DEBUG_INFO("data = %s\n", queuedata);
  17915. fputs(message, outfile);
  17916. fputs("\n", outfile);
  17917. fclose (outfile);
  17918. }
  17919. void checkTempStopTransaction(int gun_index)
  17920. {
  17921. FILE *fptr1;
  17922. char ch;
  17923. char str[QUEUE_MESSAGE_LENGTH]={0};
  17924. char guid[37]={0};
  17925. char tempdata[65]={0};
  17926. char TempStopTransaction[256];
  17927. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  17928. fptr1 = fopen(TempStopTransaction, "r");
  17929. if (!fptr1)
  17930. {
  17931. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  17932. return ;
  17933. }
  17934. ch=fgetc(fptr1);
  17935. rewind(fptr1);
  17936. if(ch!=EOF)
  17937. {
  17938. // copy all contents to the temporary file except the specific line
  17939. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17940. {
  17941. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17942. if(str[0]=='\0')
  17943. {
  17944. break;
  17945. }
  17946. strncpy(guid, str+4, 36); //copy guid
  17947. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  17948. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17949. {
  17950. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17951. }
  17952. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17953. memset(str,0,ARRAY_SIZE(str));
  17954. }
  17955. }
  17956. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17957. fclose(fptr1);
  17958. remove(TempStopTransaction); // remove the original file
  17959. }
  17960. int GetWebSocketPingInterval(void)
  17961. {
  17962. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  17963. }
  17964. int GetServerSign(void)
  17965. {
  17966. return server_sign;
  17967. }
  17968. uint8_t GetOcppSecurityProfile()
  17969. {
  17970. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  17971. }
  17972. void GetOcppChargerBoxId(uint8_t *data)
  17973. {
  17974. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17975. }
  17976. void GetOcppSecurityPassword(uint8_t *data)
  17977. {
  17978. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  17979. }
  17980. void SetServerSign(int value)
  17981. {
  17982. server_sign = value;
  17983. }
  17984. int GetBootNotificationInterval(void)
  17985. {
  17986. return BootNotificationInterval;
  17987. }
  17988. int GetInternetConn(void)
  17989. {
  17990. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17991. }
  17992. int GetBackendConnectionTimeout(void)
  17993. {
  17994. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17995. }
  17996. int isConnectorInitMode(int gun_index)
  17997. {
  17998. int tempIndex = 0;
  17999. int result = TRUE;
  18000. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18001. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18002. {
  18003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18004. {
  18005. tempIndex = ((gun_index==2) ? 1: 0);
  18006. }
  18007. else
  18008. {
  18009. tempIndex = gun_index;
  18010. }
  18011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18012. {
  18013. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18014. {
  18015. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18016. } //end of the same index
  18017. }//end of for CHAdeMO_QUANTITY
  18018. }
  18019. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18020. {
  18021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18022. {
  18023. tempIndex = ((gun_index==2) ? 1: 0);
  18024. }
  18025. else
  18026. {
  18027. tempIndex = gun_index;
  18028. }
  18029. for (int index = 0; index < CCS_QUANTITY; index++)
  18030. {
  18031. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18032. {
  18033. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18034. } //end of the same index
  18035. } // end of for CCS_QUANTITY
  18036. }
  18037. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18038. {
  18039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18040. {
  18041. tempIndex = ((gun_index==2) ? 1: 0);
  18042. }
  18043. else
  18044. {
  18045. tempIndex = gun_index;
  18046. }
  18047. for (int index = 0; index < GB_QUANTITY; index++)
  18048. {
  18049. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18050. {
  18051. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18052. } //end of the same index
  18053. } // end of for GB_QUANTITY
  18054. }
  18055. else if(gunType[gun_index] == GUN_TYPE_DO)
  18056. {
  18057. tempIndex = gun_index;
  18058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18059. {
  18060. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18061. {
  18062. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18063. } //end of the same index
  18064. }
  18065. }
  18066. else
  18067. {
  18068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18069. {
  18070. tempIndex = 2;
  18071. }
  18072. else
  18073. {
  18074. tempIndex = gun_index;
  18075. }
  18076. for (int index = 0; index < AC_QUANTITY; index++)
  18077. {
  18078. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18079. {
  18080. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18081. }//end of the same index
  18082. }//end of for AC_QUANTITY
  18083. }
  18084. return result;
  18085. }
  18086. void refreshProcDogTimer()
  18087. {
  18088. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  18089. }
  18090. void InitialSystemValue(void)
  18091. {
  18092. localversion=0;
  18093. BootNotificationInterval = 10;
  18094. authorizeRetryTimes = 0;
  18095. GunStatusInterval = 10;
  18096. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  18097. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  18098. //Hear Beat
  18099. HeartBeatWithNOResponse = 0;
  18100. HeartBeatCountPerHour = 0;
  18101. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  18102. FirstHeartBeat = 0;
  18103. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  18104. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  18105. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18106. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18107. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18108. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18109. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18110. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18111. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18112. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18113. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18114. //Status && ConnectorPlugIn Setting
  18115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18116. {
  18117. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18118. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18119. }
  18120. for (int index = 0; index < CCS_QUANTITY; index++)
  18121. {
  18122. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18123. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18124. }
  18125. for (int index = 0; index < GB_QUANTITY; index++)
  18126. {
  18127. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18128. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18129. }
  18130. for (int index = 0; index < AC_QUANTITY; index++)
  18131. {
  18132. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18133. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18134. }
  18135. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18136. {
  18137. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18138. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18139. }
  18140. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18141. {
  18142. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  18143. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  18144. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  18145. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18146. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  18147. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  18148. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  18149. }
  18150. refreshStartTimer(&clientTime.Heartbeat);
  18151. sleep(1);
  18152. }
  18153. void LWS_Send(char *str)
  18154. {
  18155. //=====================================================
  18156. // Check InternetConn 0: disconnected, 1: connected
  18157. //====================================================
  18158. if(GetOcppConnStatus() == 0)
  18159. {
  18160. DEBUG_INFO("offline now !!!\n");
  18161. return;
  18162. }
  18163. // Only disable isWebsocketSendable operation initiated by charger
  18164. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18165. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18166. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  18167. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18168. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18169. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  18170. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  18171. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18172. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18173. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18174. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  18175. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  18176. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  18177. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  18178. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  18179. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  18180. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  18181. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  18182. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  18183. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  18184. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  18185. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18186. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18187. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18188. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  18189. {
  18190. isWebsocketSendable = OFF;
  18191. }
  18192. pthread_mutex_lock(&lock_send);
  18193. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18194. sprintf((char *)SendBuffer, "%s", str);
  18195. SendBufLen = strlen(str);
  18196. pthread_mutex_unlock(&lock_send);
  18197. lws_callback_on_writable(wsi_client);
  18198. //lws_service(context, 0);
  18199. //sleep(1);
  18200. }
  18201. void LWS_SendNow(char *str)
  18202. {
  18203. //=====================================================
  18204. // Check InternetConn 0: disconnected, 1: connected
  18205. //====================================================
  18206. if(GetOcppConnStatus() == 0)
  18207. {
  18208. DEBUG_INFO("offline now !!!\n");
  18209. return;
  18210. }
  18211. // Only disable isWebsocketSendable operation initiated by charger
  18212. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18213. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18214. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  18215. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18216. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18217. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  18218. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  18219. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18220. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18221. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18222. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  18223. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  18224. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  18225. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  18226. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  18227. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  18228. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  18229. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  18230. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  18231. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  18232. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  18233. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18234. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18235. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18236. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  18237. {
  18238. isWebsocketSendable = OFF;
  18239. }
  18240. pthread_mutex_lock(&lock_send);
  18241. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18242. sprintf((char *)SendBuffer, "%s", str);
  18243. SendBufLen = strlen(str);
  18244. pthread_mutex_unlock(&lock_send);
  18245. lws_callback_on_writable(wsi_client);
  18246. lws_service(context, 0);
  18247. //sleep(1);
  18248. }